在我的 tex 文档中,我有 3 个环境,分别为定义、定理和引理。
它们的编号应连续,如下所示:
Definition 1.1
Theorem 1.2
Lemma 1.3
Definition 1.4
...
我通过以下方式获得它:
\newtheorem{defn}{Definition}[chapter]
\newtheorem{theorem}[defn]{Theorem}
\newtheorem{lemma}[defn]{Lemma}
\def\defnautorefname{Def.}
\def\theoremautorefname{Thm.}
\def\lemmaautorefname{Lem.}
到目前为止一切顺利。然后我想使用 来引用它们中的每一个\autoref
,例如:
\autoref{defn:1}
\autoref{theorem:1}
\autoref{lemma:1}
但我得到的只有:
Def. 1.1
Def. 1.2
Def. 1.3
和不是正如我希望的那样:
Def. 1.1
Thm. 1.2
Lem. 1.3
我的完整代码:
\documentclass[a4paper,11pt]{report}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{hyperref}
\newtheorem{defn}{Definition}[chapter]
\newtheorem{theorem}[defn]{Theorem}
\newtheorem{lemma}[defn]{Lemma}
\def\defnautorefname{Def.}
\def\theoremautorefname{Thm.}
\def\lemmaautorefname{Lem.}
\parindent0pt
\begin{document}
\chapter{Chapter 1}
\begin{defn}
\label{defn:1}
Def 1
\end{defn}
\begin{theorem}
\label{theorem:1}
Theorem 1
\end{theorem}
\begin{lemma}
\label{lemma:1}
Lemma 1
\end{lemma}
\begin{defn}
\label{defn:2}
Lemma 1
\end{defn}
Here should be Definition: \autoref{defn:1}
Here should be Theorem: \autoref{theorem:1}
Here should be Lemma: \autoref{lemma:1}
\end{document}
答案1
该cleveref
包提供了\cref
宏,它比 更聪明 [双关语] \autoref
。例如,它可以接受多个参数。此外,在确定当多个环境共享一个公共计数器时使用哪个标签方面,\cref
比 更好,就像您的示例中的、和\autoref
一样definition
theorem
lemma
在以下示例中,cleveref
包使用选项 加载nameinlink
。这使得标签和数字都成为超目标的一部分,模仿由 生成的交叉引用的外观\autoref
。
\documentclass[a4paper,11pt]{report}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
%%\usepackage{ucs} % don't use it; it's deprecated
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage[colorlinks]{hyperref}
\usepackage[nameinlink]{cleveref}
\newtheorem{defn}{Definition}[chapter]
\newtheorem{theorem}[defn]{Theorem}
\newtheorem{lemma}[defn]{Lemma}
\crefname{defn}{definition}{definitions}
\Crefname{defn}{Definition}{Definitions}
%\def\defnautorefname{Def.}
%\def\theoremautorefname{Thm.}
%\def\lemmaautorefname{Lem.}
\setlength{\parindent}{0pt}
\begin{document}
\setcounter{chapter}{1}
\begin{defn} \label{defn:1} Def 1 \end{defn}
\begin{theorem} \label{theorem:1} Theorem 1 \end{theorem}
\begin{lemma} \label{lemma:1} Lemma 1 \end{lemma}
\begin{defn} \label{defn:2} Definition 2 \end{defn}
Here are two Definitions: \Cref{defn:1,defn:2}
Here is a Theorem: \Cref{theorem:1}
Here is a Lemma: \Cref{lemma:1}
\end{document}