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*{}).

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!

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

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

2. Alan says:

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

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

• Frits says:

You can add \renewcommand\contentsname{} to your preamble. However, this doesn’t work when you’re using the babe package.

4. 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
\listoffigures
\listoftables

Have fun!

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

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

\chapter{Appendix 1}

\end{document}

• 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}

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

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

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

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

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

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

• 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}} 

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

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