Reference to enumerate item with manually set label
You could define it like this:
\documentclass{article}
\usepackage{enumitem}
\makeatletter
\newcommand{\mylabel}[2]{#2\def\@currentlabel{#2}\label{#1}}
\makeatother
\begin{document}
\begin{enumerate}[label=\textnormal{(\arabic*)}]
\item text1\label{itm:1}.
\item text2\label{itm:2}.
\item[\mylabel{itm:2b}{(2')}] manually different label.
\item text3\label{itm:3}.
\end{enumerate}
Referencing to \ref{itm:1}\ref{itm:2}\ref{itm:2b}\ref{itm:3}.
\end{document}
If one is using hyperref
, the easiest way to print the prime and have a link pointing to the right item is to modify slightly the solution by Ambika Vanchinathan
by adding a dummy counter (that is, adding \newcounter{dummy}
in the preamble and \refstepcounter{dummy}
inside the definition of \mylabel
).
However, personally I would rather redefine \item
(instead of \label
) through:
\makeatletter
\newcommand\myitem[1][]{\item[#1]\refstepcounter{dummy}\def\@currentlabel{#1}}
\makeatother
With this definition, manual-labeled items should be introduced as
\myitem[(2')]\label{itm:2b}
That is, changes are minimal with respect to the usual way of introducing things, so that the new definition is easier to remember. I would also define a math-mode prime through
\newcommand*{\mprime}{\ensuremath{'}}
Complete MWE:
\documentclass{article}
\newcounter{dummy}
\usepackage{hyperref}
\usepackage{enumitem}
\makeatletter
\newcommand\myitem[1][]{\item[#1]\refstepcounter{dummy}\def\@currentlabel{#1}}
\makeatother
\newcommand*{\mprime}{\ensuremath{'}}
\begin{document}
\begin{enumerate}[label=\textnormal{(\arabic*)}]
\item text1\label{itm:1}.
\item text2\label{itm:2}.
\myitem[(2\mprime)]\label{itm:2b} manually different label.
\item text3\label{itm:3}.
\end{enumerate}
Referencing to \ref{itm:1}\ref{itm:2}\ref{itm:2b}\ref{itm:3}.
\end{document}