11

I had a problem as I wanted to make my appendices look like sections.

I already found a solution to do this for the table of contents by using this code just before the \chapter command in the appendix environment :

\makeatletter
\addtocontents{toc}{\let\protect\l@chapter\protect\l@section}
\makeatother

Now, I would like to make the bookmarks "realize" it. When I open the PDF file the Appendices appears at a chapter level, but the title of the appendix appears at chapter level too.

All the bookmarks I have come from the hyperref package, so I guess I can't use the bookmark package to find a solution.

Is there any way to make it look like a section of the chapter Appendices in the bookmarks?

Here is the code I use in my LaTeX program:

\begin{appendices}
 \makeatletter
 \addtocontents{toc}{\let\protect\l@chapter\protect\l@section}
 \makeatother
 \chapter{Appendix1}
 \chapter{Appendix2}
 ...
 \end{appendices}

I already tried to use the \section function instead of \chapter, but it doesn't seem to work.

2 Answers 2

7

Method via \bookmarksetupnext

With package bookmark the following is possible:

\bookmarksetupnext{level=-1}
\addappheadtotoc

overwrites the bookmark setting of "Appendices" and moves it a level higher to part level. Then the appendix chapters become children to the "part" appendices.

\documentclass{report}
\usepackage{appendix}
\usepackage{hyperref}
\usepackage{bookmark}
\begin{document}
  \tableofcontents
  \chapter{A chapter}
  \section{A section}
  \chapter{Another chapter}
  \section{A section}
  \begin{appendices}
    \bookmarksetupnext{level=-1}
    \addappheadtotoc
    \makeatletter
    \addtocontents{toc}{\let\protect\l@chapter\protect\l@section}
    \makeatother
    \chapter{Appendix1}
    \chapter{Appendix2}
     ...
  \end{appendices}
\end{document}

The example is based on the example in Werner's answer.

Method via \toclevel@<section>

Package hyperref configures the bookmark levels in macros \toclevel@chapter, \toclevel@section:

...
\def\toclevel@chapter{0}
\def\toclevel@section{1}
\def\toclevel@subsection{2}
\def\toclevel@subsubsection{3}
\def\toclevel@paragraph{4}
\def\toclevel@subparagraph{5}
...

These macros can be redefined:

\begin{appendices}
  \makeatletter
  \addtocontents{toc}{\let\protect\l@chapter\protect\l@section}
  \def\toclevel@chapter{1}
  \def\toclevel@section{2}
  \def\toclevel@subsection{3}
  % ... (add deeper levels if needed)
  \makeatother
  \chapter{Appendix1}
  \chapter{Appendix2}
  ...
\end{appendices}

Remark: You can use package bookmark together with hyperref getting faster updated bookmarks and more features.

2
  • For me just putting \bookmarksetupnext{level=-1} above \begin{appendices} seems to work fine
    – SWdV
    Jun 22, 2020 at 20:14
  • Actually; apparently what I said does not affect the TOC, only the bookmarks
    – SWdV
    Jun 26, 2020 at 15:47
6

Perhaps you're after something like this:

enter image description here

\documentclass{report}
\usepackage{appendix,bookmark,xpatch}% http://ctan.org/pkg/{appendix,bookmark,xpatch}
\begin{document}
\tableofcontents
\chapter{A chapter}
\section{A section}
\chapter{Another chapter}
\section{A section}
\begin{appendices}
\makeatletter
\addappheadtotoc
\addtocontents{toc}{\let\protect\l@chapter\protect\l@section}
% \xpatchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\xpatchcmd{\Hy@org@chapter}{{toc}{chapter}}{{toc}{section}}{}{}%
\xpatchcmd{\Hy@org@chapter}{{toc}{chapter}}{{toc}{section}}{}{}%
\makeatother
\chapter{Appendix1}
\chapter{Appendix2}
 ...
\end{appendices}
\end{document}

The missing puzzle piece is provided by the xpatch package. It is used to patch the original \@chapter command, stored in \Hy@org@chapter (as defined by hyperref and/or bookmark).

In essence, the patch changes the ToC entry from chapter to section.

The solution works with both hyperref and bookmark.

1
  • Thanks, it worked perfectly for me, this is exactly what I was looking for. Nov 29, 2012 at 5:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .