About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Latest news 2019-11-04: The giveaway of two signed copies of “Quack, quack, quack. Give my hat back!” has closed and the winning entrants have been selected. Thank you to everyone who took part.


5.4 Creating a Table of Contents

Once you have all your sectioning commands, such as \chapter and \section, you can create a table of contents with the command

\tableofcontents

This command should go where you want your table of contents to appear (usually after \maketitle).[The format of the Table of Contents, etc] The KOMA-Script classes provide two options that govern the format of the table of contents: toc=graduated and toc=flat. The first is the default and indents the different sectioning levels. The second doesn't use any indentation.

Example:

\documentclass[12pt,toc=flat]{scrreprt}

You may recall from the previous section that the sectioning commands all had an optional argument <short title>. If your chapter or section title is particularly long[My section title is too wide for the page header], you can use <short title> to specify a shorter title that should go in the table of contents.5.1 The longer title (given by the other argument <title>) will still appear in the section heading in the main part of the document.

LaTeX processes all source code sequentially, so when it first encounters the \tableofcontents command, it doesn't yet know anything about the chapters, sections etc. So the first time the document is LaTeXed the necessary information is written to the table of contents (.toc) file (see §2.4. Auxiliary Files). The subsequent pass reads the information in from the .toc file, and generates the table of contents. You will therefore need to LaTeX your document twice to make sure that the table of contents is up-to-date[Numbers too large in table of contents, etc].

Adding Extra Information

The starred versions of the sectional commands (such as \chapter*) don't get added to the table of contents. It may be that you want to add it, in which case you need to use

\addcontentsline{<toc>}{<section unit>}{<text>}

after the heading. The first argument <toc> is the file extension without the dot. As mentioned above, the table of contents file has the extension .toc, so the first argument should be toc (later, we'll be adding a list of figures and a list of tables, and those have file extensions .lof and .lot, respectively). The second argument <section unit> is the name of the section unit. This is just the name of the relevant sectioning command without the backslash. The final argument <text> is the entry text. For example (using scrreprt class):

\chapter*{Acknowledgments}
\addcontentsline{toc}{chapter}{Acknowledgements}

Exercise 11: Creating a Table of Contents

Try modifying your document so that it has a table of contents. Modifications from the previous exercise are illustrated like this:


\documentclass[12pt]{scrreprt}

\usepackage{datetime}

\title{A Simple Document}
\author{Me}

\begin{document}

\maketitle

\tableofcontents

\begin{abstract}
A brief document to illustrate how to use \LaTeX.
\end{abstract}

\chapter{Introduction}

\section{The First Section}

This is a simple \LaTeX\␣document.  Here is the first paragraph.

\section{The Next Section}

Here is the second paragraph\footnote{with a footnote}.
As you can see it's a rather short paragraph, but not
as short as the previous one. This document was
created on: \today\␣at \currenttime.

\chapter{Another Chapter}

Here's another very interesting chapter.
We're going to put a picture here later.

\chapter*{Acknowledgements}

I would like to acknowledge all those
very helpful people who have assisted
me in my work.

\appendix
\chapter{Tables}

We will turn this tabular environment into a table later.

\begin{tabular}{lrr}
 & \multicolumn{2}{c}{\bfseries Expenditure}\\
 & \multicolumn{1}{c}{Year1} & \multicolumn{1}{c}{Year2}\\
\bfseries Travel & 100,000 & 110,000\\
\bfseries Equipment & 50,000 & 60,000
\end{tabular}


\end{document}

If your table of contents doesn't come out right, try LaTeXing it again. (Again, you can download this file.)

You might want to try experimenting with the toc=flat class options to see what difference it makes:

\documentclass[12pt,toc=flat]{scrreprt}



Footnotes

... contents.5.1
and in the page header, depending on the page style.

This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-00-5).

© 2012 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs