4

I want to publish a book, and our publishing center style guide suggests the following style rules for the table of contents:

  1. Every book chapter and section must have its entry in TOC.
  2. If a book chapter doesn't have any sections, then it must have its page number in TOC, preceded by dots,
  3. If a book chapter has nested sections, then only its name without page number must be present in TOC.

So I would like to suppress page numbers for numbered chapters, and show them only for unnumbered chapters, such as Introduction and Conclusion.

The MWE is below:

\documentclass[paper=a4, 
               fontsize=14pt, 
               DIV=calc,
               twoside=false,
               headings=small,
               numbers=endperiod,
               chapterentrydots=true,
               ]{scrbook}

\begin{document}

\tableofcontents

\chapter*{Introduction}\addcontentsline{toc}{chapter}{Introduction}
\newpage
\newpage
\chapter{Chapter without page number}
\section{Section One}


\end{document}

enter image description here

4

Update

With KOMA version 3.20 (or newer) it is possible to define an own tocentry style for unnumbered chapters. So here is a new suggestion to suppress the page numbers of all numbered chapters and to insert a dotted line for the unnumbered chapter entries in TOC.

\documentclass[paper=a4, 
               fontsize=14pt, 
               DIV=calc,
               twoside=false,
               headings=small,
               numbers=endperiod,
               ]{scrbook}[2016/05/10]% needs version 3.20 or newer

\RedeclareSectionCommand[
  tocpagenumberbox=\blankbox
]{chapter}
\newcommand\blankbox[1]{}% do nothing

\DeclareTOCStyleEntry[
  level=\chaptertocdepth,
  indent=0pt,
  numwidth=1.5em,
  linefill=\TOCLineLeaderFill
]{chapter}{unnumberedchapter}
\makeatletter
  \def\toclevel@unnumberedchapter{\chaptertocdepth}% needed if hyperref is used
\makeatother

\usepackage{xpatch}
\xpatchcmd{\addchaptertocentry}
  {\addtocentrydefault{chapter}{#1}{#2}}
  {\IfArgIsEmpty{#1}
    {\addtocentrydefault{unnumberedchapter}{#1}{#2}}
    {\addtocentrydefault{chapter}{#1}{#2}}%
  }{}{\PatchFailed}

%\usepackage{hyperref}
\begin{document}
\tableofcontents
\addchap{Introduction}
\chapter{Chapter}
\section{Section One}
\end{document}

enter image description here


Original answer

With a KOMA-Script class you can use

\addchap{Introduction}

instead \chapter*{Introduction}\addcontentsline{toc}{chapter}{Introduction}.

Here is a suggestion to suppress page numbers of all numbered chapters in TOC:

\documentclass[paper=a4, 
               fontsize=14pt, 
               DIV=calc,
               twoside=false,
               headings=small,
               numbers=endperiod,
               ]{scrbook}

\setkomafont{chapterentrypagenumber}{\nullfont}

\renewcommand\addchaptertocentry[2]{%
  \IfArgIsEmpty{#1}
    {\addtocontents{toc}
        {\protect\begingroup
          \protect\setkomafont{chapterentrypagenumber}{}%
          \protect\KOMAoptions{chapterentrydots}%
        }%
      \addtocentrydefault{chapter}{}{#2}%
      \addtocontents{toc}{\protect\endgroup}%
    }
    {\addtocentrydefault{chapter}{#1}{#2}}%
}

\begin{document}
\tableofcontents
\addchap{Introduction}
\chapter{Chapter without page number}
\section{Section One}
\end{document}

enter image description here

  • Unfortunately, miktex complains about undefined control sequence: ! Undefined control sequence. \addchaptertocentry #1#2->\IfArgIsEmpty {#1} {\addtocontents {toc}{\protect... l.26 \addchap{Introduction} The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., \hobx'), type I' and the correct spelling (e.g., I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined.` Otherwise your TOC looks just great, thank you. – Andrey Sobolev Dec 2 '15 at 7:43
  • I tried it with TexLive on Linux, and it worked wonderfully! Thank you! – Andrey Sobolev Dec 2 '15 at 8:12
  • Maybe you have to update your MiKTeX packages. Current KOMA Script Version in both MiKTeX 2.9 and TeXLive 2015 ist 3.19a. But you can replace \IfArgIsEmpty{#1}{...}{...} by \ifstr{#1}{}{...}{...}. – esdd Dec 2 '15 at 8:32
  • MikTex 2.9 Package Manager shows me 3.15 as the latest version available, so I had to update it manually. Meanwhile I got one more question: if I try to import color or xcolor package, everything breaks down. Maybe you know why? – Andrey Sobolev Dec 2 '15 at 9:13
  • I found a workaround by removing everything connected with pdfcolorstack from .toc file manually, but if there is a way to do this automatically, I'll be very grateful. – Andrey Sobolev Dec 2 '15 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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