[Tex/LaTex] \ref should use enumerate label name

#enumeratecross-referencinghyperref

I have done this:

\begin{enumerate}
\renewcommand{\labelenumi}{\textbf{S.\theenumi}}
\item a
\item \label{l} b
\item c. goto \ref{l}
\end{enumerate}

The \ref just uses the enumerate number. But I want it to be the full enumerate label.

I also could just type S.\ref{l} but that has the two disadvantages that

  1. if I update the enumerate label, I also have to update this reference,
  2. together with hyperref, this doesn't look so nice.

How would be a clean/nice way to solve this?

Best Answer

You can use the enumitem package:

\documentclass{article}
\usepackage{enumitem}

\begin{document}

\begin{enumerate}[label=\textbf{S.\arabic*}]
\item a
\item \label{l} b
\item c. goto \ref{l}
\end{enumerate}

\end{document}

enter image description here

or

\begin{enumerate}[label=\textbf{S.\arabic*},ref=S.\arabic*]
\item a
\item \label{l} b
\item c. goto \ref{l}
\end{enumerate}

if you don't want the reference to be boldfaced.

Related Question