Tx · LaTeX & TikZ

How to Fix a LaTeX Table of Contents That Is Not Working

Published By the 9to5Science editorial team

At a glance

  1. 1. Load hyperref

    Add \usepackage{hyperref} in the preamble, usually after other packages.

  2. 2. Check the document

    Use normal sectioning commands and place \tableofcontents where the contents should appear.

  3. 3. Compile again

    Run LaTeX at least twice so the contents entries and their links are updated.

  4. 4. Check special entries

    For starred sections added manually, create a hyperlink anchor before writing the contents entry.

A table of contents can seem broken in several different ways: it may be missing entries, show outdated page numbers, or appear in the PDF without clickable links. These problems have different causes, but the standard fix is simple: check the document structure, load hyperref, and compile again after the contents file has been updated.

A minimal working example

This complete example creates a table of contents with clickable section entries:

\documentclass{article}
\usepackage[colorlinks=true, linkcolor=blue]{hyperref}

\begin{document}

\tableofcontents

\section{First section}
This is the first section.

\section{Second section}
This is the second section.

\end{document}

Compile the file at least twice. On the first run, LaTeX writes section information to an auxiliary file. On the next run, it reads that information to typeset the table of contents and create the links. If the document changes, another run may be needed to refresh page numbers and entries. Tools such as latexmk normally rerun LaTeX as needed.

The hyperref package makes the entries produced by standard commands such as \section into PDF links. It also typically creates PDF outline bookmarks, which are separate from the printed table of contents.

Diagnose the symptom

The table of contents is empty or missing new sections. Check that \tableofcontents is inside the document, after \begin{document}, and that you compiled again after adding or changing section commands. Also check whether the section level is included: for example, \subsection entries may be omitted if the document’s tocdepth setting excludes them.

The entries are visible but not clickable. Confirm that hyperref is loaded and that you are opening the generated PDF, not a DVI file or a printout. If you use a custom class or a package that changes the table of contents, test the minimal example above to see whether the interaction is the cause.

The links work but look like ordinary text. This is not necessarily a failure. Options such as hidelinks keep links clickable while removing colored text and borders. To make links visibly colored, use an option such as colorlinks=true, linkcolor=blue.

A link jumps to the wrong place. This often happens with manually added contents entries for unnumbered sections. Add a hyperlink anchor immediately before the contents entry, as shown below.

Add an unnumbered section to the contents

Starred section commands, such as \section*{Acknowledgments}, do not add an entry to the table of contents automatically. Use \addcontentsline to add one. With hyperref, place \phantomsection first so the entry links to the intended location:

\section*{Acknowledgments}
\phantomsection
\addcontentsline{toc}{section}{Acknowledgments}

Here, toc names the table-of-contents file and section specifies the entry level. Put these lines where the unnumbered heading appears, then compile again. For a chapter-level entry in a book, use chapter instead of section.

Package order and common mistakes

Load hyperref late in the preamble—usually after other packages—because it modifies cross-referencing and linking commands. Some packages have documented exceptions or need special ordering, so follow their instructions if they conflict. Do not put hyperref after \begin{document}; packages belong in the preamble.

Common mistakes include:

  • Compiling only once: the table of contents is built from information saved during a previous run.
  • Expecting starred sections to appear automatically: commands such as \section* need a manual \addcontentsline entry if you want them listed.
  • Confusing bookmarks with the table of contents: the PDF sidebar outline and the printed contents page are related, but separate features.
  • Treating black links as broken: link appearance depends on package options and the PDF viewer; black text can still be clickable.
  • Adding \addcontentsline without an anchor: for an unnumbered heading, \phantomsection helps the link target the heading rather than a previous section.

If the minimal example works but your full document does not, temporarily disable packages or custom commands that redefine section headings or the table of contents. Restore them one at a time and recompile to identify the conflict.

References

  1. The hyperref package documentation
  2. The LaTeX2e unofficial reference manual

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.