Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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

share|improve this answer
    
Thank, this was exactly what i was looking for. –  Vahid Damanafshan Jun 19 '12 at 23:46
    
@Gonzalo Medina How to use your code in \documentclass{report}? –  minthao_2011 Feb 12 at 15:22
    
@minthao_2011 Please feel free to open a follow-up question. –  Gonzalo Medina Feb 12 at 15:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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