Table of Contents
How to automatically generate a Table of Contents, List of Figures, and List of Tables in LaTeX.
LaTeX automatically tracks all the chapters, sections, and subsections you create in your document. Because of this, generating a perfectly formatted, page-numbered Table of Contents requires exactly one line of code.
Generating the Table of Contents
Place the \tableofcontents command exactly where you want the TOC to appear (usually right after the \maketitle command or the abstract).
\documentclass{report}
\begin{document}
\title{My Thesis}
\author{John Doe}
\maketitle
% This generates the TOC
\tableofcontents
\chapter{Introduction}
This is the first chapter.
\section{Background}
This is a section.
\end{document}
```latex
LaTeX will automatically scan your document for `\chapter`, `\section`, `\subsection`, and `\subsubsection` commands, extract their titles, find their page numbers, and build the TOC.
<CalloutBox type="info" title="Multiple Compilations Required">
When working offline, you must compile your document **twice** to generate a TOC. The first compile gathers the section titles and page numbers into an `.aux` file. The second compile reads that `.aux` file and prints the actual TOC.
*(Note: The LetX cloud editor handles this double-compilation automatically).*
</CalloutBox>
## Excluding Sections from the TOC
If you want to create a section heading but do **not** want it to appear in the Table of Contents (and do not want it numbered), append an asterisk `*` to the command.
```latex
\section{Acknowledgments}
I would like to thank my cat for sleeping on my keyboard.
```latex
This creates a heading that looks identical to a normal section, but it is unnumbered and completely ignored by the `\tableofcontents` command.
## List of Figures and Tables
If your document has many floating images or tables, academic standards often require a directory for them.
LaTeX tracks every `figure` and `table` environment that contains a `\caption{}`. You can generate these lists instantly by adding these commands immediately after your TOC:
```latex
\tableofcontents
\listoffigures
\listoftables
```latex