How to Fix Overlapping Numbers and Titles in a LaTeX Table of Contents
At a glance
- 1. Find the affected level
Check whether the overlap occurs in chapters, sections, subsections, or more than one entry type.
- 2. Widen the number box
With tocloft, increase the numwidth for each affected level so its longest number fits.
- 3. Rebuild the document
Compile at least twice so LaTeX updates the table-of-contents file and its layout.
- 4. Check custom formatting
If the overlap remains, inspect class or package settings that redefine table-of-contents entries.
If a section number runs into its title in a LaTeX table of contents, the usual cause is that the number has outgrown the space reserved for it. The title is not necessarily too long: the table-of-contents layout assigns the number a fixed-width box, and the title begins immediately after that box.
For standard classes such as book and report, you can enlarge that box with the tocloft package. The example below adjusts the section and subsection entries; use the corresponding setting for whichever level is colliding.
Why the entries overlap
LaTeX writes table-of-contents entries to an auxiliary .toc file and formats them on a later run. Each entry has a number area followed by its title and, usually, a dotted leader to the page number. If the number area is narrower than the formatted number, the number and title can appear to touch or overlap.
This often shows up after a document gains deeper section numbering, longer chapter numbers, or a change in number formatting. For example, a subsection label such as 12.4.3 takes more room than 1.1.1. The relevant width is the space allowed for the number—not the width of the main text block.
Fix it with tocloft
Load tocloft and set the number width for each affected level. For example:
\documentclass{book}
\usepackage{tocloft}
% Reserve more room for the printed numbers in the contents.
\setlength{\cftchapnumwidth}{3em}
\setlength{\cftsecnumwidth}{3.5em}
\setlength{\cftsubsecnumwidth}{4.5em}
\begin{document}
\tableofcontents
\chapter{A chapter}
\section{A section}
\subsection{A subsection}
\end{document}
These lengths apply to the chapter, section, and subsection number areas in the table of contents. Increase only the ones for entries that need more room. The exact values depend on your font and the longest number you expect; 3.5em is a font-relative length equal to three and a half times the current font’s em (quad).
The example uses a book class, but the same tocloft lengths are commonly used with standard report and article classes for the levels they provide. An article has no chapters, so a chapter-width setting is not relevant there. If your section numbers can become much longer, increase the relevant width accordingly. Leave a small gap after the number so it does not appear cramped against the title.
After changing the settings, compile the document at least twice. The first run may update the .toc file; the next run reads the updated entries and typesets the contents. If you use latexmk, it normally runs LaTeX enough times to resolve this automatically.
Choose a width that fits the longest label
Estimate the width using the longest number that can appear at that level, including punctuation. If your section numbers may look like 10.12, for instance, make sure the section number area fits that label and still leaves a visible gap before the title. Check the printed PDF rather than relying only on the number of characters: glyph widths vary by font.
You can use the same approach for other levels supported by tocloft, such as \cftsubsubsecnumwidth for subsubsections. If chapter titles collide with chapter numbers, adjust \cftchapnumwidth; changing the section width will not fix a chapter entry. The spacing before the entry and the number area are separate settings, so widening a number box is usually preferable to moving the entire entry farther to the right.
Worked example: long subsection numbers
Suppose the contents contains a subsection numbered 10.12.3, and its title starts immediately after the final digit. First identify the entry as a subsection. Then increase \cftsubsecnumwidth, for example from the class or package default to 5em:
\setlength{\cftsubsecnumwidth}{5em}
Compile twice and check the longest subsection label in the resulting contents. If the number now has enough space but the title begins too far to the right, reduce the width slightly; if any number still crowds the title, increase it. Do not change \cftsecnumwidth for this case, because that setting controls section entries, not subsection entries.
If tocloft does not fix it
Some document classes and packages provide their own table-of-contents formatting. KOMA-Script classes, memoir, Beamer, or packages that redefine contents entries may use different controls. In those cases, consult the class or package documentation rather than assuming that tocloft lengths govern the layout. Avoid loading multiple packages that independently redefine the table of contents unless their compatibility is documented.
Also check whether the .toc file contains custom entries or manually written \addcontentsline commands. If ordinary entries look correct but one particular entry overlaps, the issue may be specific to that custom entry or to a redefinition of \numberline. A clean rebuild can help when auxiliary files contain stale formatting: remove generated files such as .aux and .toc, then compile again.
Common mistakes
- Changing the page margins: This changes the overall text block, not the width reserved between a TOC number and its title.
- Adjusting the wrong level: A subsection width does not affect chapter or section entries. Match the setting to the entry that overlaps.
- Changing indentation instead of number width: Indentation moves the whole entry; the number width controls where its title begins.
- Compiling only once: LaTeX may need another run to use the updated
.tocfile. - Assuming every class uses
tocloft: Custom classes can define their own contents layout and settings.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.