[Tex/LaTex] Remove dots in toc for a particular entry like appendix

appendicestable of contents

I am writing my thesis and use the book class under PhDthesisPSnPDF.

I would like to remove the dots in table of contents only for a particular entry like "Appendix". All the entries for chapter and section in the table of contents have dots and page numbers, I need to get rid of page number and the dots for the appendix in the TOC. Is there way to do?

Best Answer

A heading command like \section{A} writes a line into the .toc file that looks like this:

\contentsline {section}{\numberline {1.1}A}{2}

when this is read back in \contentsline{section} simply expands to \l@section and that is then the command that picks up the remaining arguments and produces the toc entry. Most often (but not always) this command is defined as a special instance of \@dottedcontentsline, e.g., in the book class you find:

\newcommand*\l@section{\@dottedtocline{1}{1.5em}{2.3em}}

So to get rid of the dots in some cases there are different approaches possible and the depend on how things are defined and which entries you have to change in reality.

Plan A

Assuming that your toc uses \@dottedtoclinethen to get rid of the dots we can redefine \@dotsep to have a very high number. Assuming further, that we only want to change the sections at the end of the toc and we do not need to have dots appearing later on again. Then the following in front of the appendix in the source document will do the trick:

\makeatletter
\addtocontents{toc}{\def\string\@dotsep{100}}
\makeatother

This will write \def\@dotsep{100} into the toc file and from that point on the dots are gone.

If you need them back at a later point issue

\makeatletter
\addtocontents{toc}{\def\string\@dotsep{4.5}}  % 4.5 might be a different value in your class
\makeatother

Plan B

Make the heading commands in the appendix area or whenever you want a different toc style not write \contentsline{section}but, say, \contentsline{appsection} and then define \l@appsection to format the toc entry according to the desired style.

For this one would need to look for the places in the heading commands that issue \addcontentsline and change that code.

Fairly elaborate but much more general.