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

This post may contain affiliate links that allow us to earn a commission at no expense to you. Learn more

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:

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\l@chapter\protect\l@section}
\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}

Further Reading

LaTex Tutorial

  1. 27 Pros and Cons of Using LaTex for Scientific Writing
  2. 6 Easy steps to create your first Latex document examples
  3. How to add circuit diagrams in Latex
  4. How to change Latex font and font size
  5. How to create footnotes in LaTeX and how to refer to them, using the builtin commands
  6. How to create Glossaries in LaTeX
  7. How to create plots in Latex – codes and examples
  8. How to create symbols in LaTeX – commands for Latex greek alphabet
  9. How to create tables in LaTeX – rows, columns, pages and landscape tables
  10. How to drawing graphs in Latex – vector graphics with tikz
  11. How to highlight source code in LaTeX
  12. How to insert an image in LaTeX – Managing Latex figure and picture
  13. How to Itemize and Number List – Adding Latex Bullet Points
  14. How to make hyperlink in latex – Clickable links
  15. How to reference in Latex – 5 steps to bibliography with Bibtex
  16. How to use Latex Packages with examples
  17. How to use LaTeX paragraphs and sections
  18. LaTeX Installation Guide – Easy to follow steps to install LaTex
  19. Learn to typeset and align Latex equations and math

Photo of author
Author
SJ Tsai
Chief Editor. Writer wrangler. Research guru. Three years at scijournal. Hails from a family with five PhDs. When not shaping content, creates art. Peek at the collection on Etsy. For thoughts and updates, hit up Twitter.

2 thoughts on “How to Create a LaTeX Table of Contents – 6 steps to create and custom ToC”

  1. Hi

    I am using Latex for 20 years via vim editor Miktex in window environment
    I would like to start a business of scientific publication in Sudan
    How can u help me
    yours
    Prof
    Babiker

    Reply

Leave a Comment