Table of contents in LaTeX

LaTeX generates a table of contents automatically with \tableofcontents — no manual formatting needed.

Quick answer

latex
\documentclass{article}
\begin{document}

\tableofcontents
\newpage

\section{Introduction}
\subsection{Background}

\end{document}

How it works

On the first compile, LaTeX writes section data to a .toc file. The second compile reads it to render the TOC. Always compile twice (or use latexmk which handles this automatically).

Controlling depth

By default, the TOC includes up to subsubsection level. Reduce depth to keep it concise.

latex
% Show only sections and subsections:
\setcounter{tocdepth}{2}

% Show sections only:
\setcounter{tocdepth}{1}

% Depth values:
% 1 = \section
% 2 = \subsection
% 3 = \subsubsection

List of figures / tables

latex
\tableofcontents
\listoffigures
\listoftables

Clickable TOC with hyperref

Load hyperref to make every TOC entry a clickable link in the PDF.

latex
\usepackage{hyperref}
% No other changes needed — \tableofcontents is automatically linked.

Custom TOC title

latex
% Rename "Contents" to something else:
\renewcommand{\contentsname}{Table of Contents}

% For book/report class (chapters use \chaptername):
\renewcommand{\contentsname}{Contents}

Adding an entry manually

latex
% Add an unnumbered section to the TOC:
\section*{Acknowledgements}
\addcontentsline{toc}{section}{Acknowledgements}

Related topics