LaTeX Table of Contents: Depth, Links, tocloft, Beamer

November 11, 2026 · 10 min read

LaTeX Table of Contents: \tableofcontents, Depth, Links and Beamer

A LaTeX table of contents takes one command: put \tableofcontents where you want the list and compile twice. LaTeX builds every entry from your \section and \chapter headings. This guide covers depth control, unnumbered entries, clickable links, tocloft styling, Beamer outline slides and the fixes for a contents page that stays empty.

How Do I Make a Table of Contents in LaTeX?

Place \tableofcontents in the body of the document, usually right after \maketitle. You never type the entries yourself. Each sectioning command reports its number, title and page, and LaTeX assembles the list for you.

\documentclass{article}
\begin{document}
\title{Field Notes}
\author{A. Writer}
\maketitle
\tableofcontents

\section{Introduction}
\subsection{Scope}
\section{Methods}
\subsection{Sampling}
\section{Results}
\end{document}

After two compiles, the PDF shows the title block, a Contents heading, and then five entries: 1 Introduction, 1.1 Scope, 2 Methods, 2.1 Sampling and 3 Results. Page numbers sit on the right. In the article class, section lines are bold without dot leaders, while subsection lines get dots.

Why two compiles? During each run, LaTeX writes the headings to an auxiliary file named after your document with a .toc extension. The \tableofcontents command prints whatever that file held when the run started. On the very first compile there's nothing to read, so you get the Contents heading with no entries under it. The LaTeX2e reference on tables of contents describes the same store-then-retrieve cycle. Tools like latexmk work out how many runs a document needs and do them for you.

To rename the heading, redefine \contentsname in the preamble with \renewcommand{\contentsname}{Table of Contents}. One catch: babel resets that name for the chosen language when the document starts, so a plain redefinition silently loses. With babel loaded, wrap it as \addto\captionsenglish{\renewcommand{\contentsname}{Table of Contents}}, swapping in your language name.

Which Sections Appear: tocdepth, secnumdepth and Level Numbers

Every sectioning command has a level number. A heading appears in the contents only when its level is less than or equal to the tocdepth counter. The numbers come from the LaTeX2e sectioning reference, and they differ slightly between classes.

CommandLevelNotes
\part-1 in book and report, 0 in articleRarely used in short papers
\chapter0Exists only in book and report
\section1
\subsection2
\subsubsection3
\paragraph4
\subparagraph5

The default tocdepth is 3 in article, so subsubsections are listed. In report and book it's 2, which stops at subsections. Change it in the preamble:

\setcounter{tocdepth}{1}
\setcounter{secnumdepth}{2}

With these two lines in an article, the contents list sections only, while headings down to subsections still carry numbers. That's the difference people mix up: secnumdepth decides which headings get numbered, and tocdepth decides which ones get listed. Watch the class, too. Setting tocdepth to 0 in an article hides every section, but in a report it keeps the chapters.

You can also change the depth partway through. In an article, writing \addtocontents{toc}{\protect\setcounter{tocdepth}{0}} just before \appendix keeps the appendix sections out of the list while earlier sections stay in. In a report, the same line hides appendix sections but still lists appendix chapters, because chapters sit at level 0.

Is a title too long for the contents? Use the optional argument. Writing \section[Short title]{The full title printed in the text} sends the short form to the contents page and running heads.

Adding Unnumbered Sections With \addcontentsline

Starred commands such as \section* print a heading with no number, and they also skip the contents entirely. To list one anyway, add an \addcontentsline right after it:

\section*{Preface}
\addcontentsline{toc}{section}{Preface}

The contents now show Preface at section level, with no number and the page where the heading sits. The three arguments are the file (toc, lof or lot), the level to format the line as, and the text. Keep the line directly below the heading, because the entry takes the page number of wherever the command lands. In a book, the same pattern works with \chapter* and a chapter level entry.

Some sections have no heading command you control, such as an index printed by a package. The hyperref manual suggests this pattern, which sets a link target first so the entry jumps to the right page:

\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{\indexname}
\printindex

\phantomsection comes from hyperref, so drop it if you don't load that package. If you'd rather not add these lines by hand, the tocbibind package adds the bibliography, index and lists of figures and tables to the contents automatically.

List of Figures and List of Tables

\listoffigures and \listoftables work exactly like the contents command. They read from .lof and .lot files, so they also need a second compile. Only floats with a \caption appear, and the optional short caption keeps long captions from flooding the list.

\tableofcontents
\listoffigures

\section{Introduction}
\begin{figure}
  \centering
  \rule{4cm}{3cm}
  \caption[River map]{A hand-drawn map of the river,
    with the three sampling sites marked.}
\end{figure}

The list of figures shows a single line, 1 River map, with its page number. The full caption still prints under the figure. Rename the headings with \listfigurename and \listtablename, the same way as \contentsname. Building the tables themselves with tabular is a separate topic from listing them. Our guide to making a table in LaTeX covers that.

How to Make the Table of Contents Clickable in LaTeX

Load hyperref and every entry becomes a link to its heading. The PDF also gets a bookmarks panel built from the same headings. The hyperref manual says it should be the last package you load, because it redefines many internals that other packages also touch.

\usepackage{hyperref}
\hypersetup{
  colorlinks=true,
  linkcolor=blue,
  linktoc=all
}

With these options, the entry text is blue instead of boxed, and linktoc=all makes both the title and the page number clickable. The default is linktoc=section, which links the title only. Without colorlinks, hyperref draws a red frame around each link in most PDF viewers. If you want links that look like plain text, use \usepackage[hidelinks]{hyperref} instead.

Here's the limitation: load order matters, and errors from it are confusing. A package loaded after hyperref may undo its changes, and a few packages, such as cleveref, must load after it on purpose. When the contents stop linking after you add a package, check the order first.

Styling the Contents Page With tocloft

The tocloft package exposes the spacing, fonts and dot leaders of each entry type as commands you can redefine. This preamble adds dot leaders to section lines in an article, tightens the gap above them, and changes the title font:

\usepackage{tocloft}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
\setlength{\cftbeforesecskip}{4pt}
\renewcommand{\cfttoctitlefont}{\Large\sffamily\bfseries}

The commands follow one naming scheme, so \cftsubsecleader and \cftbeforesubsecskip handle subsections. Two compatibility notes from its manual: tocloft doesn't work with the KOMA-Script classes, and the memoir class blocks it and supplies its own equivalents. If you're on KOMA or memoir, use the class's built-in commands. The titletoc package is another route if you already use titlesec.

We prefer leaving the default style alone for papers and articles. Readers rarely notice the contents page unless it looks odd. Reach for tocloft when a university or publisher hands you a thesis template with rules about dots, spacing and fonts. Those templates often ask for roman numerals on the contents page too, which our LaTeX page numbering guide covers.

LaTeX Beamer Table of Contents and Outline Slides

In Beamer, \tableofcontents goes inside a frame like any other content. The Beamer user guide documents its options. The common setup pairs an overview slide with an outline that repeats at every new section:

\documentclass{beamer}
\AtBeginSection[]{
  \begin{frame}{Outline}
    \tableofcontents[currentsection]
  \end{frame}
}
\begin{document}
\begin{frame}{Outline}
  \tableofcontents[hideallsubsections]
\end{frame}

\section[Results]{Results on the Main Problem}
\subsection{Setup}
\begin{frame}{Setup}Text\end{frame}

\section{Next Steps}
\begin{frame}{Plan}Text\end{frame}
\end{document}

The first slide lists the two section titles only. Before each section, a new Outline slide appears with the current section at full strength and the others shaded. The empty brackets after \AtBeginSection mean starred sections get no outline slide.

One detail trips people up. In Beamer, the optional short title [Results] goes to the navigation bars, not the outline, so the outline still shows the full title. Other useful options are pausesections, which reveals the sections one at a time, and hideothersubsections. Beamer also needs at least two compiles before outlines fill in.

Why Is My LaTeX Table of Contents Empty or Out of Date?

Most broken contents pages come down to the auxiliary file. Work through these in order:

  • You compiled once. The first run only writes the .toc file. Compile again.
  • The preamble has \nofiles. LaTeX stops writing auxiliary files, and an old .toc keeps showing stale entries.
  • tocdepth is too low. A value of 0 in an article hides every section.
  • The headings are starred. \section* never makes an entry without \addcontentsline.
  • You renamed or moved a heading. The contents lag one run behind, so the old title or page shows until the next compile.
  • You deleted the auxiliary files. You're back to an empty list until two more runs.
  • Entries come out in the wrong order. An \addcontentsline placed just before an \include can do this. Move it into the included file.

With hyperref, a third run is sometimes needed. The log says so with a rerunfilecheck warning that the bookmarks file changed.

Generating a LaTeX TOC From Markdown

If you draft in Markdown, Pandoc's --toc flag writes \tableofcontents into standalone LaTeX output, and --toc-depth sets the depth (3 by default, per the Pandoc manual). The full command line lives in our Markdown to LaTeX with Pandoc guide.

Our Markdown to LaTeX converter turns Markdown into a .tex file in your browser. It has no contents option and doesn't compile a PDF. Add \tableofcontents yourself, after \maketitle if the file has one, and compile locally. Need a contents list for the Markdown file itself? That's a different job, covered in the Markdown table of contents guide, and the TOC generator builds one with anchors for six platform slug styles.

A LaTeX table of contents is one command plus a second compile. Everything after that is tuning: tocdepth for how deep it goes, \addcontentsline for unnumbered parts, hyperref for links, tocloft for house styles and currentsection for Beamer outlines. Our editor renders the math in your notes with KaTeX but not document commands like \section, so compile full documents with a TeX distribution. Our KaTeX vs LaTeX comparison lists what KaTeX can't render.