7

I'm using the book class and I need to add the word "Chap" before the chapters numbers in the TOC. Please keep in mind that the "Chap" should only appear before my chapters numbers, not before starred chapters titles, the Index, appendices or anything similar in the TOC.
By the way, I prefer to use the book class codes rather than to use packages.
Can anybode help me accomplish this?
Here is a minimal example: ‎

\documentclass{book}‎
‎\usepackage[nottoc]{tocbibind}‎‎
‎\begin{document}‎‎
‎\tableofcontents‎‎
‎\chapter{One‎}‎‎
‎\chapter{Two‎}‎‎‎‎
‎\section{B‎la}‎‎
‎\chapter*{B‎la bla}
‎\addcontentsline{toc}{chapter}{bla‎ ‎bla}‎‎
‎\appendix‎‎
‎\chapter{App one}‎
‎\begin{thebibliography}{99}‎‎
‎\bibitem{bla‎}‎
‎bla‎
‎\end{thebibliography}‎‎‎             
‎\end{document}
7

Make a copy of \@chapter and then redefine \@chapter to add the word "Chap"; from the point on where the word must not appear, restore the original meaning of \@chapter:

\documentclass{book}

\makeatletter
\let\orig@chapter\@chapter
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
                       \if@mainmatter
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         \addcontentsline{toc}{chapter}%
                                   {Chap~\protect\numberline{\thechapter}#1}%
                       \else
                         \addcontentsline{toc}{chapter}{#1}%
                       \fi
                    \else
                      \addcontentsline{toc}{chapter}{#1}%
                    \fi
                    \chaptermark{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{#2}]%
                    \else
                      \@makechapterhead{#2}%
                      \@afterheading
                    \fi}
\makeatother

\begin{document}
\tableofcontents

\frontmatter
\chapter{Acknowledgements}

\mainmatter
\chapter{Test Chapter One}
\chapter{Test Chapter Two}

\makeatletter
\let\@chapter\orig@chapter
\makeatother
\appendix
\chapter{Test Appendix One}

\end{document}

An image of the resulting ToC:

enter image description here

  • @Gonzalo Medina How to use your code in \documentclass{report}? – minthao_2011 Feb 12 '14 at 15:22
  • @minthao_2011 Please feel free to open a follow-up question. – Gonzalo Medina Feb 12 '14 at 15:39

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.