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 \@dottedtocline
then 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.
If you want all \subsection
s to be removed from the ToC, then all you need in your document preamble is
\setcounter{tocdepth}{1}
which would set the maximum depth of entries in the ToC to 1 (or \section
).
If you only want selected \subsections
to be inserted/not in the ToC, then you should use a different technique. The following defines \stoptocentries
and \starttocentries
. The former disables inserting content in the ToC by disabling \addcontentsline
. The latter restores the functionality.
\documentclass{article}
\let\oldaddcontentsline\addcontentsline
\newcommand{\stoptocentries}{\renewcommand{\addcontentsline}[3]{}}
\newcommand{\starttocentries}{\let\addcontentsline\oldaddcontentsline}
\begin{document}
\tableofcontents
\section{A section}
\stoptocentries% Stop adding content to the ToC
\subsection{A subsection}
\starttocentries% Resume adding content to the ToC
\subsection{Another subsection}
\end{document}
Of course, usage of \stoptocentries
also pertains to other sectional units that use \addcontentsline
.
Best Answer
Method - 1: Add
in your preamble.
Method - 2: This can be achieved by
tocloft
package also. Here one has to useto remove the page numbers and
to remove the dots.
A MWE will be: