# Tag Archives: enumerate

## Inline lists in LaTeX using paralist

The paralist package implements the three standard lists: itemize, enumerate and description for usage within paragraphs. In other words, the package provides a way to create inline lists placed within normal text.

Besides the inline environments for the standard lists, the package also provides support to format the labels (bullets, numbering, etc.). However, for labeling and formatting of lists in general, I recommend the more powerful enumitem package. Please, see the paralist package documentation for more details on the functionality provided by the package.

The code for inline lists is straight forward and resamples the way standard lists are created. Therefore, I only posted one minimal working example for each environment below, without further explanations.

For more details on the standard list environments see this post and sample code here.

##### Inline enumerate (inparaenum)

\documentclass[11pt]{article}
\usepackage{paralist}
\begin{document}
This includes:
\begin{inparaenum}[1)]
\end{inparaenum}
to be completed by the end of the month.
\end{document}

Open code in writeLaTeX.

##### Inline itemize (inparaitem)

\documentclass[11pt]{article}
\usepackage{paralist}
\begin{document}
This includes:
\begin{inparaitem}
\end{inparaitem}
to be completed by the end of the month.
\end{document}

Open code in writeLaTeX.

\documentclass[11pt]{article}
\usepackage{paralist}
\begin{document}
This includes:
to be completed by the end of the month.
\end{document}

Open code in writeLaTeX.

According to the author, the last environment was added for completeness rather than usefulness.

If you do have any better idea than my brainless repetition of the same code, please let me know below!

You might have wondered about the link “Open code in writeLaTeX”. I am testing a collaboration with the folks over at writeLaTeX. The idea is to provide the possibility to open the code with one click in the browser, play with the examples and see the result right away. Let me know whether you find this useful!

## Stop loosing track of labels by displaying them in the PDF

Sometimes it is hard to keep track of labels, particularly in large documents with many figures, tables or equations. Unless you remember all label names by heart, you will likely scroll up and down till you find the particular position in the text where the label is defined. The showlabels package provides a convenient way for keeping track of label names. It displays them in the PDF next to the text element it was defined for.

Usage is straight forward, it is sufficient to load the package in the preamble of the document:

\usepackage{showlabels}

By default, labels are printed to the outer margin. Options are available to display labels in the inner/left/right margin or inline. See the package documentation for more details.

Furthermore, you can print arguments to pretty much any command. This is particularly useful for cite. See below for an example.

\showlabels{cite}

Obviously, this is not something you want in the final document. Either just delete all the code related to the package or better, use the final option to mute it:

\usepackage[final]{showlabels}

Example: figure

Example: equation

Example: enumerate

Example: cite

\documentclass{article}
\usepackage{showlabels, bibentry}
\usepackage{blindtext}
\showlabels{cite}
\begin{filecontents}{publication.bib}
@article{lamport1986latex,
title={LaTEX: User's Guide \&amp; Reference Manual},
author={Lamport, L.},
year={1986},
}
\end{filecontents}
\begin{document}
\blindtext
\section{Figure}
\begin{figure}[ht]
\centering
\rule{4cm}{3cm}
\caption{default}
\label{fig:default}
\end{figure}
\section{Equation}
$$\label{eq:default}f(x)=ax^2+bx+c$$
\section{Enumerate}
\begin{enumerate}
\item First item\label{itm:first}
\item Second item\label{itm:second}
\end{enumerate}
\section{Citation}
\cite{lamport1986latex}\\
\nobibliography{publication}
\end{document}

First seen here.

## 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 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

## 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.

Nested lists:

Lists can be nested. In other words, it is possible to have a sub-list for an item of a list. Usage is straight forward, different environments can be mixed (see example) and the maximum depth (number of levels) is 4. Here is an example:

\begin{itemize}
\item First level, itemize, first item
\begin{itemize}
\item Second level, itemize, first item
\item Second level, itemize, second item
\begin{enumerate}
\item Third level, enumerate, first item
\item Third level, enumerate, second item
\end{enumerate}
\end{itemize}
\item First level, itemize, second item
\end{itemize}

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}