Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make 'appendix' appear in toc in Latex?

Tags:

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}  
like image 744
chriss Avatar asked Apr 04 '09 16:04

chriss


1 Answers

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}
like image 65
Will Robertson Avatar answered Sep 18 '22 05:09

Will Robertson