我查过很多关于用名称引用定理、推论、引理等问题的解决方案。我的意思是,如果定理 1 的标签是 \label{T:theoremOne},那么使用命令 \ref{T:theoremOne} 时,我们会得到该定理的名称和编号,即定理 1。
我知道当环境不依赖于单个计数器时如何获得此结果,但是当我对所有定理、推论、引理、命题、定义和所有内容使用单个计数器时,我陷入了名称问题(我知道,这似乎很愚蠢,但这是我的博士论文最终稿的要求!)。这是一个可行的示例来说明我的问题。
\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\newtheorem{theorem}{Theorem}
\labelformat{theorem}{Theorem~#1}
\newtheorem{corollary}[theorem]{Corollary}
\labelformat{corollary}{Corollary~#1}
\usepackage{graphicx}
\usepackage{lmodern}
\author{Pierre-Olivier Parisé}
\begin{document}
A working example.
\begin{theorem}\label{T:theoremOne}
Here's a first theorem.
\end{theorem}
So, when we refer to \ref{T:theoremOne}, we get the following corollary.
\begin{corollary}\label{C:corollaryOne}
Here's a corollary of the first Theorem.
\end{corollary}
So now, we see that \ref{C:corollaryOne} is not named correctly...
\end{document}
如果你尝试一下,你将获得以下结果输出。如您所见,推论被打印为定理 2 而不是推论 2。我想我知道问题出在哪里了。推论环境使用与定理环境相同的计数器。因此,当它打印计数器的名称时,它采用定理计数器的名称而不是推论计数器的名称(事实上,据我所知,它们是相同的)。我也尝试对所有环境使用外部计数器,但它没有按预期工作(它只打印数字,因为计数器没有名称……而且我必须选择环境的好名称才能正确打印它,这对我来说并不明显如何实现这一点)。
有人能解决这个问题吗?如果我错过了关于这个问题的任何帖子,请告诉我。我真的很感激能得到帮助。谢谢!
答案1
您无需为标签格式而烦恼,您可以让它cleveref
为您完成工作:
\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[capitalise]{cleveref}
\newtheorem{theorem}{Theorem}
%\labelformat{theorem}{Theorem~#1}
\newtheorem{corollary}[theorem]{Corollary}
%\labelformat{corollary}{Corollary~#1}
\usepackage{graphicx}
\usepackage{lmodern}
\author{Pierre-Olivier Parisé}
\begin{document}
A working example.
\begin{theorem}\label{T:theoremOne}
Here's a first theorem.
\end{theorem}
So, when we refer to \cref{T:theoremOne}, we get the following corollary.
\begin{corollary}\label{C:corollaryOne}
Here's a corollary of the first Theorem.
\end{corollary}
So now, we see that \cref{C:corollaryOne} is not named correctly...
\end{document}
答案2
您cleveref
确实应该使用。无论如何,没有它您也可以完成工作。
\documentclass[12pt,a4paper]{article}
%\usepackage[english]{babel}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage{amsthm}
%\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{aliascnt}
\newtheorem{theorem}{Theorem}
\labelformat{theorem}{Theorem~#1}
\newaliascnt{corollary}{theorem}
\newtheorem{corollary}[corollary]{Corollary}
\labelformat{corollary}{Corollary~#1}
\aliascntresetthe{corollary}
\author{Pierre-Olivier Parisé}
\begin{document}
A working example.
\begin{theorem}\label{T:theoremOne}
Here's a first theorem.
\end{theorem}
So, when we refer to \ref{T:theoremOne}, we get the following corollary.
\begin{corollary}\label{C:corollaryOne}
Here's a corollary of the first Theorem.
\end{corollary}
So now, we see that \ref{C:corollaryOne} is not named correctly...
\end{document}