Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

For example, in my Table of Contents, I have,

Acknowledgments               ii
table of contents            iii
...
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.

share|improve this question
    
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
1  
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

1 Answer 1

up vote 2 down vote accepted

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.

enter image description here

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

enter image description here

\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}
share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.