Control your Table of Contents

Something I’ve been struggling a lot with in the past is the suppression of, for instance, the appendix in the Table of Contents. Mostly, it is enough to show that the appendices start at a certain page and not to show the sections/chapters that are in the appendices. But also the other way around: showing a section in the Table of Contents that is defined with a * in the document (\section*{}).

Adding the Table of Contents

The table of contents is added with the command \tableofcontents. Call this command inside your document (so after the \begin{document}), at the place where you want your Table of Contents. This is usually the beginning of the document:

\begin{document}
\tableofcontents
 
\chapter{First chapter}
...

Removing entries

First, let’s discuss the situation where you want to hide certain entries. Let’s say that you have to chapters in your Appendix, and just want to show ‘Appendices’ in the Table of Contents. Note that you need the appendix package for adding appendices. This is what you need to add in your document:

\appendix
\addcontentsline{toc}{chapter}{Appendices}
\addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}
\chapter{First appendix}
You don't want this to appear.
\chapter{Second appendix}
You don't want this to appear.

The \addcontentsline{toc}{chapter}{Appendices} adds the line ‘Appendices’ to your Table of Contents, as you wanted it! But we need to do more, because we want to suppress the chapters. This is done with the third line: \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}. This tells LaTeX to suppress the entries whose depth is above -1. Depth? Yes, \part has depth -1, \chapter 0, \section 1, and so on. Compile your LaTeX document (maybe twice to get the Table of Content correct). and you’ll see that the chapters have disappeared from the Table of Content!

Adding entries

Let’s add entries to your Table of Contents now! Say that you have defined a \subsection*{} in your document, for whatever reason that may be. Normally, starred entries do not appear in your Table of Content. Here’s how to add them:

\begin{document}
\tableofcontents
\chapter{First chapter}
\section{First section}
\subsection*{Starred subsection}
\addcontentsline{toc}{subsection}{Starred subsection}
\end{document}

What is done now is exactly the same as the previous case, but in a different situation. LaTeX is told to add an entry with subsection depth and to name is ‘Starred subsection’.

31 Comments

  1. Kemal says:

    Hello .
    I have a question related to the list of figures.
    I have written my dissertation in latex.
    The page numbers of the fidures are not bold in list of the fidures.
    How can I change the page numbers of the figures to bold (only page numbers) ?
    Thanks

  2. Marie says:

    Hi!

    Great tips for the toc! however when I use this trick: \appendix \addcontentsline{toc}{chapter}{Appendices} \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}

    the List of Figures and List of Tables disappear! They only come back when I comment on the table of contents…

    Could you shed some light on this problem?
    Thanks!

  3. Others include aging process, underlying diseases, swimming in chlorinated water, harsh soaps, chemicals and harsh cosmetics.
    In addition, a lot of common substances may be utilized to
    fight dry skin. Pure genuine pearl powder does not totally dissolve in water or liquid, so be sure you stir as you drink.

  4. It’s awesome in support of me to have a web site,
    which is valuable in favor of my know-how. thanks admin

  5. Vinch says:

    I’ve experienced the solution you provide, with

    \addtocontents{toc}{\protect\setcounter{tocdepth}{0}}

    right before \appendix, and it works perfect for the toc.
    However if you’re using package hyperref, it messes with the pdf’s toc, setting it down to chapter level for the whole document (except for manual \bookmark s).

    I worked this out this way:
    \addtocontents{toc}{\setcounter{tocdepth}{0}}
    right before \appendix
    And then
    \addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
    right before \end{document}.

    PdfLatex and hyperref seem to like it, worked out for me !

  6. Johnd124 says:

    Greetings! Very useful advice within this article! It is the little changes that make the most important changes. Many thanks for sharing! dadfdedfggbg

  7. Kim says:

    I used the

    \appendix \addcontentsline{toc}{chapter}{Appendices} \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}

    But now my List of Figures and List of Tables contents are also gone… They are stil in the table of contents, but the figures and pages are not shown anymore.

    Does anybody know why?

  8. Ju says:

    Question: How can add \listoffigures and \listoftables in the appendix section having the Prefix “Appendix” before the headline “List of Figures”?

    \documentclass[11pt, a4paper, oneside]{book}

    \tableofcontents
    \chapter{Introduction}
    \chapter{And so on}

    \begin{appendices}

    %\chapter{List of Figures} % to get the correct title
    %\renewcommand\listfigurename{} % to delete the title
    %Problem with the previous two commands: I either get too much space between the headline and the first entry in the list of figures.

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

    \end{appendices}

    \end{document}

    Thanks a lot

  9. Chandra says:

    You really make it seem really easy together with
    your presentation however I in finding this topic to be
    actually something that I think I’d never understand. It seems too complicated and extremely large for me. I’m taking a look
    ahead to your next submit, I’ll attempt to get the hang of it!

  10. Alan says:

    Is there anyway to “hide” rows within a table when a condition is met, for example when the row total = 0?

  11. marie says:

    Hi, you have a very nice and generous blog with lots of usefull information. Thanks!

    I have a tricky question from France (must be tricky since I’ve been browsing the web for 3 days without finding an answer to it??).
    How can I remove the entry “Contents” from my table of contents? It appears automatically and I don’t find it useful to see it printed there (when we are looking at the table of contents we don’t need to know what page it is on, it is written in the page foot…).
    I’m using the command \tableofcontents as every one else. (I’ve tried adding an asterix at the end of the command but it doesn’t change a thing of course;-)
    Thanks if you can help in that matter,
    Marie

  12. André says:

    Nice blog! i have a question, i am using \tableofcontents and after that \listoffigures and \listoftables, but in the table of content doesnt show the title of the list of figures and list of tables. How can i do that? thanks in advance!

    • André says:

      Sorted out! For those who has the same issue, u have to add this to ur code:

      \tableofcontents
      \addcontentsline{toc}{chapter}{Contents}
      \listoffigures
      \addcontentsline{toc}{chapter}{List of Figures}
      \listoftables
      \addcontentsline{toc}{chapter}{List of Tables}

      Have fun!

  13. Hanne says:

    Tanks! That fixes the page numbers.

    It did mak my TOC have two lines at the bottom like this:

    A Appendix 1: List of species…………………….31

    Appendices…………………………………………31

    But the problem was fixed by using \section*{Appendix 1}, so I’m happy.

    Thanks again.

  14. Hanne says:

    Hi, great tip about appendices. Only one problem when I use your commands, the page number in the TOC is places right after “Appendices” like this: “Appendices34”. How can I get it aligned with the others?

    This is (parts of) my document:

    \documentclass[a4paper,11pt,twoside]{article}
    \usepackage{appendix}

    \begin{document}

    \tableofcontents

    \include{section}

    \appendix
    \addcontentsline{toc}{chapter}{Appendices}
    \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}

    \chapter{Appendix 1}

    \end{document}

    Thanks in advance!

    • Frits says:

      Hi Hanne,
      This is because you use the documentclass article, which doesn’t support \chapter. Try changing the \addcontentsline to this:

      \addcontentsline{toc}{section}{Appendices}

      And to be complete, you’ll probably want your Appendix to look like this:

      \section{Appendix 1}

      Instead of the \chapter command.

  15. Chris says:

    Hi,

    Thanks for the nice tutorial. However, your method for hiding an appendix chapter from the ToC does not work for me. It ends up erasing all the chapters (and lower) from the ToC.

    Any idea why this happens?

    Thanks

    • Frits says:

      Hi Chris,

      I have no idea right now, but if you want you can email me (part of) your LaTeX document, so I can have a look at it. Email me via the contact form. I know the form is not perfect, I’ll hope to add a feature to send attachments soon.

  16. td287 says:

    When I use this approach to suppress the individual listings of each appendix, it then deletes my list of figures, which follows my table of contents. Do you know how to address this?

    • Ced says:

      Hi,

      I had the same problem and find a way to correct it. At the end of my appendices, I’ve reset the depth of the toc to its original value (3 in my case).
      I don’t see why it works, but it works anyway :)

  17. David says:

    Thanks again, but I couldn’t get it to work, perhaps because of the way the template cls file was. However, I found a cheat;

    The thesis generates a .toc and and .lof file; I merely edited these, removing the last entry in both. I then made them read only and recompiled; it annoyed winedt, but it used the now protected ones and bingo, it worked. Messy, but achieves the goal :P

  18. David says:

    Thanks for that! Sadly it’s not working for me – though I suspect because the template Im using takes use of parts rather than section / chapters.. like this…

    ————————————-
    \tableofcontents
    \listoffigures
    \printnomenclature %% Print the nomenclature
    \addcontentsline{toc}{chapter}{Nomenclature}

    \mainmatter

    \part{Literature Review}
    \include{Introduction/introduction}
    \include{Chapter1/chapter1}
    \include{Chapter2/chapter2}
    \include{Chapter3/chapter3}
    \part{Research and investigation}
    \include{Chapter4/chapter4}
    \include{Chapter5/chapter5}
    \include{Chapter6/chapter6}
    \include{Chapter7/chapter7}
    \include{Chapter8/chapter8}
    \include{Chapter9/chapter9}
    \include{Conclusions/conclusions}

    \appendix
    \include{Appendix1/appendix1}
    \include{Appendix2/appendix2}
    \include{Appendix3/appendix3}
    \include{Appendix4/appendix4}
    \include{Appendix5/appendix5}
    \include{Appendix6/appendix6}

    Any ideas what else one could try ?!

    • Frits says:

      Okay I see, but is every appendix (1 to 6) in a different \part? If so, you should set the tocdepth to -2 instead of -1.

      -2 suppresses \part and lower than that (\chapter, \section, etc.) from the ToC.
      -1 keeps \part and suppresses \chapter and lower
      … and so on

      Note that you have to compile your documents twice before the changes in the ToC are made visible.

  19. David says:

    Hey, great blog. I have a related, but oddly strange question. I have 6 appendices in a document, like this;

    \appendix
    \include{Appendix1/appendix1}
    \include{Appendix2/appendix2}
    \include{Appendix3/appendix3}
    \include{Appendix4/appendix4}
    \include{Appendix5/appendix5}
    \include{Appendix6/appendix6}

    All of these are listed in the TOC. However, for my own purposes, I want to HIDE only appendix 6; so that anyone viewing the contents would only think there are 5 appendices and the last one is a surprise. Is this possible ? I also have a table of figures, and there is one figure in appendix 6 i would also not like to show up on TOC….

    Thanks in advance!

    • Frits says:

      Hi David, if you only want to hide your last appendix you can try the following:

      ...
      \include{Appendix5/appendix5}
      \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}
      \include{Appendix5/appendix6}
      ...

      The value -1 between the brackets depends on wether you use \chapter or \section (if you use the latter you can also set it to 0).

      I’m not sure how to this in you List of Figures (LoF), but I presume that it can be done in a similar fashion:

      \addtocontents{lof}{\protect\setcounter{lofdepth}{-1}}

  20. Srinivas says:

    thanks. I have a question:

    How to I add a text to the TOC? This text (a single word) is not present in any of the chapters going forward. Example:

    Table of Contents

    Acknowledgement ………………………………………………….ii

    Abstract …………………………………………………………………..V

    Chapter ( i want to add this “Chapter”) here..
    1 Introduction ………………………………………………………..1

    • Frits says:

      Hi Srinivas, that is also treated in the article (for the word ‘Appendices‘):
      \addcontentsline{toc}{chapter}{Your Text} adds the line ‘Your Text’ to the ToC. Depending on the documentclass you are using you might want to use:
      \addcontentsline{toc}{section}{Your Text}.

      If you don’t want the pagenumbering behind the added text, there’s another command:
      \addtocontents{toc}{Your Text \par}

      Have a go with it! If you can’t get it to work, please say so :-)

Leave a Reply




XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>