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.

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}
share|improve this question
    
Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. In your case it is important to know the document class you used. –  Kurt Mar 21 '13 at 3:14
    
As @Kurt has also suggested, please consider editing your posting to supply an MWE that indicates the document class you use (book? report? something else?) and any packages you may load that influence either the appearance of the Table of Contents or the formatting of appendix material. –  Mico Mar 21 '13 at 5:19
add comment

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
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
show 8 more comments

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.