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.

Using the report document class, how can I create a table of contents that looks like:

Chapter 1: Title

1.1  Title
1.2  Title

Appendices 
1.A
1.B

Chapter 2: Title

2.1  Title
2.2  Title

Appendices 
2.A
2.B
share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

Below there's one possible solution; the code includes 1) A redefinition of \@chapter (as defined in report.cls) to include the word "Chapter" in the chapter entries of the ToC. 2) Two newly defined commands: \bappendix and \eappendix; the former starts a group, adds "Appendices" to the ToC and redefines \section (as defined in report.cls) to modify the section counter as requested; the latter simply ends the group:

\documentclass{report}

\newcounter{appendix}[chapter]

\makeatletter
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         \addcontentsline{toc}{chapter}%
                                   {\@chapapp~\thechapter: #1}%
                    \else
                      \addcontentsline{toc}{chapter}{#1}%
                    \fi
                    \chaptermark{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{#2}]%
                    \else
                      \@makechapterhead{#2}%
                      \@afterheading
                    \fi}

\newcommand\bappendix{%
  \addtocontents{toc}{\protect\addvspace{10pt}Appendices}
  \begingroup
  \renewcommand\section{\stepcounter{appendix}%
    \renewcommand\thesection{\thechapter.\Alph{appendix}}
    \@startsection {section}{1}{\z@}%
      {-3.5ex \@plus -1ex \@minus -.2ex}%
      {2.3ex \@plus.2ex}%
      {\normalfont\Large\bfseries}}}
\makeatother
\newcommand\eappendix{\endgroup}

\begin{document}
\tableofcontents

\chapter{First Chapter}
\section{Section One One}
\section{Section One Two}

\bappendix
\section{Appendix One A}
\section{Appendix One B}
\eappendix

\chapter{Second Chapter}
\section{Section Two One}
\section{Section Two Two}

\bappendix
\section{Appendix Two A}
\section{Appendix Two B}
\eappendix

\end{document}

enter image description here

Here's the same approach, but using the etoolbox package to simplify the code:

\documentclass{report}
\usepackage{etoolbox}

\newcounter{appendix}[chapter]

\makeatletter
\patchcmd{\@chapter}{\protect\numberline{\thechapter}#1}
{\@chapapp~\thechapter: #1}{}{}
\newcommand\bappendix{%
  \addtocontents{toc}{\protect\addvspace{10pt}Appendices}
  \begingroup
  \pretocmd{\section}{\stepcounter{appendix}%
    \renewcommand\thesection{\thechapter.\Alph{appendix}}}{}{}}
\makeatother
\newcommand\eappendix{\endgroup}

\begin{document}
\tableofcontents

\chapter{First Chapter}
\section{Section One One}
\section{Section One Two}

\bappendix
\section{Appendix One A}
\section{Appendix One B}
\eappendix

\chapter{Second Chapter}
\section{Section Two One}
\section{Section Two Two}

\bappendix
\section{Appendix Two A}
\section{Appendix Two B}
\eappendix

\end{document}

Here's now a much more simple solution using the subappendices environment from the appendix package; the subappendices environment was slightly modified (to add some vertical space before "Appendices" in the ToC) using the etoolbox package; this package was also used to add "Chapter" before the chapter entries in the ToC:

\documentclass{report}
\usepackage{appendix}
\usepackage{etoolbox}

\AtBeginEnvironment{subappendices}{%
  \addtocontents{toc}{\protect\addvspace{10pt}Appendices}
}
\makeatletter
\patchcmd{\@chapter}{\protect\numberline{\thechapter}#1}
{\@chapapp~\thechapter: #1}{}{}
\makeatother


\begin{document}
\tableofcontents

\chapter{First Chapter}
\section{Section One One}
\section{Section One Two}

\begin{subappendices}
\section{Appendix One A}
\section{Appendix One B}
\end{subappendices}

\chapter{Second Chapter}
\section{Section Two One}
\section{Section Two Two}

\begin{subappendices}
\section{Appendix Two A}
\section{Appendix Two B}
\end{subappendices}

\end{document}
share|improve this answer
    
Awesome, thanks. Is it possible to obtain the same formatting with the tocloft package? –  richtera Mar 6 '12 at 17:37
    
@AlexRichter: yes; Mico's answer, for example, uses tocloft. Do you want me to produce a separate example using tocloft? –  Gonzalo Medina Mar 6 '12 at 17:57
    
I wonder if it is possible to combine the appendix package (using begin and end subapendices) and either the etoolbox or tocloft packages to simplify the code. –  richtera Mar 6 '12 at 18:03
    
@AlexRichter: yes, it's possible. See the third example in my updated answer. –  Gonzalo Medina Mar 6 '12 at 18:35
    
When I inserted the code to the last example, it didn't add the "Chapter " text in front of each chapter entry in the TOC. Also, it didn't indent the appendix tag. –  richtera Mar 6 '12 at 21:37
show 8 more comments

A solution to your question is provided in the following MWE. The MWE also lets you specify when there's only one appendix in a chapter (having the subtitle read "Appendices" when there's only one appendix may look funny).

\documentclass{report}
\usepackage{tocloft,ifthen}
    \renewcommand\cftchappresnum{Chapter } 
    \cftsetindents{chapter}{0em}{6em}
    \cftsetindents{section}{0em}{2.25em}
    \cftsetindents{subsection}{2.25em}{3em}

\makeatletter
%% For source of "@seccntformat" command, see book "The LaTeX Companion"
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
   {\csname the#1\endcsname\ \ }%  default
   {\csname #1@cntformat\endcsname}}%    enable individual control
%% Individual control: '\section@cntformat'
\newcommand{\section@cntformat}{\thechapter.\thesection\ \ }

% Macros to redefine numbering of appendix sections
\newcommand{\appname}{} % dummy definition 
\newcommand{\appsecnumbering}[1][0]{%
    \ifthenelse{#1=1}{\renewcommand\appname{Appendix}}
                     {\renewcommand\appname{Appendices}}
    \setcounter{section}{0}
    \renewcommand\thesection{\thechapter.\Alph{section}}
    \renewcommand{\section@cntformat}{\appendixname~\thesection\ \ }
    \addtocontents{toc}{\medskip\protect{\mdseries\appname\par}}}
\newcommand\normalsecnumbering{%
    \renewcommand{\thesection}{\thechapter.\arabic{section}}
    \renewcommand{\section@cntformat}{\thesection\ \ }}
\let\origchapter\chapter
\renewcommand\chapter{\normalsecnumbering % first, reset numbering style
    \origchapter} % second, execute the original \chapter command
\makeatother

\begin{document}
\tableofcontents
\chapter{First Chapter}
\section{First Section Title} \label{sec:11}
\section{Second Section Title} \label{sec:12}
\appsecnumbering  
\section{Some additional stuff}       \label{sec:1a}
\section{Still more additional stuff} \label{sec:1b}
A couple of cross-references: 
  Section~\ref{sec:11} and Appendix~\ref{sec:1b}.

\chapter{Another Chapter}
\section{First Section Title}
\section{Second Section Title}
\appsecnumbering[1]  % specify "1" to request singular form of noun "Appendix"
\section{Some singular additional stuff}

\chapter{Yet Another Chapter}
\section{First Section Title}
\section{Second Section Title}
\appsecnumbering[7] % any number other than "1" generates plural form of noun
\section{Some additional stuff}
\section{Still more additional stuff}
\end{document}

enter image description here

Note the appearance of the first full page and, in particular, the cross-references to regular and appendix-area sections.

enter image description here

Finally, if you want the start of the section headers to line up vertically with the headers of the chapters, you should change the line

\cftsetindents{section}{0em}{2.25em}

to:

\cftsetindents{section}{0em}{6em}
share|improve this answer
    
I wonder if it would be simplier to use the appendix package to number the subappendices? –  richtera Mar 6 '12 at 17:43
    
With this solution, the optional argument of \chapter will produce undesired results. –  Gonzalo Medina Mar 6 '12 at 17:55
    
@GonzaloMedina -- thanks for pointing out this mistake; I've fixed it in the newly-saved version. (I've also generalized the approach to let the user indicate when there's only one appendix in a chapter.) –  Mico Mar 6 '12 at 18:16
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.