LaTeX/List Structures

From Wikibooks, open books for an open world
Jump to: navigation, search
LaTeX logo.svg

LaTeX

Getting Started
  1. Introduction
  2. Installation
  3. Installing Extra Packages
  4. Basics

Common Elements

  1. Document Structure
  2. Text Formatting
  3. Paragraph Formatting
  4. Colors
  5. Fonts
  6. List Structures
  7. Special Characters
  8. Internationalization
  9. Rotations
  10. Tables
  11. Title creation
  12. Page Layout
  13. Importing Graphics
  14. Floats, Figures and Captions
  15. Footnotes and Margin Notes
  16. Hyperlinks
  17. Labels and Cross-referencing

Mechanics

  1. Errors and Warnings
  2. Lengths
  3. Counters
  4. Boxes
  5. Rules and Struts

Technical Texts

  1. Mathematics
  2. Advanced Mathematics
  3. Theorems
  4. Chemical Graphics
  5. Algorithms
  6. Source Code Listings
  7. Linguistics

Special Pages

  1. Indexing
  2. Glossary
  3. Bibliography Management
  4. More Bibliographies

Special Documents

  1. Letters
  2. Presentations
  3. Teacher's Corner
  4. Curriculum Vitae

Creating Graphics

  1. Introducing Procedural Graphics
  2. MetaPost
  3. Picture
  4. PGF/TikZ
  5. PSTricks
  6. Xy-pic
  7. Creating 3D graphics

Programming

  1. Macros
  2. Plain TeX
  3. Creating Packages
  4. Themes

Miscellaneous

  1. Modular Documents
  2. Collaborative Writing of LaTeX Documents
  3. Export To Other Formats

Help and Recommendations

  1. FAQ
  2. Tips and Tricks

Appendices

  1. Authors
  2. Links
  3. Package Reference
  4. Sample LaTeX documents
  5. Index
  6. Command Glossary

edit this boxedit the TOC

Convenient and predictable list formatting is one of the many advantages of using LaTeX. Users of WYSIWYG word processors can sometimes be frustrated by the software's attempts to determine when they intend lists to begin and end. As a mark-up language, LaTeX gives more control over the structure and content of lists.

List structures[edit]

Lists often appear in documents, especially academic, as their purpose is often to present information in a clear and concise fashion. List structures in LaTeX are simply environments which essentially come in three flavors: itemize, enumerate and description.

All lists follow the basic format:

\begin{list_type}

  \item The first item
  \item The second item
  \item The third etc \ldots

\end{list_type
}

All three of these types of lists can have multiple paragraphs per item: just type the additional paragraphs in the normal way, with a blank line between each. So long as they are still contained within the enclosing environment, they will automatically be indented to follow underneath their item.

Itemize[edit]

This environment is for your standard bulleted list of items.

\begin{itemize}
  \item The first item
  \item The second item
  \item The third etc \ldots
\end{itemize
}

Itemize.svg

Enumerate[edit]

The enumerate environment is for ordered lists, where by default, each item is numbered sequentially.

\begin{enumerate}
  \item The first item
  \item The second item
  \item The third etc \ldots
\end{enumerate
}

Enum.svg

Description[edit]

The description environment is slightly different. You can specify the item label by passing it as an optional argument (although optional, it would look odd if you didn't include it!). Ideal for a series of definitions, such as a glossary.

\begin{description}
  \item[First] The first item
  \item[Second] The second item
  \item[Third] The third etc \ldots
\end{description
}

Example of description environment result using LaTeX.svg

Sometimes you want a description where the text begins on a new line. This cannot easily be done with \\. The trick is to use \hfill[1].

\begin{description}
  \item[First] \hfill \\
  The first item
  \item[Second] \hfill \\
  The second item
  \item[Third] \hfill \\
  The third etc \ldots
\end{description
}

LaTeX desc-newline.svg

Nested lists[edit]

LaTeX will happily allow you to insert a list environment into an existing one (up to a depth of four—if you need more than four, use the easylist package). Simply begin the appropriate environment at the desired point within the current list. Latex will sort out the layout and any numbering for you.

\begin{enumerate}
  \item The first item
  \begin{enumerate}
    \item Nested item 1
    \item Nested item 2
  \end{enumerate}
  \item The second item
  \item The third etc \ldots
\end{enumerate
}

Nested.svg

Customizing lists[edit]

Customizing LaTeX is outside the beginners' domain. While not necessarily difficult in itself, because beginners are already overwhelmed with the array of commands and environments, moving on to more advanced topics runs the risk of confusion.

However, since the tutorial aims at being complete, we shall still include a brief guide on customizing lists. Feel free to skip!

Note that in the following when \renewcommand is used it must appear after the \begin{document} instruction so the changes made are taken into account. This is needed for both enumerated and itemized lists.

Also beware of the spaces in the label definitions. It is a common error!

Line spacing[edit]

As you may have noticed, in standard LaTeX document classes, the vertical spacing between items, and above and below the lists as a whole, is more than between paragraphs: it may look odd if the descriptions are too short.

Using packages[edit]

If you want tightly-packed lists, use the mdwlist package (included in the mdwtools bundle), which provides compact, "starred" versions of the previous environments, i.e. itemize*, enumerate* and description*. They work exactly in the same way, but the output is more compact. Other packages providing compacted lists are paralist and enumitem.

Alternatively, use the memoir class and with \tightlists.

Customizing manually[edit]

Inside lists you can redefine some length/dimension variables of LaTeX, for example using:

\begin{itemize} \itemsep1pt \parskip0pt \parsep0pt
  \item first item
  \item second item
\end{itemize
}

Alternatively, to create a unified look in your document you can redefine the enumerate environment:

\let\oldenumerate\enumerate
\renewcommand{\enumerate}{
  \oldenumerate
  \setlength{\itemsep}{1pt}
  \setlength{\parskip}{0pt}
  \setlength{\parsep}{0pt}
}

Another approach is to redefine the \item command globally.

\newlength{\wideitemsep}
\setlength{\wideitemsep}{.5\itemsep}
\addtolength{\wideitemsep}{-7pt}
\let\olditem\item
\renewcommand{\item}{\setlength{\itemsep}{\wideitemsep}\olditem
}

Customizing enumerated lists[edit]

Using packages[edit]

The thing people want to change most often with Enumerated lists are the counters. A quick solution to this problem is provided by the enumerate package of David Carlisle[2], or the more sophisticated package enumitem by Javier Bezos[3]. When using enumitem, it is possible to specify the style of the numbering: \begin{enumerate}[style].

The options A, a, I, i and 1 define the style and are self-explanatory, anything else is treated as text. To use any of the style tokens as text they can be enclosed in braces, e.g. {A} will give a literal A. [4]

Sometimes you may want to place some short text in front of the enumeration for example: "Exercise 1, Exercise 2, Execise 3, ...". This is possible with the enumitem package:

\begin{enumerate}[label=\bfseries Exercise \arabic*:]
  \item 5 + 7 = 12
  \item 9 + 1 = 10
  \item 2 * 2 = 4
\end{enumerate
}

Enumeration with text

\bfseries makes it bold, Exercise is the text and \arabic* inserts the counter followed by a colon (:) which is treated as text again.

Manually[edit]

To go any further and do it yourself instead, a brief introduction to LaTeX counters is required. You should check the dedicated chapter as we will not delve into the details for now.

There are four individual counters that are associated with itemized lists, each one represents the four possible levels of nesting, which are called:

enumi
enumii
enumiii
enumiv

The counter is incremented by \item before it is printed. For example to reset enumi use:

\begin{enumerate}
  \setcounter{enumi}{4}
  \item fifth element
\end{enumerate
}

5. fifth element

The command responsible for formatting the various levels of nesting are

\labelenumi
\labelenumii
\labelenumiii
\labelenumiv

Example:

\renewcommand{\labelenumi}{(\Roman{enumi})}
\renewcommand{\labelenumii}{\Roman{enumi}.~\alph{enumii}
}

This simply redefines the appearance of the label, which is fine, providing that you do not intend to cross-reference to a specific item within the list, in which case the reference will be printed in the original format. This issue does not arise if you redefine the counter printer:

\renewcommand{\theenumi}{\Roman{enumi}}
\renewcommand{\labelenumi}{(\theenumi)}
\renewcommand{\theenumii}{\alph{enumii}}
\renewcommand{\labelenumii}{\theenumi.~\theenumii
}

Customizing itemized lists[edit]

Itemized lists are not as complex as they do not need to count. Therefore, to customize, you simply change the labels. It can be done manually for each entry with \item[new symbol], eg \item[$\star$].

The itemize labels are accessed via \labelitemi, \labelitemii, \labelitemiii, \labelitemiv, for the four respective levels.

\renewcommand{\labelitemi}{\textgreater}

The above example would set the labels for the first level to a greater than (>) symbol. Of course, the text symbols available in Latex are not very exciting. Why not use one of the ZapfDingbat symbols, as described in the Symbols section. Or use a mathematical symbol:

\renewcommand{\labelitemi}{$\star$}

Itemized list with tightly set items, that is with no vertical space between two consecutive items, can be created as follows.

\begin{itemize}
  \setlength{\itemsep}{0cm
}%
  \setlength{\parskip}{0cm}%
  \item Item opening the list
  \item Item tightly following
\end{itemize}

Inline lists[edit]

Inline lists can be achieved as follows.

With package paralist[edit]

The paralist package provides the inparaenum environment (with an optional formatting specification in square brackets):

\usepackage{paralist}
% ...

\begin{document}

Inline lists, which are
sequential in nature, just like enumerated
lists, but are
\begin{inparaenum}[\itshape a\upshape)]
\item formatted within their paragraph;
\item usually labelled with letters; and
\item usually have the final item prefixed with
`and' or `or',
\end{inparaenum
} like this example.
...

Latex example paralist.svg

To change the styles of the counter, tokens A, a, I, i, and 1 can be used in the optional argument to produce the counter with one of the styles \Alph, \alph, \Roman, \roman and \arabic. For example: \begin{inparaenum}[(i)] produces the labels (i), (ii), (iii) ...


With package enumitem[edit]

\usepackage[inline]{enumitem}
% ...

\begin{document}

Inline lists, which are
sequential in nature, just like enumerated
lists, but are
\begin{enumerate*}[label=\itshape\alph*\upshape)]
\item formatted within their paragraph;
\item usually labelled with letters; and
\item usually have the final item prefixed with
`and' or `or',
\end{enumerate*
} like this example.
...

Latex example enumitem inline list.svg

Package shortlst also provides inline lists.

Easylist package[edit]

The easylist package [5] allows you to create list using a more convenient syntax and with infinite nested levels. It is also very customizable.

Load the package with the control character as optional argument:

\usepackage[ampersand]{easylist}

The easylist environment will default to enumerations.

\begin{easylist}
& Main item~:
&& Sub item.
&& Another sub item.
\end{easylist
}

It features predefined styles which you can set as optional argument.

\begin{easylist}[itemize]
% ...
\end{easylist}

Available styles:

  • tractatus
  • checklist - All items have empty check boxes next to them
  • booktoc - Approximately the format used by the table of contents of the book class
  • articletoc - Approximately the format used by the table of contents of the article class
  • enumerate - The default
  • itemize

You can customize lists with the \ListProperties(...) command and revert back the customization with \newlist{}. Yes, that's parentheses for \ListProperties parameters.

The Style parameter sets the style of counters and text, the Style* parameter sets the sytle of counters, and the Style** parameter sets the style of text. The parameter Numbers determines the way that the numbers are displayed and the possible values are r or R (for lower and upper case Roman numerals), l or L (for lower and upper case letters), a (for Arabic numbers, the default), and z (for Zapf's Dingbats).

The FinalMark parameter sets the punctuation of the final counter (Ex: FinalMark3={)}) while FinalSpace sets the amount of space between the item and the item's text. The Margin parameter sets the distance from the left margin (Ex: FinalSpace2=1cm). The Progressive parameter sets the distance from the left margin of all items in proportion to their level.

The {{{1}}} parameter prevents the first n counters from appearing in all levels. If there is a number after a parameter (Ex: Style3*) then this numbers indicates the level that it will affect (Ex: Style3=\color{red}).

Example of custom enumerate:

\begin{easylist}[enumerate]
\ListProperties(Style2*=,Numbers=a,Numbers1=R,FinalMark={)})
& Main item~:
&& Sub item.
&& Another sub item.
\end{easylist
}

Note that we put the FinalMark argument between {} to avoid LaTeX understanding it as the end of the properties list. Now we change the default properties to print a custom itemize:

\usepackage{amssymb}
\ListProperties(Hide=100, Hang=true, Progressive=3ex, Style*=-- ,
Style2*=$\bullet$ ,Style3*=$\circ$ ,Style4*=\tiny$\blacksquare$ )
% ...

\begin{easylist}
& Blah
& Blah
&& Blah
&&& Blah
&&&& Blah
&&&&& Blah
\end{easylist
}

– Blah
  \bullet Blah
   \circ Blah
    \blacksquare Blah
     – Blah

Spaces in Style parameters are important. The Style* parameter acts as a default value and easylist will use a medium dash for level 1, 5 and onward.

You can also define custom styles using LaTeX macros:

\newcommand\myitemize{\ListProperties(Hide=100, Hang=true, Progressive=3ex, Style*=$\star$ )}
\newcommand\myenumerate{\ListProperties(Space=2\baselineskip)
}

% ...
\begin{easylist} \myitemize
& Blah
\end{easylist
}

Important note: easylist has some drawbacks. First if you need to put an easylist inside an environment using the same control character as the one specified for easylist, you may get an error. To circumvent it, use the following commands provided by easylist:

\Activate
\begin{easylist}
& ...
\end{easylist
}
\Deactivate

Besides using easylist along with figures may cause some trouble to the layout and the indentation. LaTeX lists do not have this problem.

To use easylist with Beamer, each frame that uses easylist must be marked as fragile:

\begin{frame}[fragile]
    ...
    \begin{easylist}[itemize]
        ...
    \end{easylist}
    ...
\end{frame
}

Notes and references[edit]

  1. http://www.tex.ac.uk/cgi-bin/texfaq2html?label=noline
  2. [1]The enumerate package, David Carlisle 1999
  3. [2]The enumitem package, Javier Bezos 2011
  4. CTAN documentation for enumerate
  5. easylist documentation


Previous: Fonts Index Next: Special Characters