Text FormattingReferencing Item Numbers

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
kapowza
Posts: 19
Joined: Fri Jan 30, 2009 3:32 pm

Referencing Item Numbers

Post by kapowza »

I have a question about referencing list items. I'm making a question sheet for my students. Some questions are phrased in the form "use the following information for questions 5, 6 and 7"

So, my latex code looks something like this:

Code: Select all

\begin{enumerate}
\item Question one goes here
\item Question two goes here\\
Use the following information for questions 3, 4 and 5. $x = 1$, $y = 2$ and $z = 3$.
\item Question three goes here
\item Question four goes here
\item Question five goes here
\end{enumerate}
Obviously, if I end up adding more questions before questions 3, 4 and 5, then I'd want it to say "use the following for questions 4, 5, and 6"...or whereever those questions end up. So, I'm wondering if there's some way to reference the item numbers in my enumerated list?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Referencing Item Numbers

Post by gmedina »

Hi,

you can use the standard \label, \ref mechanism:

Code: Select all

\documentclass{article}

\begin{document}

\begin{enumerate}
  \item\label{ite:fir} First item.
  \item\label{ite:sec} Second item.
  \item\label{ite:thi} Third item.
  \item\label{ite:fou} Fourth item.
  \item\label{ite:fif} Fifth item.
\end{enumerate}

As you can see in items \ref{ite:sec}, \ref{ite:fou} and \ref{ite:fif}...

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
kapowza
Posts: 19
Joined: Fri Jan 30, 2009 3:32 pm

Re: Referencing Item Numbers

Post by kapowza »

Thanks! That's exactly what I was looking for.
kapowza
Posts: 19
Joined: Fri Jan 30, 2009 3:32 pm

Referencing Item Numbers

Post by kapowza »

Just a quick followup question:

When I use the label/reference with a nested list, as in:

Code: Select all

\begin{enumerate}
\item Item
\begin{enumerate}[i]
  \item\label{ite:fir} First subitem.
  \item\label{ite:sec} Second subitem.
  \item\label{ite:thi} Third subitem.
\end{enumerate}
\item Next item
\end{enumerate}

As you can see in items \ref{ite:fir}, \ref{ite:sec} and \ref{ite:thi}...
The references include both the original item number and the sublist number. In other words, the references above appear as 9i, 9ii, 9iii. Whereas, I'd like the references to appear as just i, ii, iii. Is there a simple way to do this?
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Referencing Item Numbers

Post by Juanjo »

Presumably you are loading the enumerate package. Use enumitem instead, as shown below:

Code: Select all

\documentclass{article}
\usepackage{enumitem}

\begin{document}

\begin{enumerate}
\item Item
\begin{enumerate}[label=\roman*]
\item\label{ite:fir} First subitem.
\item\label{ite:sec} Second subitem.
\item\label{ite:thi} Third subitem.
\end{enumerate}
\item Next item
\end{enumerate}

As you can see in items \ref{ite:fir}, \ref{ite:sec} and \ref{ite:thi}...

\end{document}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Referencing Item Numbers

Post by localghost »

The enumerate package is superseded by enumitem. Use the latter one and your code will work fine.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage{enumitem}

\begin{document}
  \begin{enumerate}
    \item Item
      \begin{enumerate}[label={\roman*}]
        \item\label{ite:fir} First subitem.
        \item\label{ite:sec} Second subitem.
        \item\label{ite:thi} Third subitem.
      \end{enumerate}
    \item Next item
  \end{enumerate}

  \ref{ite:fir}
\end{document}

Best regards
Thorsten¹
Post Reply