[OS X TeX] Appendixprefix in the toc

Alan Munn amunn at msu.edu
Sat Apr 11 19:28:09 EDT 2009


At 7:35 PM +0200 4/11/09, Gewitterbukk wrote:
>Howdy!
>
>Is there a smart way to use \chapter{} in the appendix so that the 
>prefix "Apendix" is used in the table of contents? What and where do 
>I have to change something?
>
>
>Output example:
>
>1 Section
>2 Section
>...
>
>Appendix A: ...
>Appendix B: ...
>...

This is not so simple.

Use the tocloft package plus a redefinition of the \appendix command. 
Here's a sample document that does what you want.

Alan


\documentclass[chapterprefix=false,appendixprefix=true]{scrreprt}
\usepackage{tocloft}

\newlength{\tocnumwidth}
\newlength{\temp}
\setlength{\tocnumwidth}{\cftchapnumwidth} % store the starting width 
of the TOC chapter number

%\renewcommand{\cftchappresnum}{\chaptername\space}
%\settowidth{\temp}{\bfseries\cftchappresnum\cftchapaftersnum} % 
calculate the extra space
%\addtolength{\cftchapnumwidth}{\temp} % add the extra space
% uncomment the 3 lines above  if you want the word Chapter to 
precede the number in the TOC

\renewcommand*{\cftchapaftersnum}{\space}


\DeclareRobustCommand{\changetoapp}{%
    \renewcommand*{\cftchappresnum}{\appendixname\space}%
    \settowidth{\temp}{\bfseries\cftchappresnum\cftchapaftersnum}
% comment the line above out if you include Chapter before the number 
in the TOC want the Chapter and Appendix TOC entries to line up.
    \setlength\cftchapnumwidth{\tocnumwidth}
    \addtolength{\cftchapnumwidth}{\temp}}
\let\oldappendix\appendix
\renewcommand*{\appendix}{\oldappendix \addtocontents{toc}{\changetoapp}}

\begin{document}

\tableofcontents
\chapter{First}


\chapter{Second}

\appendix

\chapter{}

\end{document}




-- 
Alan Munn						amunn at msu.edu
Department of Linguistics
and Germanic, Slavic, Asian and African Languages		Tel. 
	517-355-7491
Michigan State University, East Lansing MI 48824 USA	Fax	517-432-2736



More information about the MacOSX-TeX mailing list