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
\listoftablesCustomize 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\addcontentslineif you want them. - Forgetting hyperref. Without it, TOC entries aren't clickable in PDF.
#outline() // TOC
#outline(target: figure) // list of figures
#outline(target: figure.where(kind: table)) // list of tables
#outline(depth: 2) // limit depthNo .toc file, no two-pass compile dance. Try TypeTeX free.
Try TypeTeX freeFrequently Asked Questions
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.
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.
\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.
\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}.
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.
\listoffigures and \listoftables — typically right after \tableofcontents. Both auto-populate from \caption commands inside figure/table environments. Same two-pass compile requirement.
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.
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.
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.