# Omitting only the page number of chapter's heading in ToC

How can I remove the page number of the chapter's header in ToC, without removing the page numbers of the preface pages?

Acknowledgments               ii
...
abstract                    viii

Chapter
1 Chapter one                 1
1.1 Section one             1
...
2 Chapter two                 2
2.1 Section one               2
... and so on...


How to remove the first page number 1 or 2 that related to the chapters' headers without touching the page numbers of the preface pages?

As for the document class, I am using \documentclass[doublelespace,tocchapterhead], together with file .cls of what I think was originally called chicagothesis or something like that.

I have tried to to removed #2 in:

\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par


But the result was, the page numbers of all headers have been removed. Is there any way to control that? I do not want to use tocloft package or etoolbox package.

-
Would you be able to provide a link to the .cls file you speak of? – Werner May 4 '12 at 5:00
Hello Werner, How can I provide it? Is there anyway? As far as I know, there is no link online for the .cls file that I am using. I only have it as a file. – Mara May 4 '12 at 5:52
You mention "chicagothesis or something" which isn't very specific. A quick search on Google provided easychithesis.cls which shows the same code snippet for \l@chapter you provide. Is this it? If all else fails, paste the code for the .cls on PasteBin and provide a link to it in your original post via an edit. – Werner May 4 '12 at 5:56
Hello again Werner, here is the link you asked me for: pastebin.com/nNBrUASu. I have just logged in, I will look into the answer below, I hope it will do. Thank you. – Mara May 4 '12 at 22:11

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}{%
}%
\newcommand{\restoretocpage}{%
}%
\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
\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
\hskip  -\leftskip
% : 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}{%
\newcommand{\restoretocpage}{%
%---------------------------------------------------


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}

-
Dear Werner, I have applied the example on my cls and tex files. It worked. I am grateful. The thing is, the design of the preamble of the thesis depends on \include, and therefore, the chapters are independent files. Thus, when I added the redefinition commands to the cls file, and added \gobbletocpage before each \include{chapter}, the result was deleting the page numbers of the sections, subsections as well. So, I had to add \restoretocpage inside each chapter before the first section of each one. Is there a way to make it automatically all in cls file? – Mara May 5 '12 at 8:03
UPDATE: Hello Werner. The link here is for the same .cls file I am using, but now it is with redefinitions you suggested. pastebin.com/V1r87cP8 – Mara May 6 '12 at 7:38
@Mara: I've updated \l@chapter. Let me know if this fixes your current setup (or not). – Werner May 7 '12 at 15:32
UPDATE:To Werner: I have examined the modification on cls file that you provided and it is now working nicely. Accordingly, I have updated the preamble. Thank you. – Mara May 9 '12 at 4:56
Update: To Werner. Sorry, I have just realized that was mistaken. Unfortunately, the modification did not work because of two problems. 1. Problem had accord with bold-font of the chapter numbers. Previously, I had defined bold-font numbers for chapters with the command \bfseries, and I had disabled the command \advance, and it was working, I mean only the number of the chapters were bold, but with the new modification, – Mara May 9 '12 at 5:35