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.

I have created two custom macros for chapter and part command. When I am using following code:

\documentclass[final]{book}

\usepackage{lipsum}
\usepackage{tocloft}
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cftchapfont}{\mdseries}
\renewcommand{\cftchappagefont}{\mdseries}

\long\def \mychapter#1{
\chapter*{#1}
\addcontentsline{toc}{chapter}{#1}
}

\long\def \mypart#1#2{
\part*{#1 \\* #2}
\addcontentsline{toc}{part}{#1\\ #2}
}

\begin{document}

\tableofcontents

\mypart{PART NUMBER 1}{Part Title}
\mychapter{Some chapter 1}
\lipsum[1-10]
\mychapter{Some chapter 2}
\lipsum[1-10]
\mychapter{Some chapter 3}
\lipsum[1-10]
\mypart{PART NUMBER 2}{Part Title}
\mychapter{Some chapter 4}
\lipsum[1-10]
\mychapter{Some chapter 5}
\lipsum[1-10]
\mychapter{Some chapter 6}
\lipsum[1-10]
\mychapter{Some chapter 7}
\lipsum[1-10]
\mypart{PART NUMBER 3}{Part Title}
\mychapter{Some chapter 8}
\lipsum[1-10]
\mychapter{Some chapter 9}
\lipsum[1-10]
\mychapter{Some chapter 10}
\lipsum[1-10]
\mychapter{Some chapter 11}
\lipsum[1-10]

\end{document}

it generates following Table of Contents:

Table of Contents with improper page numbers

Page numbers for \part in this Table of Contents are not correct. Instead of pointing to real page where \part text is printed, they point to page where first chapter within that part starts.

I have used pdflatex two times to make sure page numbers will be correct, but they are not.

Questions:

  1. Why are page numbers for \part not correct in ToC?
  2. How can I supress page numbers for \part altogether in ToC, but leave Table of Contents entry for \part unchanged otherwise?
share|improve this question
    
1. Probably because \part is on a single page of its own, and the real contents begins with the first chapter. So it's rather sensible. 2. I only know how to do that with titletoc. –  Bernard Apr 29 at 15:09
    
@Bernard Can you post an answer with solution to 2. with titletoc? –  Rafal Apr 29 at 15:13
1  
You should clear the double pages before a new part starts: \cleardoublepage –  Christian Hupfer Apr 29 at 15:17
    
@ChristianHupfer Why? –  Rafal Apr 29 at 15:18
1  
@Rafal: I suspect a side effect of tocloft. The page information is not updated correctly otherwise. –  Christian Hupfer Apr 29 at 15:22

2 Answers 2

up vote 5 down vote accepted

You're taking the wrong approach. If you don't want any element to be numbered, just tell LaTeX so.

\documentclass[final]{book}

\usepackage{lipsum}
\usepackage{tocloft}
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cftchapfont}{\mdseries}
\renewcommand{\cftchappagefont}{\mdseries}

\setcounter{secnumdepth}{-2}

\newcommand\mypart[2]{\part{#1 \\ #2}}

\begin{document}

\tableofcontents

\mypart{PART NUMBER 1}{Part Title}
\chapter{Some chapter 1}
\lipsum[1-10]
\chapter{Some chapter 2}
\lipsum[1-10]
\chapter{Some chapter 3}
\lipsum[1-10]
\mypart{PART NUMBER 2}{Part Title}
\chapter{Some chapter 4}
\lipsum[1-10]
\chapter{Some chapter 5}
\lipsum[1-10]
\chapter{Some chapter 6}
\lipsum[1-10]
\chapter{Some chapter 7}
\lipsum[1-10]
\mypart{PART NUMBER 3}{Part Title}
\chapter{Some chapter 8}
\lipsum[1-10]
\chapter{Some chapter 9}
\lipsum[1-10]
\chapter{Some chapter 10}
\lipsum[1-10]
\chapter{Some chapter 11}
\lipsum[1-10]

\end{document}

LaTeX will take care of the rest.

enter image description here

If you want to suppress the page number for the parts, then do like this:

\documentclass[final]{book}

\usepackage{lipsum}
\usepackage{tocloft}
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cftchapfont}{\mdseries}
\renewcommand{\cftchappagefont}{\mdseries}

% suppress page number in toc for parts
\cftpagenumbersoff{part}

\setcounter{secnumdepth}{-2}

\newcommand\mypart[2]{\part{#1 \\ #2}}

\begin{document}

\tableofcontents

\mypart{PART NUMBER 1}{Part Title}
\chapter{Some chapter 1}
\lipsum[1-10]
\chapter{Some chapter 2}
\lipsum[1-10]
\chapter{Some chapter 3}
\lipsum[1-10]
\mypart{PART NUMBER 2}{Part Title}
\chapter{Some chapter 4}
\lipsum[1-10]
\chapter{Some chapter 5}
\lipsum[1-10]
\chapter{Some chapter 6}
\lipsum[1-10]
\chapter{Some chapter 7}
\lipsum[1-10]
\mypart{PART NUMBER 3}{Part Title}
\chapter{Some chapter 8}
\lipsum[1-10]
\chapter{Some chapter 9}
\lipsum[1-10]
\chapter{Some chapter 10}
\lipsum[1-10]
\chapter{Some chapter 11}
\lipsum[1-10]

\end{document}

enter image description here

Thanks to Mico for suggesting \cftpagenumbersoff.

share|improve this answer
    
Both code snippets work great. One question though - what do you mean by "If you don't want any element to be numbered, just tell LaTeX so"? Do you refer to \setcounter{secnumdepth}{-2} command? –  Rafal Apr 29 at 15:51
    
@Rafal Yes, that's the proper way, rather than defining a \mychapter command. –  egreg Apr 29 at 15:52
    
Why is this more 'proper' than defining new command? –  Rafal Apr 29 at 15:54
    
@Could one not say \begingroup \renewcommand{\thepage}{} \part{#1}{#2} \endgroup inside of your \mypart definition in order to drop the visual page numbering? –  Christian Hupfer Apr 29 at 15:56
1  
@Rafal For one thing: this doesn't require \addcontentsline. –  egreg Apr 29 at 16:18

This addresses the wrong page numbers first, but is only a hack due to the somewhat 'unhealthy' definition of \mypart

\documentclass[final]{book}

\usepackage{lipsum}
\usepackage{tocloft}
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cftchapfont}{\mdseries}
\renewcommand{\cftchappagefont}{\mdseries}

\long\def \mychapter#1{
\chapter*{#1}
\addcontentsline{toc}{chapter}{#1}
}


\long\def \mypart#1#2{%
\cleardoublepage
\addcontentsline{toc}{part}{#1\\ #2}
\part*{#1 \\* #2}

}

\begin{document}

\tableofcontents

\mypart{PART NUMBER 1}{Part Title}
\mychapter{Some chapter 1}
\lipsum[1-10]
\mychapter{Some chapter 2}
\lipsum[1-10]
\mychapter{Some chapter 3}
\lipsum[1-10]
\mypart{PART NUMBER 2}{Part Title}
\mychapter{Some chapter 4}
\lipsum[1-10]
\mychapter{Some chapter 5}
\lipsum[1-10]
\mychapter{Some chapter 6}
\lipsum[1-10]
\mychapter{Some chapter 7}
\lipsum[1-10]
\mypart{PART NUMBER 3}{Part Title}
\mychapter{Some chapter 8}
\lipsum[1-10]
\mychapter{Some chapter 9}
\lipsum[1-10]
\mychapter{Some chapter 10}
\lipsum[1-10]
\mychapter{Some chapter 11}
\lipsum[1-10]

\end{document}

enter image description here

EDIT Redefining the \mypart command.

I used the suggestions of egreg and mico and suggest another \mypart command which removes the first argument. I do not expect, that my answer is accepted.

\documentclass[final]{book}

\usepackage{lipsum}
\usepackage{tocloft}
\usepackage{fmtcount}
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cftchapfont}{\mdseries}
\renewcommand{\cftchappagefont}{\mdseries}

\cftpagenumbersoff{part} % According to Mico's suggestion

% 'Unhealthy' chapter redefinition 
\long\def \mychapter#1{
\chapter*{#1}
\addcontentsline{toc}{chapter}{#1}
}%

\setcounter{secnumdepth}{-2}%  % According to egreg's suggestion

% If literal number words should be used: apply this one 
\renewcommand{\thepart}{PART NUMBER~\NUMBERstring{part}}%
% If really numbers are desired:
%\renewcommand{\thepart}{PART NUMBER~\arabic{part}}

\newcommand{\mypart}[1]{%
\refstepcounter{part}% cheap trick ;-)
\part{\thepart~ \\* #1}
}%


\begin{document}

\tableofcontents


\mypart{Part Title}

\mychapter{Some chapter 1}
\lipsum[1-10]
\mychapter{Some chapter 2}
\lipsum[1-10]
\mychapter{Some chapter 3}
\lipsum[1-10]
\mypart{Part Title}
\mychapter{Some chapter 4}
\lipsum[1-10]
\mychapter{Some chapter 5}
\lipsum[1-10]
\mychapter{Some chapter 6}
\lipsum[1-10]
\mychapter{Some chapter 7}
\lipsum[1-10]
\mypart{Part Title}
\mychapter{Some chapter 8}
\lipsum[1-10]
\mychapter{Some chapter 9}
\lipsum[1-10]
\mychapter{Some chapter 10}
\lipsum[1-10]
\mychapter{Some chapter 11}
\lipsum[1-10]

\end{document}

enter image description here

share|improve this answer
    
Weirdly, it works only if \addcontentsline is before \part line. Otherwise, page numbers are again incorrect. Do you have any idea how to supress page numbers altogether? –  Rafal Apr 29 at 15:35
    
@Rafal - Where do you want to suppress the page numbers for part pages: In the ToC, the actual pages that contain the part headers, or both? –  Mico Apr 29 at 15:37
    
@Mico I want to supress page numbers in the ToC. Actually I supressed them on the actual pages as well, so here I just need to supress them in ToC. –  Rafal Apr 29 at 15:45
3  
@Rafal - To suppress the showing of page numbers for part-level entries in the ToC, issue the command \cftpagenumbersoff{part}. (See also p. 12 of the user guide of the tocloft package...) –  Mico Apr 29 at 15:57
    
@Mico That is actually most straightforward way of doing it, since I use tocloft package already. Thanks! –  Rafal Apr 29 at 16:03

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.