LaTeX/List Structures

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

LaTeX

Getting Started
  1. Introduction
  2. Installation
  3. Installing Extra Packages
  4. Basics
  5. How to get help

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 types:

  • itemize for a bullet list
  • enumerate for an enumerated list and
  • description for a descriptive list.

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.


Try out the examples below, to see what the lists look like in a real document.

\documentclass{article}
\usepackage{blindtext}
\begin{document}
\begin{itemize}
\item \blindtext
\item \blindtext
\end{itemize}
\begin{enumerate}
\item \blindtext
\item \blindtext
\end{enumerate}
\begin{description}
\item [Ant] \blindtext
\item [Elephant] \blindtext
\end{description}
\end{document}
Sample output of lists in LaTeX. Itemize, enumerate and description.


LaTeX will happily allow you to insert a list environment into an existing one (up to a depth of four, more levels are available using packages). 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

Some special lists[edit]

Sometimes you feel the need to better align the different list items. If you are using a KOMA-script class (or package scrextend), the labeling environment is handy. It takes a mandatory argument that contains the longest of your labels.

\documentclass[twocolumn]{article}
\usepackage{blindtext}
\usepackage{scrextend}
\addtokomafont{labelinglabel}{\sffamily}
\begin{document}
\blindtext
\begin{labeling}{alligator}
\item [ant] really busy all the time
\item [chimp] likes bananas
\item [alligator] very dangerous animal, sharp teeth, long
muscular tail and a bit of text that is longer than one
line and shows the alignment of text quite nicely
\end{labeling}
\end{document}

WikibookListsLabeling.png


If you are on tight space limitations and only have short item descriptions, you may want to have the list inline. Please note that the example also shows how to change the font.

\documentclass[twocolumn]{article}
\usepackage{blindtext}
\usepackage[inline]{enumitem}
\usepackage{xcolor}
\begin{document}
\blindtext Coco likes fruit. Her favorites are:
\begin{enumerate*}[label={\alph*)},font={\color{red!50!black}\bfseries}]
\item bananas
\item apples
\item oranges and
\item lemons.
\end{enumerate*}
\blindtext
\end{document}

WikibooksListsInline.png

Need some details on Colors?


If you want a horizontal list, package tasks can be handy. In combination with a package like exsheets, you can prepare exam papers for students.

\documentclass{article}
\usepackage{blindtext}
\usepackage{tasks}
\begin{document}
Which one of the entries does not fit with the others?
\begin{tasks}(4)
\task mercury
\task iron
\task lead
\task zinc
\end{tasks}
\end{document}

WikibooksListsTask.png


Customizing lists[edit]

Especially when dealing with lists containing of just a few words per item, the standard lists take up too much space and you want to customize the appearance. Package enumitem helps you by providing a simple interface.

You can change the appearance of lists globally in the preamble, or just for single lists using the optional argument of the environment. Have a look at the following example where the list on the right is more compact using noitemsep.

\documentclass[twocolumn]{article}
\usepackage{blindtext}
\usepackage{enumitem}
\begin{document}
\blindtext
\begin{itemize}
\item more work
\item more responsibility
\item more satisfaction
\end{itemize}
\blindtext
\newpage
\blindtext
\begin{itemize}[noitemsep]
\item more work
\item more responsibility
\item more satisfaction
\end{itemize}
\blindtext
\end{document}

WikibookListsCompact.png

An example for alignment and the width of the label.

\documentclass[twocolumn]{article}
\usepackage{blindtext}
\usepackage{enumitem}
\begin{document}
\blindtext Coco likes fruit. Her favourites are:
\begin{description}[align=left]
\item [Kate] some detail
\item [Christina]some detail
\item [Laura]some detail
\end{description}
\begin{description}[align=right]
\item [Kate] some detail
\item [Christina]some detail
\item [Laura]some detail
\end{description}
\begin{description}[align=right,labelwidth=3cm]
\item [Kate] some detail
\item [Christina]some detail
\item [Laura]some detail
\end{description}
\blindtext
\end{document}

WikibookListsCustom.png

The documentation of package enumitem goes into more detail with respect to what can be changed and how. You can even define your own lists. Environments like labeling and tasks can be changed differently, details can be found in the package documentation respectively.


Easylist package[edit]

The easylist package 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 style 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 Hide = n 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}



Previous: Fonts Index Next: Special Characters