Document ClassesEnumeration package: Can \ref print the whole label?

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
Michi20
Posts: 1
Joined: Wed Aug 20, 2008 2:37 pm

Enumeration package: Can \ref print the whole label?

Post by Michi20 »

Hi,

i have a question concerning the enumeration package of David Carlisle and the \ref - command.

I have the following code:

\begin{enumeration}[Step (1)]
\item \label{AA} ...
.
.
.
\end{enumeration}

Then \ref{AA} just prints '1'. Is there a way to change this behaviour such that \ref{AA} prints the whole label and not just the number, i. e. 'Step 1'?

Thank you
Michi

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Enumeration package: Can \ref print the whole label?

Post by gmedina »

Hi,

to customise the list-like environments I would recommend you to use the enumitem package. Your example:

Code: Select all

\documentclass{book}
\usepackage{enumitem}

\begin{document}

\begin{enumerate}[label=Step (\arabic*)]
\item \label{AA}
\item \label{BB}
\end{enumerate}

As can be seen in \ref{AA}...
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Enumeration package: Can \ref print the whole label?

Post by Juanjo »

For simple lists, you don't need any package. The enumerate environment can be easily customized, as the following example shows:

Code: Select all

\documentclass{article}

\begin{document}

\begin{enumerate}
 \renewcommand{\theenumi}{Step (\arabic{enumi})}
 \item\label{AAA} Text.
 \item More text.
\end{enumerate}

Here we write a reference to \ref{AAA}.

\begin{enumerate}
 \renewcommand{\theenumi}{[\Roman{enumi}]}
 \renewcommand{\labelenumi}{\textbf{Level \theenumi}.-}
 \item\label{BBB} Text
 \item More text
\end{enumerate}

Here we write a reference to level or stage \ref{BBB}.
\end{document}

For numbered nested lists, you may need to replace enumi by enumii, enumiii or enumiv in the above code. Note that:
  • \ theenumi controls the way the counter is printed (think in the way you would like to print the counter in a future reference to the corresponding item);
  • \ labelenumi indicates how the full label should be printed;
  • the redefinition of both commands should be done inside the enumerate environment in order to not change any subsequent list.
Simple customization of non-numbered lists can be done analogously through the commands \labelitemi, \labelitemii,...
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Post Reply