# Changing “Chapter A” to “Appendix A” in TOC - Existing solutions don't work

I'm writing my thesis using \documentclass{harvard-thesis}

My desired result for TOC would be:

Chapter 1.
Chapter 2.
Appendix A.


I use this to include the word "Chapter" in front of chapter numbers in TOC:

\renewcommand{\cftchappresnum}{Chapter }

My appendix was shown in TOC as "Chapter A" instead of the desired "Appendix A":

>\appendix
>\renewcommand\chaptername{Appendix }
>\include{appendices/appendixA}


I have applied solutions from How to force Latex to change from "A Appendix's name" to "Appendix A", Changing “Chapter A” to “Appendix A” in TOC as well as this patch:

\makeatletter
\patchcmd{\@chapter}{\protect {Chapter }}{\ifappendix{Appendix }\else{Chapter
}\fi}{}{}
\makeatother
\AtBeginEnvironment{appendices}{\appendixtrue}


None of them works. My current result for TOC is:

Chapter 1.
Chapter 2.
Chapter A.


If I comment out the renewcommand that includes "Chapter" then Appendix A will show correctly:

1.
2.
Appendix A.


Can someone help?

• Welcome to TeX.SE! – Cragfelt Dec 12 '17 at 15:56
• Believe it or not, but the document class harvard-thesis is not unique: Several versions of LaTeX document class files with this name may be found on the Internet. Which version might you be using? Please advise. – Mico Dec 12 '17 at 16:39
• @Mico I'm using this version: % @LaTeX-class-file{ % filename = "harvard-thesis.cls", % version = "0.4", % date = "4 April 2012", % codetable = "ISO/ASCII", – user148110 Dec 12 '17 at 16:46
• Can your version be downloaded from an online repository? – Mico Dec 12 '17 at 17:00
• @Mico it's from sharelatex.com, sharelatex.com/templates/thesis/harvard-phd – user148110 Dec 12 '17 at 17:48

Appendix chapters are considered chapters as well, specifically because that's what is written to the .toc file. To illustrate this, consider the following example:

\documentclass{book}

\usepackage{tocloft}

\renewcommand{\cftchappresnum}{Chapter }
\setlength{\cftchapnumwidth}{6em}% Just for this example

\begin{document}

\tableofcontents

\chapter{A chapter}

\appendix

\chapter{An appendix}

\end{document}


Here's what the .toc looks like:

\contentsline {chapter}{\numberline {1}A chapter}{3}
\contentsline {chapter}{\numberline {A}An appendix}{5}


Note that each \contentsline entry corresponds to an entry in the ToC and they're all considered chapter.

In order to fix your problem, you can still update \cftchappresnum in your preamble, but write an update to this macro as soon as you execute \appendix. Here's how you can update \appendix to do this automatically:

\documentclass{book}

\usepackage{tocloft}

\renewcommand{\cftchappresnum}{Chapter }
\setlength{\cftchapnumwidth}{7em}% Just for this example

\let\oldappendix\appendix
\renewcommand{\appendix}{%
\oldappendix
\addtocontents{toc} % Update \cftchappresnum within the .toc
{\protect\renewcommand{\protect\cftchappresnum}{Appendix }}
}

\begin{document}

\tableofcontents

\chapter{A chapter}

\appendix

\chapter{An appendix}

\end{document}


Now your .toc resembles:

\contentsline {chapter}{\numberline {1}A chapter}{3}
\renewcommand {\cftchappresnum }{Appendix }
\contentsline {chapter}{\numberline {A}An appendix}{5}


Each \contentsline entry is still a chapter, but \cftchappresnum was updated at the appropriate time within the .toc to print an Appendix  prefix for your appendix \chapters.

This works!

\renewcommand{\appendixname}{Appendix}
\renewcommand{\appendixtocname}{Appendix}
\usepackage{tocloft,calc}

\renewcommand{\cftchappresnum}{\chaptername\space}
\setlength{\cftchapnumwidth}{2em}
\makeatletter
\protect\renewcommand{\protect\cftchappresnum}{\appendixname\space}%
}%
}
\makeatother

\renewcommand\thechapter{\Alph{chapter}}
\renewcommand\thesection{\Alph{chapter}.\Roman{section}}
\setcounter{chapter}{0}

\include{chapters/chapter1}

\appendix
\renewcommand{\chaptername}{Appendix}
\include{appendices/appendixA}