22

How to make word 'appendix' appear in the table of contents? Right now toc looks like this:

1 ......  
2 ......  
.  
.  
A .....  
B ..... 

I would like it to be:

1 ......  
2 ......  
.  
.  
Appendix A .....  
Appendix B ..... 

My latex source file structure is like this:

\begin{document}  
\tableofcontents  
\include{...}  
\include{...}  
\appendix  
\include{...}  
\include{...}  
\end{document}  
endo.anaconda
  • 2,449
  • 4
  • 29
  • 55
chriss
  • 4,349
  • 8
  • 29
  • 36

5 Answers5

13

For my thesis, I did the following:

\appendix
\addcontentsline{toc}{section}{Appendix~\ref{app:scripts}: Training Scripts}
\section*{Sample Training Scripts}
\label{app:scripts}
Blah blah appendix content blah blah blah.

Explanation: I manually added a line to the TOC so I would have "Appendix X:..." show up in my TOC. Then I excluded the actual section command from the TOC by using an asterisk.

Clokman
  • 303
  • 2
  • 11
Andrew
  • 131
  • 1
  • 3
13

There's a couple of ways to solve this problem; unfortunately, I've only got a hack for you at this stage. One problem is that if we redefine the section number "A" to include the word "Appendix", it messes up the formatting of the table of contents. So instead, I've just defined a new sectioning command that prints the section without a number and inserts "Appendix X" manually.

Kind of ugly, but at least it works without having to change any markup :)

\documentclass{article}

\makeatletter
\newcommand\appendix@section[1]{%
  \refstepcounter{section}%
  \orig@section*{Appendix \@Alph\c@section: #1}%
  \addcontentsline{toc}{section}{Appendix \@Alph\c@section: #1}%
}
\let\orig@section\section
\g@addto@macro\appendix{\let\section\appendix@section}
\makeatother

\begin{document}

\tableofcontents

\section{goo}
\label{a} 
This is sec~\ref{a}

\section{har}
\label{b}
This is sec~\ref{b}

\appendix
\section{ji}
\label{c} 
This is app~\ref{c}
\subsection{me}
does this look right?

\end{document}
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Will Robertson
  • 62,540
  • 32
  • 99
  • 117
  • How do I use that hack with `\asbuk` using `fontspec`? I need russian appendix numberings. – Adobe Apr 24 '13 at 08:17
  • Adobe, I can't paste code here. I've posted my solution in the separate answer. Hope this will help you. – Stanislav Mamontov May 04 '13 at 09:57
  • Will, this works like magic! However, I get a strange side effect: the references (if you add them) are transformed into a new section Appndix B*. Any idea how to get rid of it? – Ufos Mar 11 '16 at 14:52
  • Just replace all `section` with `chapter` if your appendix is by chapters – Miguel Dec 22 '16 at 19:47
12

This is probably most easily achieved by using the appendix package, or the memoir class.

If you don't want to use a prepackaged solution, you'll have to hack the sectioning commands. When I needed to do this for my dissertation, I cloned the report class, and edited until I made the margins lady happy. What you're looking for is the definition of the \addcontentsline macro.

ochurlaud
  • 410
  • 5
  • 14
dmckee --- ex-moderator kitten
  • 98,632
  • 24
  • 142
  • 234
  • With *appendix* package, is there a way either not to use `[page]` option for *appendices* environment, or don't waste an entire page for just "Appendices" title? The problem is that when I skip `[page]` (or `\appendixpage`), I have TOC messed up, i.e. "Appendices" comes after "Appendix A". I guess this is relevant: http://stackoverflow.com/questions/2661774/problem-with-adding-appendix-in-latex – mlt Nov 26 '12 at 19:37
  • @mlt It's been so long that I can't recall. – dmckee --- ex-moderator kitten Nov 26 '12 at 19:58
2

The appendix package is really good and simple solution. My answer can be helpful for who wants to change chapters numbering style, for example, with using cyrillic alphabet or roman digits. The appendices numbering style is hardcoded in the \@resets@pp command (I looked in sources here http://hal.in2p3.fr/docs/00/31/90/21/TEX/appendix.sty). I solved it by simple redefining this command to my own. Just add this code into your preamble:

\makeatletter

    \renewcommand{\@resets@pp}{\par
        \@ppsavesec
        \stepcounter{@pps}
        \setcounter{section}{0}

        \if@chapter@pp
            \setcounter{chapter}{0}
            \renewcommand\@chapapp{\appendixname}
            \gdef\thechapter{\Asbuk{chapter}} % changed
        \else
            \setcounter{subsection}{0}
            \gdef\thechapter{\Asbuk{section}} % changed
        \fi

        \if@pphyper
            \if@chapter@pp
                \renewcommand{\theHchapter}{\theH@pps.\Asbuk{chapter}} % changed
            \else
                \renewcommand{\theHsection}{\theH@pps.\Asbuk{section}} % changed
            \fi

            \def\Hy@chapapp{\appendixname}%
        \fi
    \restoreapp
}

\makeatother

As a result,

Appendix A
Appendix B
Appendix C
...

will change to

Appendix A
Appendix Б
Appendix В
... etc

I'm not a latex expert, and I can't guarantee this code won't break something else.

Stanislav Mamontov
  • 1,734
  • 15
  • 21
0

Based on @Will Robertson's answer, the code below defines the same thing but for chapter and also fixes the fact that chapter* does not add to the header when using the fancyhdr package.

With this in the preable all issues are resolved.

\makeatletter
\newcommand\appendix@chapter[1]{%
    \refstepcounter{chapter}%
    \def\app@ct{Appendix \@Alph\c@chapter: #1}
    \orig@chapter*{\app@ct}%
    \markboth{\MakeUppercase{\app@ct}}{\MakeUppercase{\app@ct}}
    \addcontentsline{toc}{chapter}{\app@ct}%
}
\let\orig@chapter\chapter
\g@addto@macro\appendix{\let\chapter\appendix@chapter}
\makeatother
Miguel
  • 1,293
  • 1
  • 13
  • 30