# Different TOC labels on Chapters and Appendices

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).

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}{: }

\begin{document}

\tableofcontents

\chapter{Foo}

\appendix


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