97

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?

4 Answers 4

130

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.

3
  • This is nice. I would like to add that it does not work together with \usepackage{paralist} ... if you need to use that package.
    – peschü
    Mar 12, 2017 at 20:19
  • 1
    I'm curius, what does the * after \arabic stands for? Nov 14, 2019 at 10:22
  • 1
    @GillesBonnet The * automatically picks the correct counter, such as enumi or enumii depending on the level of nesting.
    – hife
    Apr 9, 2022 at 18:19
22

For your attempt properly work, you need redefine the counter representation (\theenumi) as well as the label associated with it (\labelenumi). This separates the formatting from the counter when you're using \ref:

enter image description here

\documentclass{article}
\begin{document}
\begin{enumerate}
\renewcommand{\labelenumi}{\textbf{\theenumi}}
\renewcommand{\theenumi}{S.\arabic{enumi}}
\item a
\makeatletter
\show\@currentlabel
\makeatother
\item \label{l} b
\item c. goto \ref{l}
\end{enumerate}
\end{document}

This also works nicely with hyperref. However, in general, it is much easier to use enumitem since it can be used in a global or localized setting using a key-value approach; very convenient.

1

For all counters in LaTeX (not needing packages) there is a macro \p@counter used as a prefix in label/ref for that counter. So the matching set of definitions would be

\makeatletter
\renewcommand{\labelenumi}{\textbf{\theenumi}}
\renewcommand{\theenumi}{S.\arabic{enumi}}
\renewcommand{\p@enumi}{S.}
\makeatother

The more natural way of doing it would be to leave \theenumi as just the counter value, and put all adornment in the others

\makeatletter
\renewcommand{\labelenumi}{\textbf{S.\theenumi}}
\renewcommand{\theenumi}{\arabic{enumi}}
\renewcommand{\p@enumi}{S.}
\makeatother
0

With packages paralist works as well

\documentclass{article}
\begin{document}
\usepackage{paralist}
\begin{enumerate}[\bfseries{S}.1]
\item a
\makeatletter
\show\@currentlabel
\makeatother
\item \label{l} b
\item c. goto \ref{l}
\end{enumerate}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .