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?
Asked
Active
Viewed 1,821 times
9
minthao_2011
- 4,534
- 7
- 36
- 61
-
I don't understand the error. Can you please mention the code? right now in my thesis, \section are used for every chapter which displays chapter like 1 introduction, 2 literature. I'm using this \documentclass[12pt, chapterprefix]{article} \usepackage[a4paper, margin=20mm]{geometry}? – Sajed ahmad Mar 13 '24 at 04:44
2 Answers
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}

Gonzalo Medina
- 505,128
-
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 -
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):

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

karlkoeller
- 124,410
-
-
@minthao_2011 Do you have something like
\chapter*{appendix}in your document? – karlkoeller Feb 13 '14 at 05:13 -
-
@minthao_2011 Are you saying that you want to insert the word
Appendixinstead ofChapfor your appendices? – karlkoeller Feb 13 '14 at 05:21 -
-
-
@Karloeller How to use the
\usepackage{fancyhdr}\pagestyle{fancyplain}
\pagestyle{fancy}in your code? – minthao_2011 Feb 14 '14 at 16:12 -
-
-
@minthao_2011 Sorry for the late reply. Simply change the definition to
\renewcommand\cftchappresnum{Chap.~}if you want the dot before the number or add\renewcommand\cftchapaftersnum{.}if you want it after the number. – karlkoeller Jun 28 '15 at 14:43