I believe that usually you explicitly tell cleveref what to call your label using \crefname{type}{singular}{plural}
, this doen't work however as here "type" has to be the name of the counter (I believe). I've also tried using \label[type]{label}
to no avail.
Is there any way to accomplish two environments sharing a counter, but have cleveref be able to distinguish between them? (Or is there maybe some way to use two counters, but for them always to be equal/dependent as to accomplish the same effect?)
Below is an example:
\documentclass{article}
\usepackage[colorlinks, linkcolor=blue]{hyperref}
\usepackage[noabbrev, capitalise]{cleveref}
\usepackage{tikz}
%new theorem environment
\newcounter{theo}[section]\setcounter{theo}{0}
\renewcommand{\thetheo}{\arabic{section}.\arabic{theo}}
\newenvironment{theo}{%
\refstepcounter{theo}%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut \textbf{Theorem~\thetheo.}};
\newline
}
\crefname{theo}{Theorem}{Theorems}
%new lemma environment
\newenvironment{lem}{%
\refstepcounter{theo}
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=blue!20]
{\strut \textbf{Lemma~\thetheo.}};
\newline
}
\begin{document}
\begin{theo}\label{thrm}
Just some text.
\end{theo}
\begin{lem}\label{lm1}
Just some more text.
\end{lem}
\begin{lem}\label[Lemma]{lm2}
Just some more text.
\end{lem}
\noindent
\cref{thrm}\\ %give Theorem 0.1
\cref{lm1}\\ %give Lemma 0.2
\cref{lm2}\\ %give Lemma 0.3
\end{document}
At the bottom of the example I use \cref three times. In a comment I display the desired output.
Here I used \crefname{theo}{Theorem}{Theorems}
to give the "theo"-environment the correct name, as you can see then the "lem"-environment gets the same name, when referred to. The second time I use the "lem"-environment, I label it using \label[Lemma]{lm2}
, which turns out not to have the desired effect.
(Note: The code that uses tikz is not relevant, I added it as a small justification for not using the \newtheorem command instead.)
\crefname{...}{...}
to determine what to print.\newline