Latest news 2024-07-03: Ebook sale (1st – 31st July 2024): short story cybercrime fiction Unsocial Media free; short story cybercrime fiction Smile for the Camera free; short story noir crime fiction I’ve Heard the Mermaid Sing free; crime fiction novel The Private Enemy US$1.99; illustrated children’s story The Foolish Hedgehog US$0.99.

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


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.



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):


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:



\title{A Simple Document}




A brief document to illustrate how to use \LaTeX.


\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.


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


We will turn this tabular environment into a table later.

 & \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


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:



... 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