Written and maintained by CASRAI Editorial Board
Published
On this page
A LaTeX contents page provides an automated navigation index for academic papers, theses, dissertations, and technical reports by compiling document headings and page numbers into a structured overview. Generated primarily through the tableofcontents command, LaTeX creates this listing dynamically by scanning sectioning commands during document compilation and writing their titles and starting page numbers to an auxiliary file with the extension .toc. On subsequent compilation passes, LaTeX reads the auxiliary file back into the document to render an aligned table of contents with accurate page references and optional dot leaders.
Ask CASRAI · free to tryQuestion about this guide? Ask CASRAI answers with linked sources. 2 free questions a day, no account.
What it is used for in research
In academic writing and scientific publishing, a table of contents is essential for manuscripts exceeding five to ten pages, including master’s theses, doctoral dissertations, research proposals, technical working papers, and multi-part project deliverables. Standard peer-reviewed journal articles typically omit a contents page due to compact page budgets and linear sectioning. However, research theses and comprehensive monographs rely heavily on the contents page to guide examiners, committee members, and peer researchers directly to specific methodologies, experimental proofs, and data analyses.
Automating the contents page in LaTeX offers significant advantages over manual typesetting in word processors:
- Typographical Consistency: Section titles in the table of contents automatically match the exact wording, capitalization, and math notation used in the document body.
- Synchronized Pagination: When edits shift paragraphs across page boundaries, recompiling automatically updates the page references without requiring manual proofreading.
- Hierarchical Granularity: Authors can control whether the contents page displays broad structural divisions (chapters and sections) or fine-grained headings (subsections and subsubsections) using a single integer counter.
- Electronic Navigation: Integrated with hyperlinking packages, the contents page converts into an interactive, clickable PDF outline and bookmark tree for electronic distribution.
Install or access
The core command tableofcontents and auxiliary file generation mechanisms are built directly into standard LaTeX document classes (such as article, report, and book). No third-party packages are required for basic functionality. To author, compile, and format LaTeX documents containing a table of contents, researchers can access official TeX distributions or web-based editing platforms:
- TeX Live: The comprehensive, cross-platform TeX system maintained by the TeX Users Group (TUG). Available for Linux, macOS, and Windows via the official TUG distribution portal (
tug.org/texlive). - MacTeX: An easy-to-install redistribution of TeX Live optimized for macOS environments, distributed officially by TUG (
tug.org/mactex). - MiKTeX: An open-source, independently maintained TeX distribution for Windows, macOS, and Linux that includes automatic package installation on demand (
miktex.org). - Overleaf: A widely used cloud platform for collaborative writing in Overleaf that provides an in-browser TeX engine with pre-installed distributions, eliminating manual software installation.
- Desktop Editors: Dedicated LaTeX editors such as the open-source TeXstudio IDE streamline the multi-pass compilation required to synchronize table of contents files.
Step-by-step task: generating and formatting the contents page
Follow these numbered steps to generate, structure, and customize a table of contents in a LaTeX research document.
-
Place the tableofcontents command in the document body:
Position
tableofcontentswhere the contents listing should appear. In standard papers and articles, this is placed immediately aftermaketitleor the abstract. In book and thesis classes, place it within the front matter, followed by a page break.documentclass{article} title{Investigation of Multiphase Flow Dynamics} author{Research Group in Fluid Physics} date{today} begin{document} maketitle tableofcontents newpage section{Introduction} Document text begins here... end{document} -
Set the structural depth with tocdepth:
By default, standard LaTeX document classes set the
tocdepthcounter to2, which includes sections and subsections, but omits subsubsections and lower divisions. To modify how deeply headings penetrate the contents page, setsetcounter{tocdepth}{level}in your preamble:setcounter{tocdepth}{0}: Chapters only (available inbookandreport).setcounter{tocdepth}{1}: Chapters and sections.setcounter{tocdepth}{2}: Sections and subsections (default).setcounter{tocdepth}{3}: Sections, subsections, and subsubsections. For guidance on controlling headings at this level, consult the guide on LaTeX subsubsection and tocdepth settings.
-
Include unnumbered sections using addcontentsline:
Headings created with an asterisk (such as
section*{Acknowledgements}) are excluded from the table of contents by default. To register an unnumbered section in the contents page, use theaddcontentslinecommand. When producing interactive PDFs with thehyperrefpackage, always invokecleardoublepage(orclearpage) andphantomsectionimmediately beforeaddcontentslineto prevent hyperref from anchoring the link to the preceding chapter or page:clearpage phantomsection addcontentsline{toc}{section}{Acknowledgements} section*{Acknowledgements} We acknowledge funding from the National Research Infrastructure Fund.This approach is similarly recommended when adding formal reference sections, such as the thebibliography environment in LaTeX or formatting an appendix in LaTeX.
-
Rename the heading title:
By default, the table of contents title is printed as “Contents” in the
articleclass, and “Table of Contents” in thereportandbookclasses. To change this heading (for example, to “Table of Contents” in an article, or “Summary of Contents”), redefinecontentsnamein the preamble:renewcommand{contentsname}{Table of Contents}If your document uses internationalization packages such as
babelorpolyglossia, redefine the string within the language caption hook to prevent the localization package from overwriting your custom title:usepackage[english]{babel} addtocaptionsenglish{ renewcommand{contentsname}{Table of Contents} } -
Compile the document twice:
LaTeX requires two complete compilation passes to build the contents page. During pass 1, LaTeX writes heading titles, section levels, and starting pages into the auxiliary
.tocfile. During pass 2, it reads this file and formats the contents page. If compiling from the command line, run your TeX engine twice:pdflatex manuscript.tex pdflatex manuscript.tex
Output and how to read it
When LaTeX completes compilation, the table of contents renders as an aligned, indented list. Understanding how LaTeX generates this layout from its intermediate files clarifies how typographical elements align.
During compilation, LaTeX writes entries to an auxiliary file with the same root name as your document (e.g., manuscript.toc). A representative .toc file contains macro entries structured as follows:
contentsline {section}{numberline {1}Introduction}{3}{section.1}
contentsline {subsection}{numberline {1.1}Background and Prior Work}{4}{subsection.1.1}
contentsline {section}{numberline {2}Experimental Methodology}{7}{section.2}
Each contentsline statement contains four arguments processed by the LaTeX engine:
- Sectioning Unit: The first argument (e.g.,
section,subsection) defines the structural level and determines the horizontal indentation and font weight. - Heading Text and Number Box: The second argument contains
numberline{1}, which sets the section number inside a fixed-width box, followed by the verbatim heading title. - Page Reference: The third argument (e.g.,
3) indicates the exact physical page number on which the section heading appears. Coordinated page styling (such as Roman numerals in front matter and Arabic numerals in main chapters) is covered in our reference on LaTeX page numbering configuration. - Hyperlink Anchor: If the
hyperrefpackage is loaded, a fourth argument records the internal PDF destination anchor (e.g.,section.1) used to generate interactive links.
The standard LaTeX kernel formats these lines using the internal macro @dottedtocline. The default layout reserves a right margin box of width @tocrmarg (set to 2.55em) and allocates a page number box of width @pnumwidth (set to 1.55em). In documents with three-digit page counts (such as comprehensive research theses spanning over 100 pages), page numbers may push past the default margin box unless adjusted.
Troubleshooting
The following table outlines common problems encountered when generating a LaTeX table of contents, their technical causes, and official solutions.
| Observed Issue | Root Technical Cause | Verified Solution |
|---|---|---|
| Contents page is completely blank except for the title header. | The document has only been compiled once, meaning the intermediate .toc file has not yet been processed by the layout engine. |
Execute a second compilation pass (pdflatex or xelatex) to read the newly populated .toc file into the document. |
Fatal error: ! Undefined control sequence referencing a line in document.toc. |
A fragile command or newly deleted macro was saved inside a section heading in the .toc file from a previous compilation run. |
Delete the auxiliary file (document.toc) manually and recompile twice. Use protect before fragile commands in section headings or supply a robust short title: section[Short Title]{Full Title with protectmacro}. |
| Clicking an unnumbered section in the contents page jumps to the wrong page. | The hyperref package linked addcontentsline to the preceding section anchor because no new destination anchor was established. |
Insert clearpagephantomsection immediately before calling addcontentsline{toc}{section}{...}. |
| Section numbers overlap or collide with section titles (e.g., section 12.14.3). | The section number exceeds the standard box width allocated by @dottedtocline in the document class. |
Load the tocloft package and widen the numeral box using cftsetindents{subsection}{1.5em}{3.0em}. |
Top-level sections in the article class lack dot leaders leading to page numbers. |
Standard LaTeX article design specifies bold headings without dot leaders for level-1 sections. | Load usepackage{tocloft} and enable dot leaders via renewcommand{cftsecleader}{cftdotfill{cftdotsep}}. |
Free alternatives
While standard LaTeX provides a robust built-in table of contents mechanism, several free, open-source packages and tools offer alternative approaches to customizing contents pages in academic workflows.
| Tool / Package | Implementation Method | Key Strengths | Operational Limitations |
|---|---|---|---|
Standard LaTeX Kernel (tableofcontents) |
Built-in macro utilizing native .toc auxiliary file serialization. |
Zero external dependencies; completely portable across all TeX engines and distributions. | Deep typographical adjustments require modifying low-level internal macros (such as @dottedtocline). |
tocloft Package |
CTAN macro package providing high-level commands (e.g., cftsetindents, newlistof). |
Declarative control over fonts, indents, dot leaders, and creation of custom lists of schemes or algorithms. | May cause package conflicts if used alongside classes with built-in TOC engines like KOMA-Script or memoir. |
titletoc Package |
Companion package to titlesec focused on localized TOC styling. |
Supports partial and per-chapter tables of contents (startcontents, printcontents) for multi-part monographs. |
Different syntax conventions than standard LaTeX; higher learning curve for basic global margin adjustments. |
KOMA-Script Classes (scrreprt, scrbook) |
Class-level structural options (such as DeclareTOCStyleEntry). |
Modern typographic defaults designed specifically for European book and thesis standards without extra packages. | Requires authoring documents within KOMA-Script classes rather than standard report or book. |
Pandoc Markdown (--toc) |
Command-line document converter generating LaTeX output from plain Markdown. | Allows writing in lightweight Markdown while automatically injecting tableofcontents during PDF export. |
Advanced visual customization requires supplying custom LaTeX preamble templates. |
FAQ
How do I place the table of contents on its own page?
To isolate the table of contents on its own page in an article class, add a clearpage or newpage command immediately before and after the tableofcontents command. In report and book classes, LaTeX automatically formats the table of contents on a separate page.
How do I make table of contents entries clickable in a PDF?
To turn contents entries and page numbers into clickable hyperlinks, load the hyperref package in your document preamble: usepackage{hyperref}. You can customize link aesthetics to eliminate colored boxes using hypersetup{colorlinks=true, linkcolor=blue}.
How do I add the bibliography and index to the table of contents?
The cleanest way to include the bibliography and index without manual addcontentsline commands is to load the tocbibbind package in your preamble: usepackage[nottoc]{tocbibbind}. The nottoc option ensures the table of contents does not redundantly list itself.
Why are my subsections not showing up in the table of contents?
If subsections or subsubsections do not appear, your document preamble may have set the tocdepth counter too low, or you may be using the subsection*{} unnumbered syntax. Ensure that headings use standard numbered commands and set setcounter{tocdepth}{2} (or 3) in your preamble.
What should I do if LaTeX crashes with a .toc error?
When LaTeX encounters syntax errors referencing a line in filename.toc, an invalid command was cached during a previous compilation run. Delete the .toc file from your working directory and recompile twice to rebuild a clean auxiliary file from scratch.
Sources
- The LaTeX Project / Jim Hefferon and Karl Berry. LaTeX2e: An unofficial reference manual (June 2026 edition). Section 25.1: “Table of contents, list of figures, list of tables”. https://latexref.xyz/Table-of-contents-etc_002e.html. Accessed November 8, 2026.
- Overleaf Documentation Team. Table of contents in LaTeX. Overleaf Official Knowledge Base. https://www.overleaf.com/learn/latex/Table_of_contents. Accessed November 8, 2026.
- Wilson, Peter, and Will Robertson. The tocloft package: Control table of contents, figures, etc. Comprehensive TeX Archive Network (CTAN), Version 3.0d (October 30, 2026). https://ctan.org/pkg/tocloft. Accessed November 8, 2026.
- Wikibooks Contributors. LaTeX/Document Structure: Table of contents. Wikibooks, Open Books for an Open World. https://en.wikibooks.org/wiki/LaTeX/Document_Structure. Accessed November 8, 2026.







