0

I have the code below and it works, but not exactly the way I want.

\documentclass{report}
\usepackage[titles]{tocloft}
\usepackage{titlesec}
\renewcommand{\contentsname}{Table of contents}
\renewcommand{\cftchappresnum}{CHAPTER }
\renewcommand{\cftchapnumwidth}{0pt}
\renewcommand{\cftchapaftersnumb}{\vspace{3mm}\\}
\renewcommand{\cftchapfont}{\normalfont}
\renewcommand{\cftchappagefont}{\normalfont}
\renewcommand{\cftdotsep}{1}
\renewcommand{\cftchapleader}{\cftdotfill{\cftsecdotsep}}

\addtocontents{toc}{~\hfill  Page\par}
\titleformat{name=\chapter, numberless}[block]{\bfseries\large\filleft} {}{0em}{\MakeUppercase}[{\titlerule[1pt]}]
\titleformat{name=\chapter}[display]{\bfseries\huge\filleft} {\chaptername~\thechapter}{3ex}{\MakeUppercase}[{\titlerule[1pt]}]

\begin{document}
\tableofcontents

\chapter{FIRST CHAPTER}
\section{First Section}
\chapter{SECOND CHAPTER}
\chapter{THIRD CHAPTER}

\appendix
\chapter{ERASMUS POLICY}
\chapter{ERASMUS COUNTRY CODES}

\end{document}

Here is the output

enter image description here

What I need help with is

The appendix starts with the word "CHAPTER", whereas I want it to be "APPENDIX-A", "APPENDIX-B" and so on

Günal
  • 3,393
  • 8
  • 31
  • 31

1 Answers1

2

You have two things to fix:

  1. Your body text has appendices titled wrong as well. According to Page 4 of the documentation of the titlesec package, you should have used \chaptertitlename instead of \chaptername in your second \titleformat.
    • Why would you need two \titleformat anyway? You should keep only one.
  2. Now the fix for the table of contents and a quick search yields this answer. To accommodate your style, you would also use \MakeUppercase.

MWE

\documentclass{report}
\usepackage[titles]{tocloft}
\usepackage{titlesec}
\renewcommand{\contentsname}{Table of contents}
% Don't use this:
%\renewcommand{\cftchappresnum}{CHAPTER }
% Use this:
\renewcommand{\cftchappresnum}{\MakeUppercase{\chaptername}\space}
% Modified from https://tex.stackexchange.com/a/56845/164314
\makeatletter
\g@addto@macro\appendix{%
  \addtocontents{toc}{%
    \protect\renewcommand{\protect\cftchappresnum}{\MakeUppercase{\appendixname}-}%
  }%
}
\makeatother
\renewcommand{\cftchapnumwidth}{0pt}
\renewcommand{\cftchapaftersnumb}{\vspace{3mm}\\}
\renewcommand{\cftchapfont}{\normalfont}
\renewcommand{\cftchappagefont}{\normalfont}
\renewcommand{\cftdotsep}{1}
\renewcommand{\cftchapleader}{\cftdotfill{\cftsecdotsep}}

\addtocontents{toc}{~\hfill  Page\par}
% You don't need to define title format twice
%\titleformat{name=\chapter, numberless}[block]{\bfseries\large\filleft} {}{0em}{\MakeUppercase}[{\titlerule[1pt]}]
%\titleformat{name=\chapter}[display]{\bfseries\huge\filleft} {\chaptername~\thechapter}{3ex}{\MakeUppercase}[{\titlerule[1pt]}]
% Use \chaptertitlename:
\titleformat{name=\chapter}[display]{\bfseries\huge\filleft} {\chaptertitlename~\thechapter}{3ex}{\MakeUppercase}[{\titlerule[1pt]}]

\begin{document}
\tableofcontents

\chapter{FIRST CHAPTER}
\section{First Section}
\chapter{SECOND CHAPTER}
\chapter{THIRD CHAPTER}

\appendix
\chapter{ERASMUS POLICY}
\chapter{ERASMUS COUNTRY CODES}

\end{document}

Outputs

Table of contents:

enter image description here

Body appendices:

enter image description here

Ruixi Zhang
  • 9,553