Let
X

Add a Table of Contents, List of Figures & Tables in LaTeX

By Shihab Shahriar Antor · Updated June 2026 · 5 min read

In LaTeX, \tableofcontents auto-generates a table of contents from your \section and \chapter headings; \listoffigures and \listoftables do the same for captioned floats. They read the .aux file, so you need two compiles: the first records headings, the second prints the lists. LetX runs both passes automatically.

Generate a table of contents

You never type a TOC by hand. \tableofcontents reads your headings and builds it, with correct page numbers and links (if hyperref is loaded). Add the lists right after:

contents.tex
\documentclass{report}
\usepackage{graphicx}
\usepackage{hyperref}

\begin{document}
\tableofcontents
\listoffigures
\listoftables

\chapter{Introduction}
\section{Background}
Text...

\begin{figure}[h]
  \centering
  \includegraphics[width=.5\textwidth]{plot}
  \caption{A captioned figure appears in the LoF.}
\end{figure}
\end{document}

Only captioned floats appear in the lists. A figure or table without \caption is skipped. If a list looks empty or stale, you’re seeing the “needs two compiles” effect.

Why two compiles are needed

On the first compile, LaTeX writes every heading and caption to a .aux file but doesn’t yet know the page numbers when it reaches \tableofcontents at the top. The second compile reads that .aux and prints the finished lists. LetX runs the extra pass automatically, so you always see an up-to-date TOC.

Control what appears

GoalCommand
Limit TOC depth\setcounter{tocdepth}{2}
Add an unnumbered section to TOC\addcontentsline
Short caption text in lists\caption[short]{long}
Start a fresh page\clearpage

Compile with automatic TOC passes — free.

Open LetX Free

Frequently asked questions

How do I add a table of contents in LaTeX?

Put \tableofcontents where you want it (usually after the title). LaTeX builds it from your \section and \chapter headings. You must compile twice so the page numbers resolve — LetX runs both passes automatically.

Why is my table of contents empty or out of date?

The TOC reads the .aux file from the previous compile. After adding or changing headings you need a second compile to update it. On LetX the extra pass runs automatically.

How do I add a list of figures and tables?

Use \listoffigures and \listoftables, and give every figure and table a \caption. Only captioned floats appear in the lists.

How do I limit the depth of the table of contents?

Use \setcounter{tocdepth}{2} to include only down to subsections, or a higher number for more levels. Use \addcontentsline to add unnumbered headings manually.

Related

Written by Shihab Shahriar Antor — AI Engineer & Founder of Shahriar Labs. Builder of LetX (collaborative LaTeX) and QuantumSketch (AI STEM video).