新定理上的 autoref

新定理上的 autoref

我希望能够使用 autoref 打印我自己的定理的名称。例如

\begin{lemma}
\label{lemma_foo}
  Some lemma
\end{lemma}

\autoref{lemma_foo}

我想要打印类似“Lemma 3.2”的内容。

我目前的方法是:

\newtheorem{lemma}{Lemma}[chapter]
\newcommand{\lemmaautorefname}{Lemma}

\newtheorem{definition}[lemma]{Definition}
\newcommand{\definitionautorefname}{Definition}

定义与引理共享计数器,这是有意为之,但它有副作用,即引用定义会导致它们被称为引理。

我该如何解决?

答案1

只要定义了lemma和环境definitionhyperref和包cleveref都已加载,使用\cref代替\autoref应该可以得到您想要的东西。

在此处输入图片描述

\documentclass{report} % or 'book'?
\usepackage{ntheorem}  % or 'amsthm'?
\usepackage[colorlinks]{hyperref}
\usepackage[capitalize,nameinlink,noabbrev]{cleveref} % to emulate \autoref style

\newtheorem{lemma}{Lemma}[chapter]
\newcommand{\lemmaautorefname}{Lemma}
\newtheorem{definition}[lemma]{Definition}
\newcommand{\definitionautorefname}{Definition}

\setcounter{chapter}{1} % just for this example

\begin{document}
\begin{lemma}
\label{lemma_foo}
  Some lemma
\end{lemma}
\autoref{lemma_foo}  (correct) and \cref{lemma_foo} (correct) \dots

\begin{definition}
\label{definition_bar}
  A definition
\end{definition}
\autoref{definition_bar} (incorrect) and \cref{definition_bar} (correct) \dots

\end{document}

答案2

我设法让它与 \autoref 一起工作,但它只允许计数器对每种类型进行计数。因此,您将得到定义 1.1,然后是定义 1.2,如果您在引理 1.1 之后添加引理。这可能是可以接受的。

\newtheorem{lemma}{Lemma}[section]
\newtheorem{definition}{Definition}[section]

\newcommand{\lemmaautorefname}{Lemma}
\newcommand{\definitionautorefname}{Definition}

相关内容