21

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}  
17
  • 2
    so what kind of latex questions are valid then?
    – chriss
    Apr 4, 2009 at 16:12
  • 9
    @Johannes: I disagree. SO has consistently treated LaTeX problems as programming related. This is appropriate, because TeX and LaTeX are Turing complete languages. Apr 4, 2009 at 16:12
  • 2
    Agree, building LaTeX macros is programming.
    – Richard
    Apr 4, 2009 at 16:17
  • 2
    We have consistently answered LaTeX questions here, I find it to be a great resource. Can we get a few more people to reopen ?
    – Uri
    Apr 4, 2009 at 17:01
  • 2
    I agree we should continue to allow TeX/LaTeX questions here :) Apr 5, 2009 at 0:12

5 Answers 5

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}
4
  • How do I use that hack with \asbuk using fontspec? I need russian appendix numberings.
    – Adobe
    Apr 24, 2013 at 8:17
  • Adobe, I can't paste code here. I've posted my solution in the separate answer. Hope this will help you. May 4, 2013 at 9: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, 2016 at 14:52
  • Just replace all section with chapter if your appendix is by chapters
    – Miguel
    Dec 22, 2016 at 19:47
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.

11

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.

2
  • 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: stackoverflow.com/questions/2661774/…
    – mlt
    Nov 26, 2012 at 19:37
  • @mlt It's been so long that I can't recall. Nov 26, 2012 at 19:58
1

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.

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

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.