Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to refer to all the items of an enumerate environment, by applying a label to the list. I tried this

\documentclass{article}[10pt]
\usepackage{amsmath, hyperref, enumerate}
\begin{document}
\setcounter{section}{1}
\begin{enumerate}\label{listref}
\item Mary
\item Had
\item A little
\item Lamb
\end{enumerate}
The poem \eqref{listref} is one of the best known childrens' rhymes.
\end{document}

but that did not produce the result required. I think labelling the first and the last items on the list is an option, but I was wondering if there is a smoother way of doing this.

share|improve this question
1  
What results should \eqref{listref} produce? "Poem (1)" because the referred enumerate environment is the first one in your document, or something else? –  lockstep Oct 26 '11 at 14:47
    
Hmm, I didn't think this through. I would like for there to be some way of identifying an entire numbered list and to be able to cross-reference using this identification elsewhere in the document. I wonder if this is possible, or if I will have to put this in a float or something like that. –  fg nu Oct 26 '11 at 14:56
    
@lockstep The \eqref{listref} actually produces nothing, or, (Doc-start) depending on whether I use the hyperref package or not.. –  fg nu Oct 26 '11 at 14:57
1  
Bear in mind that a list doesn't display its "number" in-text by default even if one adds a (referable) counter to lists. Consider to put your list inside a figure environment and to provide a name for this figure with \caption -- this way, you may refer to the figure. –  lockstep Oct 26 '11 at 15:01
1  
The following may be a possible duplicate: Label a complete enumeration. Please take a look as the answers there might help you. –  Werner Oct 26 '11 at 15:36

4 Answers 4

up vote 3 down vote accepted

For numbered environments which can be referenced, LaTeX provides theorem environments. They are not just theorems or definitions, you can use them more generally. You can

  • use titles,
  • attach the counter to a sectioning,
  • share counters,
  • and don't have to take care of defining an environment and managing a counter.

Further there are several packages for customizing these numbered environments, such as amsthm, ntheorem and thmtools. They provide predefined styles and ways for defining your own style.

Example:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{poem}{Poem}
\begin{document}
\begin{poem}\mbox{}\\[-\baselineskip]
  \begin{enumerate}\label{listref}
    \item Mary
    \item Had
    \item A little
    \item Lamb
    \end{enumerate}
\end{poem}
\noindent The poem \eqref{listref} is one of the best known childrens' rhymes.
\end{document}

numbered enumerate environment

For choosing a theorem package for customizing the format, have a look at: Theorem packages: which to use, which conflict?

share|improve this answer
    
Thanks for the reply Stefan. –  fg nu Oct 29 '11 at 17:19

I think you want something like this:

\newcounter{poemcnt}

\newenvironment{poem}%
  {\refstepcounter{poemcnt}\par Poem~\arabic{poemcnt}\begin{verse}}%
  {\end{verse}}

\begin{poem}
  \label{poemref}
  Mary\\
  Had\\
  A Little\\
  Lamb
\end{poem}

The poem~\ref{poemref} is one of the best known childrens' rhymes.

P.S. Mico asked for optional title. This is a little more involved :)

\newcounter{poemcnt}

\makeatletter
\newenvironment{poem}[1][]%
  {\refstepcounter{poemcnt}\par Poem~\arabic{poemcnt}%
    \def\@tempa{#1}\ifx\@tempa\@empty\else\space(#1)\fi
    \begin{verse}}%
  {\end{verse}}
\makeatother

\begin{poem}[Mary's Little Lamb]
  \label{poemref}
  Mary\\
  Had\\
  A Little\\
  Lamb
\end{poem}
share|improve this answer
    
Not trying to dwell too much on the fine points of typesetting poetry, but ... your poem environment does not seem to allow for a title. You could fix this by giving the environment an argument, which would be typeset right after Poem \arabic{poemcnt}. :-) –  Mico Oct 26 '11 at 15:24
    
Surely: \newcounter{poemcnt} \makeatletter \newenvironment{poem}[1][]% {\refstepcounter{poemcnt}\par Poem~\arabic{poemcnt} \def\@tempa{#1}\ifx\@tempa\@empty\else\space(#1)\fi \begin{verse}}% {\end{verse}} \makeatother \begin{poem}[Mary's Little Lamb] \label{poemref} Mary\ Had\ A Little\ Lamb \end{poem} –  Boris Oct 26 '11 at 15:30
    
Thanks for the reply Boris. –  fg nu Oct 29 '11 at 17:19

Bear in mind that a list doesn't display its "number" in-text by default even if one adds a (referable) counter to lists. Consider to put your list inside a figure environment and to provide a name for this figure with \caption -- this way, you may refer to the figure.

Note: \eqref{listref} produces nothing in your MWE because there's nothing to refer to in your document. Add \section{foo} immediately after \begin{document}, and your \eqref will (wrongly) refer to section 1.

share|improve this answer
    
Thanks @lockstep. –  fg nu Oct 29 '11 at 17:19

In order to cross-reference the poem as a whole, you need to place it in an environment that is itself numbered (more specifically, an environment or grouping that comes with a counter of some sort). For instance, one can cross-reference items in an enumerated list by attaching labels to the individual items. Consider, then, creating an enumerated list of poems as in the following example. (You could also place each poem in a figure environment, etc, as long as the environment has a counter.)

\documentclass{article}
\usepackage[colorlinks=true]{hyperref}
\begin{document}
\section*{Nursery Rhymes}
\begin{enumerate}
\item Mary Had a Little Lamb \label{poem:mary}
   \begin{verse}
   Mary had a little lamb\\
   Its fleece was white as snow\\
   And everywhere that Mary went\\
   The lamb was sure to go.
   \end{verse}
\item Humpty Dumpty \label{poem:humpty}
   \begin{verse}
   Humpty Dumpty sat on a wall\\
   Humpty Dumpty had a great fall\\
   And all the king's horses and all the king's men\\
   Couldn't put Humpty together again.
   \end{verse}
\end{enumerate}
Poems \ref{poem:mary} and \ref{poem:humpty} are among the best known nursery rhymes.
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.