[Tex/LaTex] Appendix at the end of Chapter

appendicestable of contents

I am writing a book and would like to have appendices at the end of each chapter, for instance appendices at the end of Chapter 2 should look like:

Appendix 2A Derivation of MMSE Equation

Appendix 2B Proof of ….

Each appendix can contain subsections. In the TOC they should also appear with these titles. And the page headings also should she the title of the appendix. I have looked at the appendix package but it does not seem to offer all these capabilities. Any ideas how can I do this?

Best Answer

Here's a possible solution in which I assumed that the sections corresponding to appendices will be the last sections of their corresponding chapter. I defined an \appsection command to change \thesection so as to obtain the required formatting; this command has to be issued before the appendices for a chapter. Using the etoolbox package, \chapter restores the original meaning of \thesection.

\documentclass{report}
\usepackage{etoolbox}

\pretocmd{\chapter}{\renewcommand\thesection{\thechapter.\arabic{section}}}{}{}

\newcommand\appsection{%
  \setcounter{section}{0}%
  \renewcommand\thesection{\thechapter.\Alph{section}}}

\begin{document}

\tableofcontents
\chapter{Test Chapter One}
\section{A regular section in chapter one}

\chapter{Test Chapter Two}
\section{A regular section in chapter two}
\appsection
\section{Derivation of MMSE Equation}
\subsection{Some remarks}
\subsection{Preliminary results}
\section{Proof of the main result}
\subsection{Some important consequences}

\chapter{Test Chapter Three}
\section{A regular section in chapter three}
\appsection
\section{Derivation of ABCD Equation}
\subsection{Preliminary results}
\section{Proof of the main result}
\subsection{Some important consequences}
\subsection{Some remarks}

\end{document}

enter image description here

In case hyperref is loaded, the above code has to be slightly changed to

\pretocmd{\chapter}{%
  \renewcommand\thesection{\thechapter.\arabic{section}}%
  \renewcommand\theHsection{\thechapter.\arabic{section}}}{}{}

\newcommand\appsection{%
  \setcounter{section}{0}%
  \renewcommand\thesection{\thechapter.\Alph{section}}%
  \renewcommand\theHsection{\thechapter.\Alph{section}}}
Related Question