I am trying to print a List of Appendices (LoA) for my thesis, separate from the Table of Contents (ToC).
I wish for my ToC to look like this, with depth up to subsections (2?):
CONTENTS
CHAPTER
I. Introduction......1
1.1 Section title...1
1.1.1 Subsection...1
Appendices ..... 2
and for an LoA on a new page, with depth 0, thus:
APPENDICES
APPENDIX
A. Proof of Theorem 1...1
B. Proof of Theorem 2...1
I am trying to achieve this using the report
class, in a way that allows me to type appendices using the hierarchy that I obtain from the chapter
, section
commands. This is as opposed to defining a custom myappendix
command into which I insert my appendix content. (I realize that I only need the titles from the appendix chapters for the LoA, but I'd like for the appendix content to have such structure.)
For instance, this approach would solve my problem:
\chapter{Introduction}
\section{Section title}
\subsection{Subsection}
% \begin{appendices} is also acceptable
\appendix
% Some settings are changed now
\chapter{Proof of Theorem 1}
\chapter{Proof of Theorem 2}
% \end{appendices} if environment is begun
whereas the following approach would not:
\chapter{Introduction}
\section{Section title}
\subsection{Subsection}
\myappendix{Proof of Theorem 1}
\myappendix{Proof of Theorem 2}
I realize several questions have been asked regarding this before, but none of them quite solved my problem. Notably, this solution defines a custom appendix command; this solution defines two custom commands to maintain some hierarchy, but I will have to do more work to handle the inclusion of another layer (subsection) into the appendix.
This reply is the closest to what I want: it does give me a separate LoA, but it also adds appendices to ToC and I can't quite figure out how to suppress the entires in ToC. The moment I use
\addcontentsline{toc}{\setcounter{tocdepth}{-1}}
the line
\xpatchcmd{\@chapter}{\addcontentsline{toc}}{\addcontentsline{toa}}{}{}%
fails because I am not adding anything to the ToC anymore.
My approach: Since I was using titlesec
and tocloft
packages anyway, I tried to do the following:
- Stop ToC once
appendix
command is issued - Start a new counter for appendices using
tocloft
- Using the
<after-code>
option oftitlesec
, add contents line after everychapter
.
My MWE
\documentclass[a4paper]{report}
\usepackage{lipsum} % for arbitrary text
\usepackage{tocloft,etoolbox,titlesec}
\newcommand{\listappendixname}{List of Appendices}
\newlistof{appendix}{apc}{\listappendixname}
\makeatletter
\g@addto@macro{\appendix}{
\clearpage
\addcontentsline{toc}{chapter}{Appendices}
\addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}
\titleformat
{\chapter}
[display]
{\huge\bfseries\filcenter}
{\Large \MakeUppercase{\@chapapp} \thechapter}
{1.5ex}{}
{\refstepcounter{appendix} \addcontentsline{apc}{appendix}{\protect{\@chapapp \thechapter}}}
}
\makeatother
\title{Title}
\author{Author}
\begin{document}
\maketitle
\tableofcontents
\clearpage
\listofappendix
\chapter{Introduction}
\lipsum[1]
\section{Section}
\lipsum[2]
\subsection{Subsection}
\lipsum[3]
\appendix
\chapter{Proof of Theorem One}
\lipsum[4]
\chapter{Proof of Theorem Two}
\lipsum[5]
\end{document}
produces the following LoA:
List of Appendices
Appendix...... 5
It doesn't get the Appendix title or number, and fails after the first one.
Could you please help me obtain a separate LoA in a way that I can still use LaTeX's chapter
, section
, … hierarchy? (I am okay with using different packages, the book
class, or any approach other than mine.)
Best Answer
The fiddling with
\addcontentsline
can be tricky, due its asynchronous writing via\@writefile
, taking place in the.aux
file.I used another approach, letting all structuring commands do what they should, writing to
toc
, however, thetoc
file handle is copied to beapc
in the.aux
file and reestablishing it later after the end of theappendices
environment.