When working with large documents with tens (or hundreds) of pages, it’s useful to be able to scroll directly to the section you’re interested in by clicking the section in the table of contents. In LaTeX, this functionality can be added quickly and easily in just a few lines using the hyperref package (and the color package if you want the links to be colored).

This post extends on this post how to add a table of contents to a LaTeX document. If you don’t know how to do that, read that post first.

To make the links clickable, we need to add the packages and configuration to the preamble – the part before \begin{document}. A typical configuration may look something like this:

\usepackage{color}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true, % make the links colored
    linkcolor=blue, % color TOC links in blue
    urlcolor=red, % color URLs in red
    linktoc=all % 'all' will create links for everything in the TOC
}

The configuration is fairly self-descriptive. With this, we will have a table of contents with links, as well as clickable website URLs (always useful).

The full working example will produce this document:

\documentclass[12pt, a4paper]{article}

\usepackage{color}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    urlcolor=red,
    linktoc=all
}

\begin{document}

\tableofcontents
\newpage

\section{First Section}
\subsection{First part of the first section}
Source code for this can be found at \url{http://timmurphy.org/2014/03/11/latex-table-of-contents-with-clickable-links}
\subsection{Second part of the first section}
\ldots

\section{Second Section}
\subsection{First part of the second section}
\ldots
\end{document}

  1. Ric says:

    Nice website. Thanks for the effort

  2. You have an awesomely designed site! I’m definitely bookmarking it. And thanks for this article, I was able to get links in my \tableofcontents to \section’s.

    All best,
    Brandon Doyle