4

The following MWE should display

(2) Test

(2') Test

Reference to (2').

but the last line only says "Reference to ", with no reference. How can I achieve the desired effect ?

\documentclass[a4paper,12pt]{article}
\usepackage{enumerate}

\begin{document}

\begin{enumerate}
  \item[(2)]\label{item:2} Test
  \item[(2')]\label{item:2p} Test
  \end{enumerate}
  Reference to \ref{item:2p}.
\end{document}
  • The \item[foo] does not provide the correct reference label here, since enumi counter is not at all – user31729 Sep 7 '16 at 13:52
4

Since \item[foo] does not increase the enumi counter (it is the enumerate environment on 1st level here) with \refstepcounter, the \label command cannot apply the correct reference 'number' -- this is generated by \refstepcounter and stored in the \@currentlabel macro -- no \refstepcounter means that \@currentlabel is empty here.

An approach can be to use a wrapper command, say \myitem and store the argument as the \@currentlabel value. This way, \label works as expected.

Since \@currentlabel is an @ - letter - command, the \makeatletter...\makeatother pair has to be wrapped around the definition of \myitem.

The name of \myitem is somewhat arbitray, of course, as long as no name of an already existing command sequence or primitive is used.

\documentclass[a4paper,12pt]{article}
\usepackage{enumerate}

\makeatletter
\newcommand{\myitem}[1]{%
\item[#1]\protected@edef\@currentlabel{#1}%
}
\makeatother

\begin{document}

\begin{enumerate}
  \myitem{(2)}\label{item:2} Test
  \myitem{(2')}\label{item:2p} Test
  \end{enumerate}
  Reference to \ref{item:2} and \ref{item:2p}
\end{document}

enter image description here

  • Catching \item[...] would be possible too, but this is easier, in my point of view – user31729 Sep 7 '16 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.