[Tex/LaTex] How to keep Appendix (as is) in TOC but have heading capitalized in report

appendiceschaptersreporttable of contents

I am using report and I need to have chapter headings be in all caps (including the Appendix) but not in the TOC. E.g. instead of "Appendix A", it should appear as "APPENDIX A" inside the paper and "Appendix A" in the TOC. I seem to have fixed the regular chapters but cannot seem to figure out how to fix the Appendix.

I can just change \appendixname to APPENDIX, but then it will appear as all caps in the TOC (which I would prefer not be the case). Changing the definition of \appendix for report class seems to have the same effect (I believe because it's basically just redefining \@chapapp):

\renewcommand{\appendix}{\par
   \setcounter{chapter}{0}%
   \setcounter{section}{0}%
   \gdef\@chapapp{APPENDIX}% modified from \appendixname
   \gdef\thechapter{\@Alph\c@chapter}}

I was able to fix the regular chapter issue by keeping \chaptername as is and hard coding CHAPTER rather than using \@chapapp in the following (which was part of the original template–I did not create this so I don't fully understand what all this is doing):

\def\@chapter[#1]#2{
    \ifnum \c@secnumdepth >\m@ne
        \refstepcounter{chapter}%
        \typeout{CHAPTER\space\thechapter.} % originally used \@chapapp
        \addcontentsline{toc}{chapter}%
        {\@chapapp\space {\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
}

Honestly, I don't understand why \uppercase doesn't work in the following but it doesn't capitalize "Chapter" from \@chapapp (this was from the original template as well) and still appears in the style file after the above (the chapter titles have always appeared in CAPS, just not the "Chapter x:" prefix).

\def\@makechapterhead#1{%
    \vspace*{-20\p@}%
    {\parindent \z@ \raggedright \normalfont
    \interlinepenalty\@M
    \ifnum \c@secnumdepth >\m@ne
        \centering  \large\bfseries 
        \uppercase{\@chapapp\space \thechapter: #1}
    \fi
    \vskip 20\p@
    }
}

Best Answer

A solution without hardcoding or editing the .cls file directly:

The O.P. was right in his assumption about \@makechapterhead:

\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
        \huge\bfseries \@chapapp\space \thechapter
        \par\nobreak
        \vskip 20\p@
    \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 40\p@
  }}

The line with \@chapapp does indeed print Chapter (or Appendix), followed by the chapter number.

To get this uppercase, it's necessary to use \MakeUppercase{\@chapapp}, not \uppercase.

Instead of editing the report.cls code, it's better to use \xpatchcmd, looking for the line \huge\bfseries\@chapapp.. and replacing this with the relevant code using \MakeUppercase.

However, this should be done only after \appendix, so append this patch to \appendix using \xapptocmd{\appendix}{...} (see the code please)

\documentclass{report}


\usepackage{xpatch}


\makeatletter

\xapptocmd{\appendix}{%
\xpatchcmd{\@makechapterhead}{%
  \huge\bfseries \@chapapp\space \thechapter
}{%
  \huge\bfseries \MakeUppercase{\@chapapp}\space \thechapter
}{\typeout{Patching \@makechapterhead succeeded}}{\typeout{Patching failed}}% Patching ends
}{\typeout{Appending succeeded}}{\typeout{Appending failed}}
\makeatother

\begin{document}

\chapter{First}

\appendix

\chapter{Appendix 1}

\end{document}

enter image description here

Please note that my code does not work for \chapter* like - appendices.