How to Create a LaTeX Table of Contents – 6 steps to create and custom ToC

How to Create a LaTeX Table of Contents – 6 steps to create and custom ToC

One of the standout features in LaTeX is the ability to generate a Latex table of contents easily. A Table of Contents is an essential inclusion in many documents, as it provides readers with an overview of the content. This helps them navigate to the information they are seeking quickly.

Creating a Table of Contents in LaTeX can seem tricky at first. However, it is easy to do once you understand the commands involved.



Creating a Table of Contents in LaTeX

Creating a simple Table of Contents is a straightforward process. Users simply need to enter the following command:

\tableofcontents

You should keep in mind that the document needs to be typeset twice to produce this list. The first iteration will collect each heading and caption, before writing them to the “.toc” meta file. The second iteration will print the list on the basis of the meta file content. 

The following example illustrates the commands for a document with a Table of Contents:

\documentclass{article}

\begin{document}

\tableofcontents

\newpage

\section{Section}

Example text 1

\subsection{Subsection}

Example text 2

\end{document}

The above commands should produce a table of contents that resembles the following:

Customizing the Table of Contents

LaTeX also offers many options for customizing your Table of Contents.

Step 1. Change the List Headings

It is possible to change the heading without loading a specific package. You can use the following command to do this:

\renewcommand\contentsname{}

\tableofcontents

So if you wanted to change the heading from Table of Contents to Summary, the command would resemble:

\renewcommand\contentsname{Summary}

\tableofcontents

Step 2. Add “Page” Above the Page Numbers

It is possible to add the word “Page” above the page numbers in the Table of Contents. You can do this with the following command:

\tableofcontents

\addtocontents{toc}{~\hfill\textbf{Page}\par}

\chapter{…}

Step 3. Change the Depth of Table of Contents Entries

Users can change the depth or the number of levels to be printed in the Table of Contents using the following command:

\setcounter{tocdepth}{1}

\tableofcontents

In this example “1” refers to a section. “2” would create a subsection and so forth.

Step 4. Use Different Styles For Table of Contents Page Numbers

Users can change the style for the page numbers in the Table of Contents using the command:

\pagenumbering{}

LaTeX supports different styles such as Roman, Alph, and arabic. If you wanted to change the page numbering style to Roman and then switch it back to Arabic before the beginning of the first chapter, the code would resemble the following:

\pagenumbering{roman}

\tableofcontents

\listoffigures

\listoftables

\clearpage

\pagenumbering{arabic}

\chapter{…}

Step 5. Add Lists of Table of Contents

It is possible to add entries to your Table of Contents using a single command. Many users do this to ensure the page number of each section is correct. This command is:

\addcontentsline{}{}{}

The above brackets refer to file the line (toc), the entry type (chapter or figure), and the entry text.

Adding the three lists to the Table of Contents resembles the following:

\tableofcontents

\addcontentsline{toc}{chapter}{Contents}

\listoffigures

\addcontentsline{toc}{chapter}{List of Figures}

\listoftables

\addcontentsline{toc}{chapter}{List of Tables}

This should produce a Table of Content that resembles the following:


Related content for LaTex:


Step 6. Add a List of Figures in Table of Contents

Users can add a list of figures using the command \listoffigures. After compiling the code, the output should resemble the following:

\documentclass{article}

\usepackage[utf8]{inputenc}

\title{List of Figures}

\author{User }

\date{}

\begin{document}

\begin{figure}

     \caption{Your first figure}

     \caption{Your second figure}

\end{figure}

\begin{appendix}

\listoffigures

\end{appendix}

\end{document}

Final Thoughts

As you can see, adding a Table of Contents to your LaTeX document is a relatively easy process. Customizing this Table of Contents does require the right commands. However, this process becomes much faster once you understand the process.

Frequently Asked Questions

Q1: How do you create a Table of Contents in LaTeX?

You can add a Table of Contents using the following command: \tableofcontents

Q2: How do you add an Appendix to a Table of Contents in LaTeX?

You can add an appendix to the Table of Contents with the following code:
\appendix
\addtocontents{toc}{\cftpagenumbersoff{chapter}} 
\chapter*{APPENDICES}
\addtocontents{toc}{\protect\contentsline {chapter}{APPENDICES}{}{}}
\addtocontents{toc}{\cftpagenumberson{chapter}} 
\makeatletter
\addtocontents{toc}{\let\protect\[email protected]\protect\[email protected]}
\makeatother
\include{appendix_materials}
\include{appendix_project}

Q3: How to Create a LaTeX Table of Contents With Links?

You can turn the lines in a Table of Contents into clickable links that direct to corresponding pages by adding \usepackage{hyperref} in the preamble of the document line. 

Q4: How to Change the LaTeX Table of Contents Style?

You can change the font of entries using a command in the tocloft package. It should resemble the following:
\usepackage{tocloft}
\renewcommand{\cftchapfont}{\scshape}
\renewcommand{\cftsecfont}{\bfseries}
\renewcommand{\cftfigfont}{Figure }
\renewcommand{\cfttabfont}{Table }

Q5: What to Do if the LaTeX Table of Contents Aren’t Working?

If your Table of Contents aren’t working, ensure you are typesetting the  document twice as mentioned in the “Creating a Table of Contents in LaTeX” section above.

Q6: What Is a LaTeX Table of Contents Beamer? 

Beamer is a LaTeX class for creating presentations. Users can add a table of contents to the beginning of their presentation using the following code:
\begin{frame}
\frametitle{Table of Contents}
\tableofcontents
\end{frame}

Q7 What Is LaTeX Table of Contents Depth? 

Depth describes sections and their corresponding subsections in the Table of Contents. You can set the dept for each section and subsection using the following command:
\setcounter{tocdepth}{1}
\tableofcontents
The “1” above corresponds to a section, while “2” would correspond to its sub-section.

Q8: How to Change LaTeX Table of Contents Unnumbered Sections?

You can add unnumbered sections to the LaTeX Table of Contents using the following code: 
\documentclass{article}
\setcounter{secnumdepth}{0}
\begin{document}
\tableofcontents
\section{ADSF}
\section{Foo}
\end{document}


Photo of author
Author
Joannah W.
Joannah has been a science publisher with close to 20 years of experience. She wants to help students and researchers stay ahead of the trends and developments in the science community by making science more accessible to everyone.

Leave a Comment