Tag Archives: enumerate

Cross-referencing list items

List items of numbered lists (enumerate) can be cross-referenced using the standard \label{} and \ref{} command pair. Cross-referencing description items is not supported by default, but can be done with a few additional lines of code in the preamble.

Enumerate
Ordered or numbered lists are cross-referenced with the label-ref command pair similar to figures, tables or chapters. The label can either be place right after \item or after the item’s text. The cross-reference \ref{} works within and outside the list as shown in the example below.

\documentclass[11pt]{article}
\usepackage{hyperref}
\begin{document}
\begin{enumerate}
	\item \label{itm:first} This is a numbered item
	\item Another numbered item \label{itm:second}
	\item \label{itm:third} Same as \ref{itm:first}
\end{enumerate}
Cross-referencing items \ref{itm:second} and \ref{itm:third}.
\end{document}

Cross-referencing numbered items in lists (enumerate).

Loading the hyperref package, automatically adds links to cross-references and allows navigation to list items by clicking the reference.

Description
By default, items in a description can’t be cross-referenced. LaTeX would just use the number of the section/chapter. SX has a solution with a few lines of additional code in the preamble.

\documentclass[11pt]{article}
\usepackage{enumitem, hyperref}
\makeatletter
\def\namedlabel#1#2{\begingroup
	#2%
	\def\@currentlabel{#2}%
	\phantomsection\label{#1}\endgroup
}
\makeatother
\begin{document}
\begin{description}[style=multiline, labelwidth=1.5cm]
	\item[\namedlabel{itm:rule1}{Rule 1}] Everything is easy with \LaTeX
	\item[\namedlabel{itm:rule2}{Rule 2}] Sometimes it is not that easy\\
		$\to$ \ref{itm:rule1} applies
\end{description}
\end{document}

Cross-referencing description items

The code in the preamble defines a new command namedlabel which produces the name when cross-referencing the item. In the example, the enumitem package is loaded for a correct alignment of multiline items (see documentation for details)

Itemize
Cross-referencing items in unordered lists (bullet items) is not supported and wouldn’t make sense anyway, since individual items don’t have an unique identifier.


Reverse enumerate or etaremune

I stumbled across this package recently thanks to a comment by ofer.

Basically, the etaremune package inverses the enumerate counter, making the indices decreasing rather than increasing.

Basic example:

\documentclass{article}
\usepackage{etaremune}
\begin{document}
\begin{etaremune}
	\item Third item
	\item Second item
	\item First item
\end{etaremune}
\end{document}

basic_etaremune

Basic etaremune example.

Furthermore, to make the package more flexible, it offers different customizations.

Starting number:

The start option, lets you begin with an arbitrary number. In case the starting number is smaller than the number of items, the counter won’t further decrease once it reaches zero.

\usepackage{etaremune}[start=7]

Nesting (with enumerate):

Normal lists can be nested and so can etaremune lists. The lists can also be mixed with normal, enumerate lists. The documentation has a very nice example which I will just reuse here:

\renewcommand{\labelenumi}{\theenumi)}
\renewcommand{\theenumii}{\roman{enumii}}
\begin{enumerate}
	\item First.
	\begin{etaremune}
		\item third.\label{notice}
		\item second.
		\item first.
	\end{etaremune}
	\item Second.
	\item Third.
\end{enumerate}
Notice item~\ref{notice}.

Controlling the style:

Finally, the package allows the usage of some options for both, global and local style control.

Global options:

\usepackage[<options>]{etaremune}

Local options:
\begin{etaremune}[<options>]

Available options:

Vertical lengths control:
\topsep, \partopsep, \itemsep and \parsep.

Horizontal lengths control:
\leftmargin, \rightmargin, \listparindent, \itemindent, \labelwidth and \labelsep.

Here is the example from above slightly extended with the options itemsep and parsep set to zero. The first reduces the space between items of the same level to a minimum, whereas the latter between levels.

\documentclass{article}
\usepackage{etaremune}
\begin{document}
\renewcommand{\labelenumi}{\theenumi)}
\renewcommand{\theenumii}{\roman{enumii}}
\renewcommand{\theenumiii}{\Alph{enumiii}}
\begin{enumerate}
	\item First
	\item Second
	\begin{etaremune}[itemsep=0pt,parsep=0pt]
		\item third.\label{notice}
		\item second.
		\begin{etaremune}
			\item subsecond
			\item subfirst
		\end{etaremune}
		\item first.
	\end{etaremune}
	\item Third
\end{enumerate}
Notice item~\ref{notice}.
\end{document}

etaremune example

etaremune example


Increase enumerate & itemize depth with enumitem

The default maximum depth for the list environments enumerate and itemize is four. Using more than four nested levels will lead to the error: “Too deeply nested”.

One way to increase the depth of a list is using a mix of enumerate and itemize. However, obviously, some levels will be a bulleted rather than enumerated.

The enumitem package allows you to define new lists with an arbitrary number of levels. For example, let’s create nested lists with up to five levels.
Define a new list longenum of type enumerate which has 5 levels. Set the label style for each level they way you like. I used roman, alph and arabic.

\usepackage{enumitem}
\newlist{longenum}{enumerate}{5}
\setlist[longenum,1]{label=\roman*)}
\setlist[longenum,2]{label=\alph*)}
\setlist[longenum,3]{label=\arabic*)}
\setlist[longenum,4]{label=(\roman*)}
\setlist[longenum,5]{label=(\alph*)}

That’s all you need to know. The rest is straight forward, just use longenum instead of enumerate for each level and create a nested lists with up to 5 levels.

Here is the complete sample code with the output below:

\documentclass[11pt]{article}
\usepackage{enumitem}
\newlist{longenum}{enumerate}{5}
\setlist[longenum,1]{label=\roman*)}
\setlist[longenum,2]{label=\alph*)}
\setlist[longenum,3]{label=\arabic*)}
\setlist[longenum,4]{label=(\roman*)}
\setlist[longenum,5]{label=(\alph*)}
\begin{document}
\section*{Enumerated list with 5 levels}
\begin{longenum}
	\item Level 1 first
	\item Level 1 second
	\begin{longenum}
		\item Level 2 first
		\item Level 2 second
		\begin{longenum}
			\item Level 3 first
			\item Level 3 second
			\begin{longenum}
				\item Level 4 first
				\item Level 4 second
				\begin{longenum}
					\item Level 5 first
					\item Level 5 second
				\end{longenum}
			\end{longenum}
		\end{longenum}
	\end{longenum}
\end{longenum}
\end{document}

Enumitem package documentation.


Generating dummy text/blindtext with Latex for testing

I was often using any of the available “lorem ipsum” generators on the web while testing different things in Latex until I discovered that the Latex distribution provides packages generating blind text, which is definitely more convenient. With just a few lines of code, these packages will generate paragraphes, even whole documents with sections, paragraphs of text, lists, etc.

The first package that I will introduce is the “blindtext” package. First the language option as well as the package have to be loaded. Make sure you get the order right, otherwise your text might appear in latin by default.

\usepackage[english]{babel}
\usepackage{blindtext}

The language options english, (n)german and latin are available. French is also available, but in a preliminary version. Try it out yourself :-) .

Now you are ready to create a paragraph or even a whole document with just one line of code.

For few/more paragraphs of normal text:

\blindtext
\Blindtext

For a small/large document:

\blinddocument
\Blinddocument

In an arbitrary number of repetitions, e.g.

\blindtext[5]

Furthermore,

\blindlist{env}[x]

creates a list with “x” being the number of items generated. The environment can be set to itemize, enumerate or description.

A more direct way to generate lists is by using the commands:

\blinditemize
\blindenumerate
\blinddescription

and their extended versions with capital letters are available. Similarly, the number of items is defined through the optional argument, e.g.

\blindenumerate[10]

If you want math within the text, use

\blindmathtrue
\blindmathfalse

respectively.

It is also possible to generate text with math including formulas, using

\blindmathpaper

The “lipsum” package is a more basic package. It generates a certain number of the standard “lorem ipsum” text:

\usepackage{lipsum}
...
\lipsum
\lipsum[3-56]

By default, the package will either generate slightly more than a single page (fist line). Alternatively, it generates an arbitrary number of paragraphs (second line).

For more information, please refer to the package information of the blindtext as well as the lipsum packages.


Lists: Enumerate, itemize, description and how to change them

Latex distinguishes between three different enumeration/itemization environments. Each of them provide four levels, which means you can have nested lists of up to four levels.

Enumerate:

\begin{enumerate}
\item ...
\end{enumerate}

The enumerate-environment is used to create numbered lists.
If you like to change the appearance of the enumerator, the simplest way to change is to use the enumerate-package, giving you the possibility to optionally choose an enumerator.

\usepackage{enumerate}
...
\begin{enumerate}[I]%for capital roman numbers.
\item
\end{enumerate}

 

\begin{enumerate}[(a)]%for small alpha-characters within brackets.
\item
\end{enumerate}

Itemize:

\begin{itemize}
\item ...
\end{itemize}

Itemization is probably the mostly used list in Latex. It also provides four levels. The bullets can be changed for each level using the following command:

\renewcommand{\labelitemi}{$\bullet$}
\renewcommand{\labelitemii}{$\cdot$}
\renewcommand{\labelitemiii}{$\diamond$}
\renewcommand{\labelitemiv}{$\ast$}

Amongst the more commonly used ones are $\bullet$ (\bullet), $\cdot$ (\cdot), $\diamond$ (\diamond), $-$ (-), $\ast$ (\ast) and $\circ$ (\circ).

Description:

\begin{description}
\item[] ...
\end{description}

The description list might be the least known. It comes in very handy if you need to explain notations or terms. Its neither numbered nor bulleted.

Example:

\begin{description}
\item[Biology] Study of life.
\item[Physics] Science of matter and its motion.
\item[Psychology] Scientific study of mental processes and behaviour.
\end{description}

And in a PDF it would look like this:

Example of a description list.

Example of a description list.

Note:

The space between different items can be controlled with the \itemsep command (can only be added just after “begin”):

\begin{itemize}\itemsep2pt
\item
\end{itemize}


Follow

Get every new post delivered to your Inbox.

Join 316 other followers