8

At here Adding the word "Chap" before the chapters numbers in the TOC the word Chapter added in \documentclass{book}. Now I want to use them in \documentclass{report}. How can I do that?

10

Here's the modification for the report class (basically, it's the same code but suppressing the conditional test for the \frontmatter); I defined two commands \AddChap and \SuppChap to activate (deactivate, resp.) the addition:

\documentclass{report}

\makeatletter
\let\orig@chapter\@chapter
\newcommand\SuppChap{%
  \let\@chapter\orig@chapter}
\newcommand\AddChap{%
\def\@chapter[##1]##2{\ifnum \c@secnumdepth >\m@ne
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         \addcontentsline{toc}{chapter}%
                                   {Chap~\protect\numberline{\thechapter}##1}%
                       \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

\chapter{Acknowledgements}

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

\SuppChap
\appendix
\chapter{Test Appendix One}

\end{document}

enter image description here

  • I am a Vietnamese. If I use \usepackage[utf8]{vietnam}. Can I repair the "Chap" into the "Chương" or "Chuong"? – minthao_2011 Feb 12 '14 at 16:03
  • How Can add the word Index in \tableofcontents? – minthao_2011 Nov 18 '14 at 16:02
8

A much simpler solution with the tocloft package.

\documentclass{report}
\usepackage{tocloft}

\newlength\mylength

\renewcommand\cftchappresnum{Chap~}
\settowidth\mylength{\bfseries\cftchappresnum\cftchapaftersnum}
\addtolength\cftchapnumwidth{\mylength}

\begin{document}

\tableofcontents

\chapter{Intro}

\chapter{Test}

\end{document} 

Output (ToC):

enter image description here


EDIT

If you want to add the word "Appendix" instead of "Chap" for your appendices, you can load the package etoolbox and add the following lines in your preamble:

\apptocmd{\appendix}
  {\addtocontents{toc}{%  
   \protect\addtolength\protect\cftchapnumwidth{-\mylength}%
   \protect\renewcommand{\protect\cftchappresnum}{Appendix~}%
   \protect\settowidth\mylength{\bfseries\protect\cftchappresnum\protect\cftchapaftersnum}%
   \protect\addtolength\protect\cftchapnumwidth{\mylength}}%
  }{}{}

Complete MWE:

\documentclass{report}
\usepackage{tocloft}
\usepackage{etoolbox}
\apptocmd{\appendix}
  {\addtocontents{toc}{%  
   \protect\addtolength\protect\cftchapnumwidth{-\mylength}%
   \protect\renewcommand{\protect\cftchappresnum}{Appendix~}%
   \protect\settowidth\mylength{\bfseries\protect\cftchappresnum\protect\cftchapaftersnum}%
   \protect\addtolength\protect\cftchapnumwidth{\mylength}}%
  }{}{}

\newlength\mylength

\renewcommand\cftchappresnum{Chap~}
\settowidth\mylength{\bfseries\cftchappresnum\cftchapaftersnum}
\addtolength\cftchapnumwidth{\mylength}

\begin{document}

\tableofcontents

\chapter{Intro}

\chapter{Test}

\appendix

\chapter{Conclusions}

\end{document} 

Output (ToC):

enter image description here

  • If I want to add the word "Appendix" in Toc, how must I do? – minthao_2011 Feb 13 '14 at 5:11
  • @minthao_2011 Do you have something like \chapter*{appendix} in your document? – karlkoeller Feb 13 '14 at 5:13
  • No. I have some appendices. – minthao_2011 Feb 13 '14 at 5:14
  • @minthao_2011 Are you saying that you want to insert the word Appendix instead of Chap for your appendices? – karlkoeller Feb 13 '14 at 5:21
  • Yes. I want so. – minthao_2011 Feb 13 '14 at 5:29

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.