Nested lists

Nest one list inside another and LaTeX switches the label at the head of each line according to the level. Yet an enumerate placed inside an itemize entry — visually the second level — starts at “1.” and not at “(a)”. What LaTeX counts is not depth on the page but how many lists of the same kind enclose you. Write nested lists without knowing that one fact and the output will keep surprising you. This page covers how the label is chosen, why a wall named Too deeply nested stands at the fourth level, a second ceiling that all list environments share, and the line width you lose, irreversibly, with every level you add.

The label follows the count of same-type lists, not the depth on the page

LaTeX counts depth with two separate counters. In latex.ltx, itemize advances \@itemdepth and enumerate advances \@enumdepth; each then builds a command name — \labelitem or \labelenum plus a Roman numeral — from its own value and calls it. The two never consult each other, so an enumerate inside an itemize is at \@enumdepth 1: \labelenumi applies and the numbering starts at “1.”. The claim that the label is determined by nesting depth regardless of type is often repeated, and it is wrong. One compilation settles it.

latex
\begin{enumerate}
  \item Make the dough
  \begin{itemize}
    \item Flour
    \item Water
    \begin{enumerate}
      \item Add half
      \item Add the rest
    \end{enumerate}
  \end{itemize}
  \item Let it rest
\end{enumerate}

Here is what those three levels actually produce. The outer enumerate gives “1.” and “2.”; the itemize inside it gets the first-level bullet •, not the second-level dash –; and the innermost enumerate gets the second-level (a), not the third-level Roman i. From the itemize’s point of view this is the first itemize around; from the inner enumerate’s point of view there is exactly one enumerate outside it. Alternate the types as you go down and each type works through its own label sequence independently.

DepthEnvironmentDepth within that typeLabel produced
1itemize1• (\labelitemi)
2enumerate11. (\labelenumi)
3itemize2– (\labelitemii)
4enumerate2(a) (\labelenumii)
5itemize3* (\labelitemiii)
6enumerate3i. (\labelenumiii)

The wall at the fourth level: ! LaTeX Error: Too deeply nested.

Nest five lists of the same type and compilation halts with ! LaTeX Error: Too deeply nested. The message does not tell you the depth — it is just those three words, so counting which \begin is the fifth is left to you; the line number reported is the \begin{itemize} that opened it. The reason is not a typographic prohibition but a plain shortage of names: the test in latex.ltx is only \ifnum \@itemdepth >\thr@@, “greater than three”. Label commands are defined for four levels, there is no name to hand the fifth, and so it stops. Which also means merely loading enumitem does not remove the wall: open a fifth level without adding any configuration and the same error appears in exactly the same way.

latex
% raising the ceiling really does take all four lines
\usepackage{enumitem}
\setlistdepth{9}
\renewlist{itemize}{itemize}{9}
\setlist[itemize]{label=$\cdot$}
\setlist[itemize,1]{label=$\bullet$}

Actually removing the wall takes more than enumitem’s \setlistdepth on its own. \setlistdepth{9} only lifts the overall list ceiling; itemize itself still stops at four. You have to rebuild the environment for nine levels with \renewlist{itemize}{itemize}{9} and then supply labels for the new levels with \setlist[itemize]{label=…} before a fifth level will typeset at all. Open a fifth level without giving it a label and the error simply changes to ! Package enumitem Error: Undefined label. If what you really want is a deep numbered hierarchy, a package such as easylist, designed from the start for arbitrary depth, is the more honest tool. But pause before reaching for any of them: almost no reader can follow five levels of nesting. Nesting that deep is usually a sign that the structure wants to become section headings instead.

A second ceiling: the six-level budget every list environment shares

Above the four-per-type limit sits a second ceiling of six levels, shared by every list. Both itemize and enumerate are built on the same underlying list environment, and list carries its own test, \ifnum \@listdepth >5. Alternating itemize and enumerate therefore gets you to six levels, and the seventh fails with Too deeply nested all the same. The awkward part is that lists are not the only things spending from this budget. Look through article.cls and you find quote, quotation, verse, description and even thebibliography all built on \list. Put two nested quotation blocks inside a deep bulleted list and they alone can exhaust what is left. Because the culprit does not look like a list, this is the hardest version of the failure to track down.

Indentation accumulates: a quarter of the measure is gone by level four

The real cost of nesting shows up not in the labels but in the width of the line. Every time a list environment opens it adds its \leftmargin to the running total on the left, so indentation stacks up level by level. In a 10pt article set in one column, \leftmargini is 25.0pt, \leftmarginii 22.0pt, \leftmarginiii 18.7pt and \leftmarginiv 17.0pt. By the fourth level the left margins sum to 82.7pt — roughly a quarter of the 345pt text width — leaving 262.3pt of line to write on. The values shrink slightly at each level precisely to slow that accumulation down, and even so, four levels take that much.

LengthValueRunning totalLine width left (textwidth 345pt)
\leftmargini25.0pt (2.5em)25.0pt320.0pt
\leftmarginii22.0pt (2.2em)47.0pt298.0pt
\leftmarginiii18.7pt (1.87em)65.7pt279.3pt
\leftmarginiv17.0pt (1.7em)82.7pt262.3pt

Put in figures, the reason deep nesting reads badly becomes concrete. A measure of 262pt is close to a single column of a two-column layout; pour long sentences into it and the line breaker has less room to work, so inter-word spacing opens up unnaturally and Overfull \hbox warnings multiply. In two-column layouts \leftmargini is reduced to 2em to begin with, and the narrower the measure, the less slack nesting has. When the left margin needs tightening, setting leftmargin= per level with enumitem is the practical route. More often than not, though, revisiting the structure is faster than any of that: entries below the third level can usually be folded back into the parent entry as prose.

Where to stop nesting

LaTeX permits four levels, but that is not the same as saying four levels can be read. Deep nesting communicates hierarchy, and the reader has to reconstruct that hierarchy from the shape of the marker and the position of the left edge, and nothing else. The third-level asterisk and the fourth-level centred dot look alike, and only 17pt of indentation separates them. By the fourth level, in other words, the reader has almost no cue left to work with. What follows is a checklist for reviewing nesting after it is written.

  • Check whether two levels would do. Anything past the third can usually be folded into the parent entry as prose.
  • If the depth is genuinely needed, use section headings instead of a list. \subsection and \subsubsection bring a table of contents and cross-references with them.
  • Always look at the output when you mix types. The label depends on how many lists of the same type enclose it, so you may not get the marker you expected.
  • Keep quote and verse out of deep nesting. They spend from the same six-level budget and cause errors whose source is hard to see.
  • When Too deeply nested appears, recount the depth. The message never names the level, so walk back through the \begin lines from the one reported.