cleveref因共享同一个计数器的定理环境而失败

obc*_*bco 6 counter latex reference theorem

我想在同一(部分)计数器上对所有定理和推论进行编号.但是当我这样做时,Cleveref将它们都命名为"定理".这是一个最小的例子:

\documentclass{amsart}

\usepackage{amsthm, cleveref}
%\crefname{theorem}{theorem}{theorems}
%\crefname{corollary}{corollary}{corollaries}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}[theorem]{Corollary}

\begin{document}
\section{Section title}

\begin{theorem}\label{thm:test}
Here is the theorem.
\end{theorem}

\begin{corollary}\label{cor:test}
Here is the corollary.
\end{corollary}

The theorem reference is given by \cref{thm:test} and the corollary reference is given by \cref{cor:test}.

\end{document}
Run Code Online (Sandbox Code Playgroud)

这里,推论参考是'定理1.2'.即使明确说明crefname,此问题仍然存在.

有什么建议?

小智 7

如果您希望 smartef 区分使用相同计数器的不同类似定理的环境,则需要加载 ntheorem 或 amsthm 包。这些包存储有关 smartef 使用的类似定理环境的附加信息。请注意,它们必须在smartef之前加载。

使用 ntheorem(长期以来通过 hyperref 选项与 hyperref 兼容)或 amsthm(也与 hyperref 兼容)与 Cleveref 一起使用是比使用 \label 的可选参数更好的解决方案。并且也没有必要退回到 \thref 。如果您无论如何都使用 ntheorem,那么 \cref 将执行 \thref 执行的所有操作,甚至更多(多重引用、自定义格式等)。事实上,当使用 thref 选项加载 ntheorem 时,cleveref 将 \thref 重新定义为 \cref 的别名。

(有一个技巧 - 也在 smartef 手册中描述 - 使用 aliascnt 包来区分类似定理的环境,而不需要 ntheorem 或 amsthm。但这需要更多的工作,坦率地说,当一个简单的 \usepackage{ntheorem} 或 \usepackage 时为什么要费心呢? {amsthm} 会完美地完成这项工作吗?)

  • 正如您所注意到的,“amsthm”必须在“cleveref”之前加载。此外,看来“\newtheorem”命令必须出现在“cleveref”加载*之后。 (8认同)

Dan*_*ner 0

由于您已声明两种定理使用相同的计数器,所以 smartef 无法区分它们。考虑改用 ntheorem 包。