Tell me more ×
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 have

\chapter{My first chapter}
\chapter{My second chapter}
\phantomsection
\addcontentsline{toc}{chapter}{Appendixes}
\appendix
\makeatletter
\def\toclevel@chapter{1}\def\toclevel@section{2}
\makeatother
\chapter{My first appendix}
\chapter{My second appendix}

So my hyperref ToC look like:

- My first chapter
- My second chapter
+ Appendixes
  - My first appendix
  - My second appendix

But my \tableofcontents still look like:

1 My first chapter
2 My second chapter
Appendixes
A My first appendix
B My second appendix

And what I want is that the appendixes look like sections:

1 My first chapter
2 My second chapter
Appendixes
  A My first appendix
  B My second appendix

I can figure out, that there is a really small trick to do the job... but I can't find it...

share|improve this question
how about \addcontentsline{toc}{section}{Appendixes}? ` – cmhughes Jun 16 '12 at 2:00
Which document class are you using? – Gonzalo Medina Jun 16 '12 at 3:22

3 Answers

up vote 7 down vote accepted

set \l@chapter to l@section

\documentclass{book}
\usepackage{hyperref}

\begin{document}

\tableofcontents
\chapter{My first chapter}
\chapter{My second chapter}

\phantomsection
\addcontentsline{toc}{chapter}{Appendixes}
\appendix
\def\toclevel@chapter{1}\def\toclevel@section{2}
\addtocontents{toc}{\string\let\string\l@chapter\string
\l@section}
\chapter{My first appendix}
\chapter{My second appendix}

\end{document}
share|improve this answer

You can redefine \@chapter (as implemented in the document class used) to use \addcontentsline{toc}{section}{...} instead of \addcontentsline{toc}{chapter}{...}. Here's an example of such redefinition for book.cls:

\documentclass{book}
\usepackage{hyperref}

\begin{document}

\tableofcontents
\chapter{My first chapter}
\chapter{My second chapter}

\phantomsection
\addcontentsline{toc}{chapter}{Appendixes}
\appendix
\makeatletter
\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

\chapter{My first appendix}
\chapter{My second appendix}

\end{document}

Here's the resulting ToC:

enter image description here

and the bookmarks pabel:

enter image description here

share|improve this answer
I want it class independant (like Herbert's answer) – Kyle_the_hacker Jun 18 '12 at 0:04

The following is a condensed version of Gonzalo's answer, using regexpatch. It patches the first appearance of {toc}{chapter} in \Hy@org@chapter with {toc}{section}, yielding the same result:

\documentclass{book}
\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\usepackage{regexpatch}% http://ctan.org/pkg/regexpatch

\begin{document}

\tableofcontents
\chapter{My first chapter}
\chapter{My second chapter}

\phantomsection
\addcontentsline{toc}{chapter}{Appendixes}
\appendix
\makeatletter
\xpatchcmd{\Hy@org@chapter}{{toc}{chapter}}{{toc}{section}}{}{}%
\makeatother

\chapter{My first appendix}
\chapter{My second appendix}

\end{document}
share|improve this answer

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.