[Tex/LaTex] List of appendices without chapter titles

appendices

This was somewhat similar to what I am looking for, but not exactly: How to make appendices behave like sections in ToC

I would like for my appendices to do the following:

  1. One chapter in the ToC for all appendices
  2. Appendices behave like sections and are labeled A, B, C, etc.
  3. \ref command inserts the appendix label, not a number
  4. Appendices have their name and label in the page header, no need for chapter, section or other headings.

The resulting ToC would look like this:

Some Chapter 1
    Some section 1
Some Chapter 2
    Some section 2
Appendices
    Appendix A - Some name
    Appendix B - Some name 2
    etc.

Currently I can only reproduce this behaviour by adding the content lines manually, using phantom sections to get the page numbers correct and manual naming for the ToC lines and headers. This leads to a problem that my labels and references use numbers instead of the letters defined for the counter. With the command below I would have to define the header for each appendix manually.

\refstepcounter{AppCounter}
\phantomsection\addcontentsline{toc}{section}{Appendix \Alph{AppCounter} - Some name}
\includegraphics ...
\label{app:appA}

The other problem with using appendix package is that I could not figure out how to have appendix labels without chapters/sections. And chapter/section commands add the text to the page, which is something I have no use for.

Best Answer

Here is an idea:

\newcommand{\startappendix}{%
\pagebreak%
\addcontentsline{toc}{chapter}{Appendices}%
\fancyhead[L]{{\bfseries Appendices}}%
\setcounter{section}{0}%
\renewcommand{\thesection}{\Alph{section}}%
}

\newenvironment{newappendix}[2]%
{\gdef\headername{#1}%
\phantomsection%
\refstepcounter{section}%
\addcontentsline{toc}{section}{Appendix \thesection~- #1}%
\label{app:#2}}
{\fancyhead[R]{Appendix \thesection~- \headername}
\newpage}

Add these two commands in your preamble. The first one should be used when you want to start your appendices. The second one is to use each time you want to change the name of the current appendix. The first argument is the name of the appendix and the second is what will be added the the app: prefix for the label. You can then call the appendix with the \ref{app:<your second argument>} wherever you want in your code.

Example

Here is a short example of the code and its output

\documentclass{report}
\usepackage[demo]{graphicx}
\usepackage{hyperref}
\usepackage{fancyhdr}
\pagestyle{fancy}

\newcommand{\startappendix}{%
\pagebreak%
\addcontentsline{toc}{chapter}{Appendices}%
\fancyhead[L]{{\bfseries Appendices}}%
\setcounter{section}{0}%
\renewcommand{\thesection}{\Alph{section}}%
}

\newenvironment{newappendix}[2]%
{\gdef\headername{#1}%
\phantomsection%
\refstepcounter{section}%
\addcontentsline{toc}{section}{Appendix \thesection~- #1}%
\label{app:#2}}
{\fancyhead[R]{Appendix \thesection~- \headername}
\newpage}

\begin{document}
\tableofcontents

\chapter{One}
\section{One-one}

\startappendix

\begin{newappendix}{First}{1}
\includegraphics[width=12cm,height=15cm]{test}
\end{newappendix}

\begin{newappendix}{Second}{2}
\includegraphics[width=12cm,height=15cm]{test}
\end{newappendix}

\end{document}

Table of contents

First appendix

EDIT Another way to go I found thanks to egreg for the second command:

\fancyhead[R]{Appendix \rightmark}

\newcommand{\newappendix}[2]{%
  \clearpage%
  \phantomsection%
  \refstepcounter{section}%
  \addcontentsline{toc}{section}{Appendix \thesection~- #1}%
  \markright{\thesection \ -- #1}%
  \label{app:#2}
}