2

In the table of contents, I want the chapters to appear like

Chapter 1: Preface

and

Chapter 4: Advanced Topics

I tried to modify the \l@chapter command as shown in the MWE but what I get is actually

Chapter 1 Preface:

How to fix it?

I want to do it without titletoc or tocloft.

enter image description here

\documentclass{book}
\makeatletter
\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      Chapter #1:\nobreak\hfil % <<<--- Changed
      \nobreak\hb@xt@\@pnumwidth{\hss #2%
                                 \kern-\p@\kern\p@}\par
      \penalty\@highpenalty
    \endgroup
  \fi}
\begin{document}
\tableofcontents
\chapter{Preface}
\end{document}

1 Answer 1

4

The chapter number is printed in the \@chapter command, not in the \l@chapter command. So you need to patch both commands to do what you want without using one of the TOC packages:

\documentclass{book}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\l@chapter}{#1}{\chaptername{} #1}{}{}
\patchcmd{\@chapter}{\numberline{\thechapter}}{\numberline{\thechapter:}}{}{}
\makeatother
\begin{document}
\tableofcontents
\chapter{Preface}
\end{document}

output of code

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .