How can I add an appendix with two or 3 sections after each chapter in a book?
[Tex/LaTex] Appendix after each chapter
appendiceschapters
Related Solutions
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}
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}}}
This is a modification of https://tex.stackexchange.com/a/186907/4427
\documentclass{book}
\usepackage{environ}
\newtoks\mainnotetoks
\newtoks\tempnotetoks
\newtoks\prenotetoks
\newtoks\postnotetoks
\NewEnviron{appendixatend}{%
\tempnotetoks=\expandafter{\BODY}%
\edef\notetemp{%
\the\mainnotetoks % what was already stored
\the\prenotetoks % text before the new note
\the\tempnotetoks % the current note
\the\postnotetoks % text after the new note
}%
% update \mainnotetoks
\global\mainnotetoks=\expandafter{\notetemp}%
}
\newcommand\includeappendices{%
\appendix
\chapter*{Appendix}
\renewcommand{\thesection}{\Alph{section}}
\the\mainnotetoks}
% set the pre and post note
\prenotetoks={}
\postnotetoks={}
\begin{document}
\mainmatter
\chapter{Chapter 1}
\section{Section 1}
This is the first section of the first chapter. For details see Appendix 1.
\begin{appendixatend}
\section{Appendix for Chapter 1, Section 1}
Here is additional information that is typeset at the end of the book.
\end{appendixatend}
\chapter{Chapter 2}
\section{A new section}
This is a new section in the second Chapter. Even though I add a new appendix here, it will become consolidated with the first appendix at the end of the book.
\begin{appendixatend}
\section{Appendix for a new section}
This is the appendix for "A new section" in Chapter 2
\end{appendixatend}
\includeappendices
\end{document}
Best Answer
The
subappendices
environment from theappendix
package could be useful here:An image of the resulting ToC:
An image of the first page of appendices for one of the chapters: