5

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:

  1. Stop ToC once appendix command is issued
  2. Start a new counter for appendices using tocloft
  3. Using the <after-code> option of titlesec, add contents line after every chapter.

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.)

  • Untested yet, but titlesec and tocloft in combination is not well! – user31729 Dec 28 '16 at 8:58
  • I was willing to forego either (or both) in favor of a "nice" solution. In any case your solution below, which I accepted, addresses the heart of my problem: stop writing to the .toc aux file, and write to a different aux file while in appendices :) – rjtjs Dec 28 '16 at 13:25
  • In fact, you still write to the .aux file, but this will use the other toc related file – user31729 Dec 28 '16 at 16:11
5

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, the toc file handle is copied to be apc in the .aux file and reestablishing it later after the end of the appendices environment.

\documentclass[a4paper]{report}
\usepackage{lipsum} % for arbitrary text

\usepackage{etoolbox}
\usepackage{appendix}

\usepackage{tocloft,titlesec}
\newcommand{\listappendixname}{List of Appendices}
\newlistof{appendix}{apc}{\listappendixname}


\makeatletter


\AtBeginEnvironment{appendices}{%
  \clearpage
  \addcontentsline{toc}{chapter}{Appendices}
  \write\@auxout{%
    \string\let\string\latex@tf@toc\string\tf@toc% Store the original `\tf@toc` file handle
    \string\let\string\tf@toc\string\tf@apc% 
  }% Naughty trick
  \titleformat 
  {\chapter} 
  [display]
  {\huge\bfseries\filcenter} 
  {\Large \MakeUppercase{\@chapapp} \thechapter} 
  {1.5ex}{}
  {}
}

\AtEndEnvironment{appendices}{%
  \write\@auxout{%
    \string\let\string\tf@toc\string\latex@tf@toc% 
  }% Naughty trick, restoring the old `\tf@toc` number, to be able to write stuff to the real `.toc` again.
}

\makeatother

\title{Title}
\author{Author}

\begin{document}
\maketitle
\tableofcontents
\clearpage
\listofappendix

\chapter{Introduction}
\lipsum[1]
\section{Section}
\lipsum[2]
\subsection{Subsection}
\lipsum[3]

\begin{appendices}

\chapter{Proof of Theorem One}
\lipsum[4]
\chapter{Proof of Theorem Two}
\lipsum[5]
\end{appendices}

\chapter{Foo stuff}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.