Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cleveref fails for theorem environments sharing the same counter

I want to number all theorems and corollaries on the same (section) counter. But when I do this, cleveref names them both 'theorem'. Here is a minimal example:

\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}

Here, the corollary reference is 'theorem 1.2'. This problem persists even when explicitly stating the crefname.

Any suggestions?

like image 821
obco Avatar asked Jun 27 '11 22:06

obco


2 Answers

You need to load either the ntheorem or the amsthm package if you want cleveref to distinguish different theorem-like environments that use the same counter. Those packages store additional information about theorem-like environments that cleveref makes use of. Note that they must be loaded before cleveref.

Using ntheorem (which has been hyperref-compatible for a long time now via the hyperref option) or amsthm (also hyperref-compatible) together with cleveref is a much better solution than using an optional argument to \label. And there's no need to fall back to \thref either. If you're using ntheorem anyway, then \cref will do everything that \thref does, and more (multi-references, customised formatting, etc.). In fact, cleveref redefines \thref to be an alias for \cref when ntheorem is loaded with the thref option.

(There is a trick - also described in the cleveref manual - that uses the aliascnt package to distinguish theorem-like environments without ntheorem or amsthm. But it takes more work, and frankly why bother when a simple \usepackage{ntheorem} or \usepackage{amsthm} will do the job perfectly?)

like image 162
Toby Cubitt Avatar answered Nov 16 '22 02:11

Toby Cubitt


Ok, here's a workaround.

Specify the name to be displayed in the optional label argument, i.e:

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

This gives the desired output whilst keeping the environment name in the same place (albeit written twice).

like image 34
obco Avatar answered Nov 16 '22 01:11

obco