LaTeX Guide

LaTeX Table of Contents

One command: \tableofcontents. Compile twice. Customize depth with \setcounter{tocdepth}.

Minimal example

\documentclass{article}
\usepackage{hyperref}    % makes TOC clickable

\begin{document}
\title{Document Title}
\author{Author}
\maketitle

\tableofcontents          % TOC here
\newpage

\section{Introduction}
Content...

\section{Methods}
Content...

\subsection{Data}
Content...

\section{Results}
Content...

\end{document}

Compile twice: first pass writes .toc file, second reads it.

Control TOC depth

% Show only sections (skip subsections)
\setcounter{tocdepth}{1}
\tableofcontents

% Show down to subsubsections
\setcounter{tocdepth}{3}
\tableofcontents

% Skip individual section from TOC
\section*{Acknowledgments}    % unnumbered, not in TOC

% Force unnumbered into TOC
\section*{Acknowledgments}
\addcontentsline{toc}{section}{Acknowledgments}

Lists of figures and tables

\tableofcontents
\listoffigures
\listoftables

Customize with tocloft

\usepackage{tocloft}

% Bold section names in TOC
\renewcommand{\cftsecfont}{\bfseries}

% Add space before each section entry
\setlength{\cftbeforesecskip}{1em}

% Change "Contents" title
\renewcommand{\contentsname}{Table of Contents}

Common mistakes

  • Compiling once. TOC needs two passes. Three for first-time setup.
  • tocdepth values. 0=chapters, 1=sections, 2=subsections (default), 3=subsubsections.
  • Using \section* and expecting TOC. Starred sections skip TOC. Use \addcontentsline if you want them.
  • Forgetting hyperref. Without it, TOC entries aren't clickable in PDF.
Typst TOC: one function, no two-pass compile
#outline()                    // TOC
#outline(target: figure)      // list of figures
#outline(target: figure.where(kind: table))    // list of tables
#outline(depth: 2)            // limit depth

No .toc file, no two-pass compile dance. Try TypeTeX free.

Try TypeTeX free

Frequently Asked Questions

How do I add a table of contents in LaTeX?

Add \tableofcontents where you want the TOC to appear (typically after \maketitle, before the first section). LaTeX automatically lists all \section, \subsection, etc. with page numbers. You need to compile twice: first pass writes to .toc, second pass reads it.

Why does my TOC show old content?

TOCs need two passes. After adding/removing sections, run pdflatex twice. Most LaTeX editors (Overleaf, TeXShop) auto-detect and rerun, but a fresh single-pass compile shows stale TOC. Three passes is sometimes needed when adding a new TOC for the first time.

How do I control the depth of the TOC?

\setcounter{tocdepth}{2} limits the TOC to sections and subsections. Default is 2 (subsections). Set to 0 for chapters only, 1 for sections only, 3 for subsubsections, 4 for paragraphs. Place before \tableofcontents.

How do I add an entry to the TOC manually?

\addcontentsline{toc}{section}{Custom Entry} — adds 'Custom Entry' as a section-level TOC entry. Used for unnumbered sections (\section*) that you still want in the TOC. Or for the bibliography: \addcontentsline{toc}{section}{References}.

How do I prevent a section from appearing in the TOC?

Use the starred form: \section*{Title} skips numbering and the TOC. To keep numbering but skip TOC: \section{Title} \addtocontents{toc}{...}—custom but rare. Most authors use \section* for acknowledgments, abstract, etc.

How do I add a list of figures and tables?

\listoffigures and \listoftables — typically right after \tableofcontents. Both auto-populate from \caption commands inside figure/table environments. Same two-pass compile requirement.

How do I customize the TOC styling?

Use the tocloft package: \usepackage{tocloft}. Then \renewcommand{\cftsecfont}{\bfseries} for bold section entries, \setlength{\cftbeforesecskip}{1em} for spacing, and many more. titletoc and etoc are alternatives for full control.

Why does the TOC start on a new page?

By default, \tableofcontents calls \newpage internally. To suppress, redefine \contentsname or use the etoc package. To force a new page after the TOC: \tableofcontents \newpage.

How do I make the TOC clickable in PDF?

Load hyperref: \usepackage{hyperref}. Once loaded, all TOC entries become clickable hyperlinks to their sections. Add \hypersetup{linkcolor=blue} (or colorlinks=true in the package options) to color them.

More LaTeX guides