[Tex/LaTex] Cleveref with counters with same name

cleverefcross-referencingnewtheoremtheorems

I am trying to use the cleveref package.

I have the following counters defined (hopefully this is the right way to do it!)

\newtheorem{thm}{Theorem}[section]
\newtheorem{lemma}[thm]{Lemma}
\newtheorem{cor}[thm]{Corollary}

This works as I would like (i.e. Theorem 1.1, Corollary 1.2, Lemma 1.3, etc.)

My problem is \cref always returns Theorem 1.2, Theorem 1.3. I

Perhaps this is not right? (In my preamble)

\crefname{thm}{theorem}{theorem's}
\crefname{lemma}{lemma}{lemma's}

Best Answer

The behaviour you describe comes from the standard LaTeX \newtheorem command; the problem can be solved by using the amsthm or ntheorem packages:

\documentclass{article}
\usepackage{amsthm}
\usepackage{cleveref}

\newtheorem{thm}{Theorem}[section]
\newtheorem{lemma}[thm]{Lemma}
\newtheorem{cor}[thm]{Corollary}

\begin{document}

\begin{thm}\label{thm:test}
test
\end{thm}

\begin{lemma}\label{lem:test}
test
\end{lemma}

As shown in \cref{thm:test} and \cref{lem:test}

\end{document}

The \newtheorem commands have to come after the loading of cleveref. Additionally, the cleverref package has to be loaded after ntheorem or amsthm. In total this gives the following order:

\usepackage{ntheorem}
\usepackage{cleveref}
\newtheorem{...}

By the way, the plural forms of theorem and lemma don't use an apostrophe, so you should use

\crefname{thm}{theorem}{theorems}
\crefname{lemma}{lemma}{lemmas}