[Tex/LaTex] Formatting Appendix Labels and its TOC Entry in the Report Document Class

appendicesreportsectioning

I'm using the standard TOC and appendix functionality in a report document class, in PDFLatex. Relevantly, I have

\documentclass{report}

....

\begin{document}

    \tableofcontents

    ...

    \chapter{Appendix}
    \appendix

        \section{Testing the LaTeX Appendix}
        \label{app:test1}
            hello

        \section{Testing Referencing to the Appendix}
        \label{app:test2}
            goodbye

\end{document}

This creates a TOC which looks like

a snippet of the TOC when using appendix sections

and an appendix section like

a snippet of the appendix chapter when using appendix sections

The issue is that the appendix section labels don't have a leading chapter number (e.g. they are .1 instead of 8.1, or better yet, 8.A), but I do like that the appendix sections appear as subsections of Appendix in the TOC.

Clearly this is because I define the appendix sections with \section whilst I'm using the report environment. However, changing my appendix sections to chapters like so…

\chapter{Appendix}
\appendix

    \chapter{Testing the LaTeX Appendix}
    \label{app:test1}
        hello

    \chapter{Testing Referencing to the Appendix}
    \label{app:test2}
        goodbye

makes each of them be treated like independent chapters (save a label change), which muddles up both the TOC…

a snippet of the TOC when using appendix chapters

and the actual appendix sections…

a snippet of the appendix chapter when using appendix chapters

How can I format my TOC and appendix entries like in the former case, though with the correct label numbers? The best outcome would see the appendix labels formatted as 8.A, etc.

Note I have attempted use of the appendix package and the begin{indices} environments with the same results.

Best Answer

Just redefine the \appendix switch in your preamble:

\documentclass{report}
\usepackage[utf8]{inputenc}

\makeatletter
\renewcommand\appendix{\par
 \gdef\@chapapp{\appendixname}%
 \gdef\thesection{\thechapter.\@Alph\c@section}}
\makeatother

\begin{document}

    \tableofcontents
\setcounter{chapter}{7}

    \appendix
    \chapter{Appendix}

        \section{Testing the LaTeX Appendix}
        \label{app:test1}
            hello

        \section{Testing Referencing to the Appendix}
        \label{app:test2}
            goodbye

\end{document} 

enter image description here