1

In a book I am working on, I'd like the TOC entries for chapters to read

Chapter 1: foobar        3

while for Appendices

Appendix 1:  bletch    197

Using tocloft, the lines

\renewcommand{\cftchappresnum}{Chapter }
\renewcommand{\cftchapaftersnum}{: }

(together with a line to control width) in my preface does the trick for the chapter name formatting, but unfortunately those lines seem to need to be in the preface, so I can't later redefine cftchappresnum when starting to process appendices. I've also tried making the definition of cftchappresnum dependent on that boolean:

\newboolean{inappendix}
\setboolean{inappendix}{false}
\renewcommand{\cftchappresnum}{\ifthenelse{\boolean{inappendix}}{Appendix }{Chapter }}

and then issuing \setboolean{inappendix}{true} just after \appendix, but this fails as well (it acts as though inappendix is always false).

2

The change of \cftchappresnum must be written to the ToC directly to make it effective for the appendix when the .toc file is called, i.e.

\addtocontents{toc}{\protect\renewcommand{\protect\cftchappresnum}{\protect\appendixname~}}

will write the change (use \protect to prevent errors during the writing process)

\documentclass{book}
\usepackage{tocloft}


\renewcommand{\cftchappresnum}{\chaptername~}
\renewcommand{\cftchapaftersnum}{: }

\addtolength{\cftchapnumwidth}{50pt}

\begin{document}

\tableofcontents

\chapter{Foo}

\appendix

\addtocontents{toc}{\protect\renewcommand{\protect\cftchappresnum}{\protect\appendixname~}}

\chapter{Foo appendix}

\end{document}

I leave the real length specification of \cftchapnumwidth to the O.P.

enter image description here

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.