LaTeX listings

StartSearchLaTeX for Beginners F.A.Q.LaTeXfont sizearrowsminipageitalicsboldtext colormatrixfontslistingstables

1 Listings & Enumerations

A short overview about listings & enumerations in LATEX.

1.1 description

The description environment is a listing variant in LATEX that can be used for a glossary, among other things. Example 1
Input:
\begin{description}
\item[A key point]
There must be something here to see the effect.
\item[Another key point] and text behind it
\end{description}
Output:
A key point There must be something here to see the effect.
Another key point and text behind it
Example 2 How not to do it
Input:
\begin{description}
\item[A key point] \\
A line break is not enough to bring the text
\item[Another key point] \\  down.
\end{description}
Output:
A key point A line break is not enough to bring the text
Another key point down.
Example 3 almost correct
Input:
\begin{description}
\item A key point \\
If the key point is not in the option 
\item Another key point\\ 
the key point is not bold
but the line break works.
\end{description}

Output:
A key point
     If the key point is not in the option
Another key point
     the key point is not bold but the line break works.
Example 4 How it works
Input:
\begin{description}
\item[A key point]\hfill \\
There must be something here to see the effect.
\item[Another key point]\hfill \\ and text behind it
\end{description}

Output:
A key point
There must be something here to see the effect.
Another key point
and text behind it

1.2   itemize

The itemize environment in LATEX provides an unnumbered listing.
Input:
\begin{itemize}
\item first key point
\item second key point
\end{itemize}

Output: The itemize environment can be nested up to four levels deep within itself.
Input:
\begin{itemize}
\item first level
\begin{itemize}
\item second level
\begin{itemize}
\item third level
\begin{itemize}
\item fourth level
\end{itemize}
\end{itemize}
\end{itemize}
\end{itemize}

Output:
levelsymbol / label Example
1. level bullet
2. level dash -
3. level asterisk *
4. level period ·
Input:
\begin{itemize}
\item first level
\begin{itemize}
\item second level
\begin{itemize}
\item third level
\begin{itemize}
\item fourth level
\end{itemize}
\item back to the third level 
\item another entry
\end{itemize}
\item here second level
\end{itemize}
\item and here first level
\end{itemize}

Output:

1.2.1   change label output

The output of the labels can be changed. At the beginning an example for using the option of the item command. \item[Option] Here a label can be set as an option. Example 1 Mixing characters Input:
\begin{itemize}
\item[a)] A key point
\item[*)] Another key point
\item[?)] key point three
\end{itemize}

Output: Example 2 uniform characters Input:
\begin{itemize}
\item[a] A key point
\item[b] Another key point
\item[c] key point three
\end{itemize}

Output: Example 3 no / without characters Input:
\begin{itemize}
\item[] A key point
\item[] Another key point
\item[] key point three
\end{itemize}

Output: Instead of using the option, the label fields could be changed.
level label field
1. level \labelitemi
2. level \labelitemii
3. level \labelitemiii
4. level \labelitemiv
Suppose you want to mark all layers with :
\renewcommand{\labelitemi}{$\bullet$}
\renewcommand{\labelitemii}{$\bullet$}
\renewcommand{\labelitemiii}{$\bullet$}
\renewcommand{\labelitemiv}{$\bullet$}
Then the example changes to: Input:
\begin{itemize}
\item first level as usual with $\bullet$
\begin{itemize}
\item now also second level has a $\bullet$
\begin{itemize}
\item as third level 
\begin{itemize}
\item and also fourth level has a $\bullet$
\end{itemize}
\end{itemize}
\end{itemize}
\end{itemize}

Output:

1.3   enumerate

The enumerate environment in LATEX provides a numbered listing.
Input:
\begin{enumerate}
\item first 
\item second 
\end{enumerate}

Output:
  1. first
  2. second
The enumerate environment (like the itemize environment) can be nested up to four levels deep within itself.
Note: If five or more levels are used, you will get this error message

! LaTeX Error: Too deeply nested.


By default, the numbering is on the first level with arabic numerals, on the second level with (small Latin letter), on the third level with small roman numerals and on the fourth level with large latin letters.
level symbol / label example
1. level arabic numerals. 1.
2. level (small latin letter) (b)
3. level small roman numerals. iii.
4. level large latin letters. D.

Note: At level 1, 3 and 4 period . and at level 2 parentheses (  ) are part of the numbering.
Input:
\begin{enumerate}
\item first level
\begin{enumerate}
\item second level
\begin{enumerate}
\item third level
\begin{enumerate}
\item fourth level
\end{enumerate}
\end{enumerate}
\end{enumerate}
\end{enumerate}

Output:
  1. first level
      (a) second level
        i. third level
          A. fourth level
Input:
\begin{enumerate}
\item first level
\begin{enumerate}
\item second level
\begin{enumerate}
\item third level
\begin{enumerate}
\item fourth level
\end{enumerate}
\item back to the third level
\item another entry
\end{enumerate}
\item here second level
\end{enumerate}
\item and here first level
\end{enumerate}

Output:
  1. first level
      (a) second level
      1. third level
        1. fourth level
      2. back to the third level
      3. another entry
      (b) here second level
  2. and here first level

1.3.1  change label output

The output of the labels and label fields could be changed.
level counter counter value label field
1. level enumi \theenumi \labelenumi
2. level enumii \theenumii \labelenumii
3. level enumiii \theenumiii \labelenumiii
4. level enumiv \theenumiv \labelenumiv

Suppose you want to remove periods and parentheses, you have to renewcommand the label fields in this way:
\renewcommand{\labelenumi}{\theenumi}
\renewcommand{\labelenumii}{\theenumii}
\renewcommand{\labelenumiii}{\theenumiii}
\renewcommand{\labelenumiv}{\theenumiv}
Accordingly, the output also changes to: Input:
\begin{enumerate}
\item first level
\begin{enumerate}
\item second level
\begin{enumerate}
\item third level
\begin{enumerate}
\item fourth level
\end{enumerate}
\end{enumerate}
\end{enumerate}
\end{enumerate}

Output:
    1 first level
      a second level
        i third level
          A fourth level
If you want to change the numbers, it works in a similar way. To do this, the display symbol (label field) of the enumeration is changed. Example 1 abc enumeration
Input:
\renewcommand{\labelenumi}{\alph{enumi}}
\begin{enumerate}
\item one
\item two
\item three
\end{enumerate}

Output:
    a one
    b two
    c three
Example 2 abc enumeration with parentheses
Input:
\renewcommand{\labelenumi}{\alph{enumi})}
\begin{enumerate}
\item one
\item two
\item three
\end{enumerate}

Output:
    a) one
    b) two
    c) three
Example 3 roman numerals enumeration
Input:
\renewcommand{\labelenumi}{\roman{enumi}}
\begin{enumerate}
\item one
\item two
\item three
\end{enumerate}

Output:
    i one
    ii two
    iii three
Example 4 roman numerals with period
Input:
\renewcommand{\labelenumi}{\roman{enumi}.}
\begin{enumerate}
\item one
\item two
\item three
\end{enumerate}

Output:
    i. one
    ii. two
    iii. three
Example 5 roman numerals with parentheses
Input:
\renewcommand{\labelenumi}{\roman{enumi})}
\begin{enumerate}
\item one
\item two
\item three
\end{enumerate}

Output:
    i) one
    ii) two
    iii) three
The outputs of the other levels can also be changed in the same way. In the following example, all four levels have different variants.
\renewcommand{\labelenumi}{\Roman{enumi}}
\renewcommand{\labelenumii}{\roman{enumii}}
\renewcommand{\labelenumiii}{\Roman{enumiii}.}
\renewcommand{\labelenumiv}{(\roman{enumiv})}

Input:
\begin{enumerate}
\item first level
\begin{enumerate}
\item second level
\begin{enumerate}
\item third level
\begin{enumerate}
\item fourth level
\end{enumerate}
\end{enumerate}
\end{enumerate}
\end{enumerate}

Output:
    I first level
      i second level
        I. third level
          (i) fourth level
Note: With the use of the paralist package or others, changing is much more easier.

1.4  typical error messages

These are the error messages for the itemize environment, but in principle the error messages are also usable for the enumerate environment.
 
error message: ! LaTeX Error: Too deeply nested.
cause: The nesting is too deep, i.e. five or more levels have been defined.
solution: Use fewer levels, maximum 4.

 
error message: ! LaTeX Error: Something's wrong--perhaps a missing \item.
cause: The environment was used without the \item command.
solution: Insert the \item command.
 
error message: ! LaTeX Error: \begin{document} ended by \end{itemize}.
cause: Too much \end{itemize} has been used.
solution: Remove the unnecessary \end{itemize}.

 
error message: ! LaTeX Error: \begin{itemize} on input line 100 ended by \end{document}.
cause: The \end{itemize} is missing.
solution: Insert the \end{itemize}.

 
error message: ! LaTeX Error: Lonely \item--perhaps a missing list environment.
cause: The beginning of the environment \begin{itemize} is missing or the whole environment was forgotten and only the \item command was used.
solution: Either remove the \item or start the environment \begin{itemize} or insert the whole missing environment

 
error message: ! Missing \endcsname inserted.
cause: \begin{itemize} was replaced by \begin{\itemize} and/or \end{itemize} was replaced by \end{\itemize}.
solution: Change \begin{\itemize} to \begin{itemize} and/or \end{\itemize} to \end{itemize}.

 
error message: ! LaTeX Error: Command \end{itemize} invalid in math mode.
cause: Within the itemize environment the math environment was started but not finished.
solution: Quit the math environment correctly.

Contact   Privacy Policy   disclosures

accept decline

This website uses cookies and pixel tags to ensure you get the best experience on our website. By using this website, you consent to the use of cookies.learn more about cookies see also our privacy policy