How to remove the page number from the table of contents page?
[Tex/LaTex] Removing page number from ToC
header-footerpage-numberingtable of contents
Related Solutions
In the line after begin document, do the follows:
\begin{document}
\pagenumbering{gobble}
Do the title and author before this.
Then, on the actual first page, do:
\newpage
\pagenumbering{arabic}
The following should work for most document classes, although without the actual document class it is difficult to test.
You can selectively turn on the use of page numbers in the ToC using the following macros: \gobbletocpage
and \restoretocpage
. The former redefines \addtocontents
, replacing \thepage
with \relax
(effectively doing nothing), while the latter restores this back to \thepage
.
\documentclass{book}
\newcommand{\gobbletocpage}{%
\renewcommand{\addcontentsline}[3]{%
\addtocontents{##1}{\protect\contentsline{##2}{##3}{\relax}}}
}%
\newcommand{\restoretocpage}{%
\renewcommand{\addcontentsline}[3]{%
\addtocontents{##1}{\protect\contentsline{##2}{##3}{\thepage}}}
}%
\begin{document}
\tableofcontents
\chapter{A chapter}
\section{A section}
\section{A section}
\gobbletocpage
\section{A section}
\chapter{Another chapter}
\restoretocpage
\section{A section}
\section{A section}
\section{A section}
\end{document}
By means of example, the above ToC is void of page numbers after a call to \gobbletocpage
(Section 1.3 and Chapter 2), and this is restored with \restoretocpage
.
Since you have access to the .cls
, replace your definition of \l@chapter
(and some surrounding code) with the following (lines 182-219):
% Change style of printing chapters in ToC to match chapter headings.
\setcounter{secnumdepth}{3}% Always number up to \subsubsection
\setcounter{tocdepth}{2}% Include up to \subsection in ToC
\newcommand{\thechappagenum}{}% Empty page number for chapter
\newif\ifchappagenum\chappagenumtrue
\renewcommand*\l@chapter[2]{%
\renewcommand{\thechappagenum}{\ifchappagenum#2\fi}% Include chapter page num based on \chappagenum boolean
\typeout{\thechappagenum}
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip .1cm \@plus \p@ %{the v-distance between the headings in the contents}
\setlength\@tempdima{1.5em}% %{the distance between the number of the chapter and its title}
\begingroup
\parindent\z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode
\advance \leftskip \@tempdima
\hskip -\leftskip
\etchapterheadstyle{#1}\nobreak
% : The following 3 lines add dots to the chapter TOC listings
\leaders\hbox{$\m@th
\mkern \@dotsep mu\hbox{.}\mkern \@dotsep
mu$}\hfill
\hfil \nobreak\hb@xt@\@pnumwidth{\hss \thechappagenum}\par
\penalty\@highpenalty
\endgroup
\fi}
%---------------------------------------------------
% The lines below responsible on the mechanism of removing pages numbers of selecting headers in ToC.
% We need to add the command \gobbletocpage in the preamble before the \include{chapter} to delete their page numbers in ToC. And,
% we need to add the command \restoretocpage to restore chapter page numbering in ToC
%---------------------------------------------------
\newcommand{\gobbletocpage}{%
\addtocontents{toc}{\protect\chappagenumfalse}}%
\newcommand{\restoretocpage}{%
\addtocontents{toc}{\protect\chappagenumtrue}}%
%---------------------------------------------------
The above defines a new boolean "condition" \ifchappagenum
that is set to false
(\chappagenumfalse
) by \gobbletocpage
and true
(\chappagenumtrue
) by \restoretocpage
. All of this is written to the .toc
file, since this is processed without any knowledge/before the rest of your document.
Use \gobbletocpage
before the chapter(s) that you want no page numbers for in the ToC, and \restoretocpage
before you want to restore the chapter page numbers. This condition can be modified and used to reformat chapter ToC entries as needed (not just page numbers). Here's your easythesis.cls
with the above modifications used in a MWE:
\documentclass{easythesis}
\begin{document}
\tableofcontents
\chapter{A chapter}
\section{A section}
\section{A section}
\section{A section}
\gobbletocpage
\chapter{Another chapter}
\section{A section}
\section{A section}
\section{A section}
\end{document}
Best Answer
See this FAQ answer. In the simplest case you just use
\thispagestyle{empty}
after\tableofcontents
. However there are several complications, so see the linked answer.One problem not discussed in the FAQ is if the table of contents is longer than 1 page. For this situation you can write
\addtocontents{toc}{\protect\thispagestyle{empty}}
somewhere before your first chapter.