Using the enumitem
package, I'm trying to cross-reference an item in an enumerate
list.
When I use
\ref
to cross-reference an item, I get the same, satisfactory, result no matter whether I create theenumerate
list directly in the body of the source, on the one hand, or use a\newlist
/\setlist
definition of the environment in the preamble. But why do I not get the same results in those two situations when I use\cref
instead of\ref
?Why don't the
\cref
results work in either situation?
This example, showing all 4 combinations of \ref
, \cref
, preamble-defined enumerate, and directly-defined enumerate, uses just the *
versions of the commands; but similar results occur with the unstarred versions.
Situation — \newlist
\setlist
with \ref*
:
\documentclass[12pt]{memoir}
\usepackage{enumitem}
\usepackage[colorlinks=true,linkcolor=red]{hyperref}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}
\newlist{romcases}{enumerate}{3}
\setlist[romcases,1]{%
label=\sffamily{Case (\roman*):},
ref=\normalfont{Case (\roman*)},
wide,itemsep=0pt,topsep=0pt
}
\crefname{romcases}{Case}{Case}
\Crefname{romcases}{Case}{Case}
\begin{document}
We distinguish two cases.
\begin{romcases}
\item \label{case:abequal}
$a = b$. Now we see that\dots
\item\label{case:abnotequal}
$a \neq b$. In contrast to \ref*{case:abequal}, in this case \dots
\end{romcases}
\bigskip
\textbf{\emph{NOTE:} Output as expected.}
\end{document}
Situation — direct \enumerate
with \ref*
:
\documentclass[12pt]{memoir}
\usepackage{enumitem}
\usepackage[colorlinks=true,linkcolor=red]{hyperref}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}
\begin{document}
We distinguish two cases.
\begin{enumerate}[%
label=\textsf{Case (\alph*):},ref=\normalfont{Case (\roman*)},
wide,itemsep=0pt,topsep=0pt]
\item \label{case:abequal}
$a = b$.
Now we see that\dots
\item\label{case:abnotequal}
$a \neq b$.
In contrast to \ref*{case:abequal}, in this case \dots
\end{enumerate}
\bigskip
\textbf{\emph{NOTE:} Output \emph{OK}.}
\end{document}
Situation — \newlist
\setlist
with \cref*
:
\documentclass[12pt]{memoir}
\usepackage{enumitem
\usepackage[colorlinks=true,linkcolor=red]{hyperref}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}
\newlist{romcases}{enumerate}{3}
\setlist[romcases,1]{%
label=\sffamily{Case (\roman*):},
ref=\normalfont{Case (\roman*)},
wide,itemsep=0pt,topsep=0pt
}
\crefname{romcases}{Case}{Case}
\Crefname{romcases}{Case}{Case}
\begin{document}
We distinguish two cases.
\begin{romcases}
\item \label{case:abequal}
$a = b$. Now we see that\dots
\item\label{case:abnotequal}
$a \neq b$. In contrast to \cref*{case:abequal}, in this case \dots
\end{romcases}
\bigskip
\textbf{\emph{NOTE:} Output \emph{NOT} as expected.}
\end{document}
Situation — direct \enumerate
with \cref*
:
\documentclass[12pt]{memoir}
\usepackage{enumitem}
\usepackage[colorlinks=true,linkcolor=red]{hyperref}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}
\begin{document}
We distinguish two cases.
\begin{enumerate}[%
label=\textsf{Case (\alph*):},ref=\normalfont{Case (\roman*)},
wide,itemsep=0pt,topsep=0pt]
\item \label{case:abequal}
$a = b$. Now we see that\dots
\item\label{case:abnotequal}
$a \neq b$. In contrast to \cref*{case:abequal}, in this case \dots
\end{enumerate}
\bigskip
\textbf{\emph{NOTE:} Output \emph{NOT} as expected.}
\end{document}
romcases
case, the level-1 counter variable is namedromcasesi
, notromcases
. Correct the first argument of\crefname
and\Crefname
and you'll be fine.enumi
. Thecleveref
package prefixes the string "Item" to objects associated with theenumi
counter. Because you also have the instructionref=\normalfont{Case (\roman*)}
, it is actually fully expected to get "Item Case (i)" as the output of\cref{case:abequal}
. If you want to keepref=\normalfont{Case (\roman*)}
and wish to use\cref
, you should run\crefname{enumi}{}{}
to override the default.