[Tex/LaTex] Table of Contents: Changing the formatting of specific Chapters (the Appendices)

appendicestable of contents

Instead of my Appendix titles appearing in my Table of Contents formatted like the rest of my Chapters (I'm using the report class) I would prefer for them to appear in the same format as my Sections (see second image below). However, I can't just use \section for each Appendix, as I would like them to be treated as Chapters for all purposes other than the ToC.

My MWE (no additional packages specified):

\documentclass[12pt,a4paper,final]{report}

\begin{document}

    \tableofcontents
    \pagebreak

% Chapters  
    \chapter{First Chapter}
    \chapter{Second Chapter}
    \chapter{Third Chapter}
    \chapter{Fourth Chapter}

%Appendices
    \appendix
    \pagebreak % So that \addcontentsline is given the right page number
    \addcontentsline{toc}{chapter}{Appendices}
    \chapter{First Appendix}
    \chapter{Second Appendix}
    \chapter{Third Appendix}

\end{document}

This gives me a Table of Contents that looks like this, where each Appendix (as well as the additional line `Appendices') are formatted as Chapters:

ToC with Appendices formatted as Chapters

However, I would prefer for them to appear in the ToC formatted like Sections. I can produce this manually by editing the ToC file, changing (for example) the line:

\contentsline {chapter}{\numberline {A}First Appendix}{6} 

to:

\contentsline {section}{\numberline {A}First Appendix}{6}

Editing each Appendix line the same way gives me:

ToC with Appendices formatted at Sections

…which is exactly how I want the finished thing to look.

Obviously manually editing the .toc file works, but isn't ideal (as it gets overwritten when I recompile) and, to be honest, the simplicity of the change makes me feel like there must be a way to do it cleanly and automatically. And I'd always prefer a 'proper' (elegant) solution. If anyone can help me to produce the same result 'properly', I would be very grateful.

N.B. I have found a few solutions to similar questions, but none of them quite cuts it:

  • The obvious solution is to just make the Appendices Sections instead of Chapters, but that changes how they appear in the body (and I would prefer each Appendix to be treated as a Chapter in all instances other than the ToC.

  • I have tried using \chapter*{First Appendix} followed by \addcontentsline{toc}{section}{First Appendix} but that removes the 'numbering' (or rather lettering) in the main body and in the ToC. I would prefer that it still say 'Appendix A' etc.

Best Answer

Here is a solution with \let\l@chapter\l@section in .toc

\documentclass[12pt,a4paper,final]{report}

\begin{document}

    \tableofcontents
    \pagebreak

% Chapters  
    \chapter{First Chapter}
    \chapter{Second Chapter}
    \chapter{Third Chapter}
    \chapter{Fourth Chapter}

%Appendices
    \appendix
    \pagebreak % So that \addcontentsline is given the right page number
    \addcontentsline{toc}{chapter}{Appendices}
    \addtocontents{toc}{\protect\makeatletter}
    \addtocontents{toc}{\string\let\string\l@chapter\string\l@section}
    \addtocontents{toc}{\protect\makeatother}
    \chapter{First Appendix}
    \chapter{Second Appendix}
    \chapter{Third Appendix}

\end{document}