I want to create a list of appendices at the end of my document, and add the corresponding entry and page number to the table of contents.
The following code is a simplified version of my code (MWE), with dummy text applied.
\documentclass{report}
\usepackage{setspace}
\usepackage{titlesec}
\usepackage{tocloft}
\usepackage{etoolbox}
\usepackage{appendix}
\usepackage{lipsum}
\makeatletter % start of
\newcommand{\listappendixname}{Anhangsverzeichnis}
\newlistof{appendix}{apc}{\listappendixname}
\AtBeginEnvironment{appendices}{%
\clearpage
\addcontentsline{toc}{chapter}{Anhangsverzeichnis}
\write\@auxout{%
\string\let\string\latex@tf@toc\string\tf@toc%
\string\let\string\tf@toc\string\tf@apc%
}
}
\AtEndEnvironment{appendices}{%
\write\@auxout{%
\string\let\string\tf@toc\string\latex@tf@toc%
}
}
\makeatother
\begin{document}
\tableofcontents
%\nopagebreakchapter{bla bla}
\chapter{bla bla}
\lipsum[2-3]
\section{bla bla bla}
\lipsum[2-3]
\subsection{bla bla bla}
\lipsum[2-3]
\subsection{bla bla bla}
\lipsum[2-3]
\subsection{bla bla bla}
\lipsum[2-3]
\chapter{bla bla}
\lipsum[2-3]
\section{bla bla bla}
\lipsum[2-3]
\subsection{bla bla bla}
\lipsum[2-3]
\subsection{bla bla bla}
\lipsum[2-3]
\subsection{bla bla bla}
\lipsum[2-3]
% #############################################################################
\clearpage
\listofappendix
\begin{appendices}
\section{questions}
\lipsum[1]
\section{answers}
\lipsum[1]
\end{appendices}
\end{document}
In this example I expect the page number for the LoA to be 4
, not 5
(assuming you use the parameter a4paper
for the report
class). It seems to me that LaTeX is always selecting the page for the first chapter of the appendix. How can I fix that?