Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How do I create a table of contents that looks like:

Chater 1 Name

   1.1 section
   1.2 section 
   Appendix A
   Appendix B

Chapter 2 Name

   2.1 section
   2.2 section 
   Appendix A
   Appendix B

Specifically, I am wondering how to create appendix entries for each chapter, instead of the whole document. I am also wondering how to add the terms "Appendix" and "Chapter" as shown above.

share|improve this question
2  
Welcome to TeX.SE! It would help if you provided a bit more information on (i) the document class you're currently using and (ii) all formatting-relevant issues you need to satisfy (such as font size, bold and/or italic font usage, and the width of the text block). Separately, do you want the chapter-specific appendices to be "numbered" as A, B, etc or as 1.A, 1.B, 2.A, 2.B, etc? –  Mico Mar 5 '12 at 22:15
    
I am using the report documentclass. I am not too picky on the font size or numbering, mainly just the indendation. –  richtera Mar 5 '12 at 22:23
    
A follow-up question: Do you just want to display "Appendix A", etc, or do the appendix sections have their separate header strings? –  Mico Mar 5 '12 at 23:02
    
I would like them to have separate header stings--whatever the name of the chapter/section/subsection/etc. Thanks for following up. –  richtera Mar 6 '12 at 2:07
    
The subappendices environment in the appedix allows appexices within a chapter but not the formatting I was hoping for. –  richtera Mar 6 '12 at 2:14
add comment

2 Answers

up vote 4 down vote accepted

I believe the following code does most of what you're asking for. Be sure to use the macro \appsecnums in each chapter at the start of the appendix area.

The major (but hopefully not disqualifying) limitation of this code is that you can't have subsections (or subsubsections) inside appendix-type sections because the numbering would be incorrect. (Specifically, you'd have an unwanted "Appendix" string prefixed to the sub(sub)section's number.) When cross-referencing an appendix section labelled, say, as \label{sec:newapp}, be sure to write \ref{sec:newapp} rather than Appendix~\ref{sec:newapp}.

\documentclass{report}
\usepackage{tocloft} % the tocloft package lets you redefine the Table of Contents (ToC)
  \renewcommand\cftchappresnum{Chapter } % prefix "Chapter " to chapter number in ToC
  \cftsetindents{chapter}{0em}{8em}      % set amount of indenting
  \cftsetindents{section}{2em}{6em}
% Macros to redefine numbering of appendix sections (and to
%   reset numbering when not in per-chapter area appendix)
\newcommand\normalsecnums{%
    \renewcommand\thesection{\thechapter.\arabic{section}}}
\let\origchapter\chapter
\renewcommand{\chapter}[1]{\normalsecnums
    \origchapter{#1}}
\newcommand\appsecnums{%   % execute this command before entering appendix area
    \setcounter{section}{0}
    \renewcommand\thesection{\appendixname~\Alph{section}}}

\begin{document}
\tableofcontents
\chapter{First Chapter}
\section{Section Title}
\section{Section Title}
\appsecnums  % switch to "appendix-style" numbering of sections
\section{Some additional stuff}
\section{Still more additional stuff}

\chapter{Another Chapter}
\section{Section Title}
\section{Section Title}
\appsecnums  % switch to "appendix-style" numbering of sections
\section{Some additional stuff}
\section{Still more additional stuff}
\end{document}

enter image description here

Addendum. In the MWE above, to change the numbering style of the appendices from A, B, ... to <chapnum>.A, <chapnum>.B, ..., you'd need to modify the instruction

\renewcommand\thesection{\appendixname~\Alph{section}}}

as follows:

\renewcommand\thesection{\appendixname~\thechapter.\Alph{section}}}

You'll probably also need to increase the indent amount, in the third argument of cftsetindents commands, by a bit, say by 0.75em:

\cftsetindents{chapter}{0em}{8.75em}  
\cftsetindents{section}{2em}{6.75em}
share|improve this answer
    
This is great. You see this format in books quite often. What about if someone wanted to make it look like: Chapter 1 First Chapter 1.1 Section Title 1.2 Section Title Appendix 1.A Appendix Title 1.B Appendix Title –  richtera Mar 6 '12 at 13:55
    
@AlexRichter: Please see the addendum to my answer. –  Mico Mar 6 '12 at 14:53
    
In my response, I wasn't able to show formatting. Perhaps you could take a look at the other question I posted to see better what I mean. Thanks for all your help! –  richtera Mar 6 '12 at 15:16
    
@AlexRichter: I've noticed your new question in the meantime and have attempted to provide a more directed answer there. –  Mico Mar 6 '12 at 16:02
add comment

You can do the following. It uses \section* to place the Appendix. Notice that you have to use special new command \Appx for that. Package amsmath is loaded to provide the command \numberwithin.

EDIT: Modified the command \l@chapter that is responsible for printing the chapter entries in ToC so that they include the chapter name.

\documentclass{report}

\usepackage{amsmath}
\makeatletter

% Per-section appendicies
\newcounter{Appx}
\numberwithin{Appx}{chapter}
\def\@Appx[#1]#2{
\refstepcounter{Appx}
\section*{%
\addcontentsline{toc}{section}{\appendixname\ \Alph{Appx}\quad#1}%
\appendixname\ \Alph{Appx}\quad#2}
}
\def\@@Appx#1{\@Appx[#1]{#1}}
\def\Appx{\@ifnextchar[\@Appx\@@Appx}

% "Chapter" prefix in ToC
\let\@@l@chapter\l@chapter
\def\l@chapter#1{\@@l@chapter{\chaptername\ #1}}

\makeatother

\begin{document}

\tableofcontents

\chapter{CHP}
\section{SEC}
\section{SECC}
\Appx{APX}
\Appx{APXX}

\chapter{CHP}
\section{SEC}
\section{SECC}
\Appx{APX}
\Appx{APXX}

\end{document}
share|improve this answer
1  
You could use the etoolbox package to patch the \@chapter command to include the word "Chapter" in the ToC (another option would be to use the tocloft package). –  Gonzalo Medina Mar 6 '12 at 2:24
    
I have done in another way, I forgot that original poster asked for that as well. –  tohecz Mar 7 '12 at 10:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.