4

I would like my appendices to appear in TOC at section level instead of at chapter level.

Like this:

    Appendices
        A  My appendix 1 . . . . . . .
        B  My appendix 2 . . . . . . .

I've tried with \settocdepth but it does not work.

My code:

    \documentclass[11pt,a4paper]{report}
    \usepackage[english]{babel}     % english language
    \usepackage[latin1]{inputenc}   % accents in source
    \usepackage[T1]{fontenc}        % accents in DVI
    \usepackage{color}              % add color to the text
    \definecolor{bluekeywords}{rgb}{0.13,0.13,1}
    \definecolor{greencomments}{rgb}{0,0.5,0}
    \definecolor{redstrings}{rgb}{0.9,0,0}

    \usepackage{graphicx}           % images in the document
    \usepackage{float}              % containers
    \usepackage{wrapfig}            % wrap text around figure

    \usepackage{vmargin}            % redefine the margins
    \setmarginsrb{2.5cm}{1.5cm}{2.5cm}{1cm}{0cm}{0cm}{0cm}{1cm}

    \usepackage[
    hyperindex=true, % add links in the index
    bookmarks=true,  % show bookmarks bar when displaying the document}{hyperref}
    ]{hyperref}
    \hypersetup{
    colorlinks=true, % colored links
    breaklinks=true, % allows return line in too long links
    urlcolor= blue,  % links color
    linkcolor= blue, % internal links color
    citecolor= blue, % green by defaut, color of citation links (bibliography)
    bookmarksopen=true,
    pdftitle={Cloud 3D Teapot},
    pdfauthor={Jos\'{e} L\'{o}pez C\'{i}vico},
    pdfsubject={Cloud Latency}
    }

    \usepackage{listings}
    \lstset{
    basicstyle=\footnotesize,       % code font size
    numbers=left,                   % place of numbers
    numberstyle=\normalsize,        % numbers font size
    numbersep=7pt,                  % distance between code and its numeration
    backgroundcolor=\color{white},  % background color
    }

    \lstdefinestyle{CSharp}{
      language=[Sharp]C,
      showspaces=false,
      showtabs=false,
      breaklines=true,
      showstringspaces=false,
      breakatwhitespace=true,
      escapeinside={(*@}{@*)},
      commentstyle=\color{greencomments},
      keywordstyle=\color{bluekeywords},
      stringstyle=\color{redstrings},
      basicstyle=\ttfamily
    }

    \lstdefinestyle{XMLc}{
      language=XML,
      showspaces=false,
      showtabs=false,
      breaklines=true,
      showstringspaces=false,
      breakatwhitespace=true,
      stringstyle=\color{bluekeywords},
      keywordstyle=\color{redstrings},
      morekeywords={name, connectionString, providerName},
      commentstyle=\color{greencomments},
      basicstyle=\ttfamily
    }

    \usepackage{titlepic}
    \usepackage{appendix}

    \usepackage{makeidx}
    \usepackage{lmodern}
    \usepackage{kpfonts}

    \begin{document}

    \tableofcontents
    \newpage

    \listoffigures
    \newpage

    \chapter{Test Chapter}
    \section{A Regular Section}

\appendix
\clearpage % or \cleardoublepage
\appendixpage
\addappheadtotoc
% code to show appendices at section level in TOC
\begin{appendices}
    \chapter{Installation requirements}
\chapter{Acronyms}
\end{appendices}

    \end{document}
0
3

Update: the document class used was report, so here's now the solution with the actual settings:

\documentclass[11pt,a4paper]{report}
\usepackage[english]{babel}     % english language
\usepackage[latin1]{inputenc}   % accents in source
\usepackage[T1]{fontenc}        % accents in DVI
\usepackage{color}              % add color to the text
\definecolor{bluekeywords}{rgb}{0.13,0.13,1}
\definecolor{greencomments}{rgb}{0,0.5,0}
\definecolor{redstrings}{rgb}{0.9,0,0}

\usepackage{graphicx}           % images in the document
\usepackage{float}              % containers
\usepackage{wrapfig}            % wrap text around figure

\usepackage{vmargin}            % redefine the margins
\setmarginsrb{2.5cm}{1.5cm}{2.5cm}{1cm}{0cm}{0cm}{0cm}{1cm}

\usepackage{listings}
\lstset{
    basicstyle=\footnotesize,       % code font size
    numbers=left,                   % place of numbers
    numberstyle=\normalsize,        % numbers font size
    numbersep=7pt,                  % distance between code and its numeration
    backgroundcolor=\color{white},  % background color
 }

\lstdefinestyle{CSharp}{
      language=[Sharp]C,
      showspaces=false,
      showtabs=false,
      breaklines=true,
      showstringspaces=false,
      breakatwhitespace=true,
      escapeinside={(*@}{@*)},
      commentstyle=\color{greencomments},
      keywordstyle=\color{bluekeywords},
      stringstyle=\color{redstrings},
      basicstyle=\ttfamily
}

\lstdefinestyle{XMLc}{
      language=XML,
      showspaces=false,
      showtabs=false,
      breaklines=true,
      showstringspaces=false,
      breakatwhitespace=true,
      stringstyle=\color{bluekeywords},
      keywordstyle=\color{redstrings},
      morekeywords={name, connectionString, providerName},
      commentstyle=\color{greencomments},
      basicstyle=\ttfamily
}

\usepackage{titlepic}
\usepackage{appendix}

\usepackage{makeidx}
\usepackage{lmodern}
\usepackage{kpfonts}

\usepackage[
    hyperindex=true, % add links in the index
    bookmarks=true,  % show bookmarks bar when displaying the document}{hyperref}
    ]{hyperref}
\hypersetup{
    colorlinks=true, % colored links
    breaklinks=true, % allows return line in too long links
    urlcolor= blue,  % links color
    linkcolor= blue, % internal links color
    citecolor= blue, % green by defaut, color of citation links (bibliography)
    bookmarksopen=true,
    pdftitle={Cloud 3D Teapot},
    pdfauthor={Jos\'{e} L\'{o}pez C\'{i}vico},
    pdfsubject={Cloud Latency}
}

\makeatletter
\newcommand\chapassect{%
\def\@chapter[##1]##2{\ifnum \c@secnumdepth >\m@ne
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         \addcontentsline{toc}{section}%
                                   {\protect\numberline{\thechapter}##1}%
                    \else
                      \addcontentsline{toc}{section}{##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}%
}
\makeatother

    \begin{document}

    \tableofcontents
    \newpage

    \listoffigures
    \newpage

    \chapter{Test Chapter}
    \section{A Regular Section}

\appendix
\clearpage % or \cleardoublepage
\appendixpage
\addappheadtotoc
% code to show appendices at section level in TOC
\chapassect
\begin{appendices}
\chapter{Installation requirements}
\chapter{Acronyms}
\end{appendices}

\end{document}

enter image description here

I moved the hyperref package and loaded it last (except some well documented exceptions this should always be done).

Here's one option; the appendix package was used to include "Appendices" in the ToC just before the appendices, and the titletoc package was used to change the way chapter entries are typeset in the ToC, inside the appendix environment:

\documentclass{book}
\usepackage{appendix}
\usepackage{titletoc}

\begin{document}

\tableofcontents
\chapter{Test Chapter}
\section{A Regular Section}

\begin{appendix}
\addappheadtotoc
\titlecontents{chapter}
  [3.8em]
  {}{\contentslabel{2.3em}}
  {\hspace*{-2.3em}}
  {\titlerule*[0.7em]{.}\contentspage}
\chapter{Test Appendix One}
\chapter{Test Appendix Two}
\end{appendix}

\end{document}

enter image description here

In the above solution I assumed that appendices will be build using \chapter, and only the entries in the ToC must be changed; if the intent is to use \section to typeset the appendices, then it's enough to use the subappendices environment from the appendix package, and to redefine \setthesection:

\documentclass{book}
\usepackage{appendix}

\renewcommand\setthesection{\Alph{section}} 

\begin{document}

\tableofcontents
\chapter{Test Chapter}
\section{A Regular Section}

\addappheadtotoc
\begin{subappendices}
\section{Test Appendix One}
\section{Test Appendix Two}
\end{subappendices}

\end{document}

enter image description here

Since, according to a comment, the hyperref package is being used, the titletoc solution won't be completely valid, since these two packages don't interact well; in this case, some extra work has to be done:

\documentclass{book}
\usepackage{appendix}
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}

\makeatletter
\newcommand\chapassect{%
\def\@chapter[##1]##2{\ifnum \c@secnumdepth >\m@ne
                       \if@mainmatter
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         \addcontentsline{toc}{section}%
                                   {\protect\numberline{\thechapter}##1}%
                       \else
                         \addcontentsline{toc}{section}{##1}%
                       \fi
                    \else
                      \addcontentsline{toc}{section}{##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}%
}
\makeatother

\begin{document}

\tableofcontents
\chapter{Test Chapter}
\section{A Regular Section}

\begin{appendix}
\addappheadtotoc
\chapassect
\chapter{Test Appendix One}
\chapter{Test Appendix Two}
\end{appendix}

\end{document}

enter image description here

The code above assumed the book document class; after a comment, it seems that this class is not used, but unfortunately the actual document class is not mentioned in the comment; however, given the error message obtained by the OP after trying to implement my last suggestion, my crystal ball tells me that the document class might be amsbook. In this case the necessary redefinition is even simpler:

\documentclass{amsbook}
\usepackage{appendix}
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}

\makeatletter
\def\@chapter[#1]#2{\refstepcounter{chapter}%
  \ifnum\c@secnumdepth<\z@ \let\@secnumber\@empty
  \else \let\@secnumber\thechapter \fi
  \typeout{\chaptername\space\@secnumber}%
  \def\@toclevel{0}%
  \ifx\chaptername\appendixname \@tocwriteb\tocappendix{section}{#2}%
  \else \@tocwriteb\tocchapter{chapter}{#2}\fi
  \chaptermark{#1}%
  \addtocontents{lof}{\protect\addvspace{10\p@}}%
  \addtocontents{lot}{\protect\addvspace{10\p@}}%
  \@makechapterhead{#2}\@afterheading}%
\makeatother

\begin{document}

\tableofcontents
\chapter{Test Chapter}
\section{A Regular Section}

\begin{appendix}
\addappheadtotoc
\chapter{Test Appendix One}
\chapter{Test Appendix Two}
\end{appendix}

\end{document}

enter image description here

13
  • Both of them work but I would prefer to use the first approach because of the use of chapter. If I use it, the A, B, etc. on TOC aren't in blue color (link) as the name of the appendix. And the dots don't finish where all the other dots. – jlcivico Mar 21 '13 at 19:58
  • @jlcivico yes, titletoc and hyperref don't play well together; please see my updated answer for a new solution compatible with the use of hyperref. – Gonzalo Medina Mar 21 '13 at 21:58
  • To which character does @ fit? Sorry for the silly question. – jlcivico Mar 21 '13 at 22:48
  • @jlcivico @ is a special character for internal macros; redefining such macros (containing the character) in a .tex file requires \makeatletter, \makeatother to perform a change in category codes. a detailed explanation can be found in the answer to tex.stackexchange.com/q/8351/3954. – Gonzalo Medina Mar 21 '13 at 23:39
  • If I try to use it the next error pops up: ! Undefined control sequence. \@chapter ...\c@secnumdepth >\m@ne \if@mainmatter \refstepcounter {chapter}\... – jlcivico Mar 22 '13 at 15:59

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.