4

Whenever I try to label an item that is defined, it never seems to work. For example, consider the following:

\documentclass{article}
\usepackage{enumitem}
\usepackage[noabbrev]{cleveref}
\begin{document}
\begin{enumerate}
  \item[3.1]
  \item[6.3]
  \label{prob63}
  \item
    From \cref{prob63}, some statement
\end{enumerate}
\end{document}
lockstep
  • 250,273
dustin
  • 18,617
  • 23
  • 99
  • 204

1 Answers1

5

I think this may be partly because one can use non-counter-style entries when using the optional argument to \item[<stuff>]. So, in that regard, you can set this manually so that the reference appears as you want:

enter image description here

\documentclass{article}
\usepackage{enumitem}
\usepackage[noabbrev]{cleveref}
\makeatletter
\newcommand{\setcreflabel}[1]{%
  \protected@edef\cref@currentlabel{%
    [\@tempa][#1][\cref@result]%
    #1}}%
\makeatother
\begin{document}
\begin{enumerate}
  \item \label{prob1}
  \item[6.3] \setcreflabel{6.3}\label{prob63}
  \item
    From \cref{prob63}, some statement; From \cref{prob1}, some statement.
\end{enumerate}
\end{document}

The motivation here is to update \cref@currentlabel in an analogous way to how \refstepcounter updates \@currentlabel. In that way, when you issue \label, the correct reference content is written to the .aux:

\relax 
\newlabel{prob1}{{1}{1}}
\newlabel{prob1@cref}{{[enumi][1][]1}{1}}
\newlabel{prob63}{{1}{1}}
\newlabel{prob63@cref}{{[enumi][6.3][]6.3}{1}}
Werner
  • 603,163