Skip to main content
Add \tableofcontents where the table of contents should appear. LaTeX collects numbered chapters, sections, and subsections automatically, but you normally need to compile the document twice before every title and page number is current.
Quick answer: place \tableofcontents after \begin{document} and before the first chapter or section. Use hyperref when the entries should be clickable in the PDF.

How a LaTeX Table of Contents Works

During the first compilation, LaTeX writes section titles and page numbers to an auxiliary .toc file. During the next compilation, it reads that file and prints the finished list. Compile again whenever headings or pagination have changed.

Create a Basic Table of Contents

This complete example creates a linked TOC. The rendered pages show the TOC followed by the chapter content it references.
Compile at least twice so LaTeX can resolve TOC entries and page numbers. A third run can be necessary when a changed TOC alters pagination again.

Control TOC and Heading Depth

tocdepth controls which heading levels appear in the table of contents. secnumdepth separately controls which heading levels receive numbers in the document. Set these counters in the preamble when the rule should apply to the whole document. Changing them later affects the headings that follow.

Add an Unnumbered Heading to the TOC

Starred headings such as \chapter* and \section* are omitted from the TOC by default. Add the visible title explicitly with \addcontentsline. The middle argument must match the heading level: use chapter for a \chapter* entry and section for a \section* entry. Keep the displayed heading and TOC text identical unless a shorter navigation label is intentional. With hyperref, place \phantomsection before \addcontentsline when the manual entry needs a link anchor at the unnumbered heading.

Make TOC Entries Clickable

Load hyperref, preferably near the end of the preamble, to turn TOC entries and cross-references into PDF links. Options such as colorlinks=true change their appearance; they do not change which headings are collected. See Hyperlinks in LaTeX for link colors, hidden borders, URLs, and cross-references.

Common Table of Contents Problems

TOC Practices for Long Documents

  • Keep headings short enough to scan in both the page and the TOC.
  • Do not include every paragraph-level heading; a very deep TOC hides the document’s structure.
  • Use the same heading hierarchy throughout the project, including files loaded with \input or \include.
  • Treat manual \addcontentsline entries as exceptions for front matter such as acknowledgments or an unnumbered introduction.

Try a Table of Contents in LaTeX Cloud Studio

Compile the complete TOC example

Run the document twice and inspect how headings, page numbers, and PDF links are generated.

Structure a multi-file project

Split chapters into separate files while keeping one automatically generated table of contents.