[Tex/LaTex] How to make appendices like section in bookmarks

appendicesbookmarkshyperref

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.

Best Answer

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.