4

I want a bookmark called "Frontmatter" at level=0 and bookmarks for "Preface", "Acknowledgements" and "Contents" at level=1.

My problem is that \addcontentsline{toc}{chapter}{<x>} automatically creates bookmarks at chapter level (level=0) and I don't how to overwrite them with bookmarks at level=1. The lines I commented out in the below MWE indicate the structure of the bookmarks I would like to have. The bookmark package seems not be provide a solution either, hence I didn't load it in the MWE.

\documentclass{book}

\usepackage{lipsum}
\usepackage{hyperref}

\begin{document}

\frontmatter

%\pdfbookmark[0]{Frontmatter}{frontmatter}
\chapter*{Preface}
%\pdfbookmark[1]{Preface}{preface}
\addcontentsline{toc}{chapter}{Preface}
\lipsum[1]

\chapter*{Acknowledgements}
%\pdfbookmark[1]{Acknowledgements}{acknowledgements}
\addcontentsline{toc}{chapter}{Acknowledgements}
Thanks to everyone for everything.

\cleardoublepage
\pdfbookmark[0]{Contents}{toc}
%\pdfbookmark[1]{Contents}{toc}
\tableofcontents

\mainmatter

\chapter{Lipsum 2}
\lipsum[2]

\end{document}
8

Also in this case package bookmark can help. The bookmark "Frontmatter" can be added at part level and at \mainmatter the bookmark hierarchy is restarted using option startatroot.

\documentclass{book}

\usepackage{lipsum}
\usepackage{hyperref}
\usepackage{bookmark}

\begin{document}

\frontmatter

\pdfbookmark[-1]{Frontmatter}{frontmatter}
\chapter*{Preface}
\addcontentsline{toc}{chapter}{Preface}
\lipsum[1]

\chapter*{Acknowledgements}
\addcontentsline{toc}{chapter}{Acknowledgements}
Thanks to everyone for everything.

\cleardoublepage
\pdfbookmark[0]{Contents}{toc}
\tableofcontents

\bookmarksetup{startatroot}
\mainmatter

\chapter{Lipsum 2}
\lipsum[2]

\end{document}

An alternative solution would be the redefinition of \toclevel@chapter to 1 and resetting after the frontmatter.

  • Why is this solution better than mine (it got a positive vote mine didn't)? No, I am not whining, I just want to know so that I can improve my LaTeX style! ;-) – lpdbw Aug 10 '12 at 14:24
4

Solution: Use bookmark package and then \bookmarksetup{depth=-1} for the frontmatter and \bookmarksetup{depth=4} for the mainmatter.

\documentclass{book}

\usepackage{lipsum}
\usepackage{hyperref}
\usepackage{bookmark}

\begin{document}

\bookmarksetup{depth=-1}

\frontmatter

\pdfbookmark[0]{Frontmatter}{frontmatter}
\chapter*{Preface}
\pdfbookmark[1]{Preface}{preface}
\addcontentsline{toc}{chapter}{Preface}
\lipsum[1]

\chapter*{Acknowledgements}
\pdfbookmark[1]{Acknowledgements}{acknowledgements}
\addcontentsline{toc}{chapter}{Acknowledgements}
Thanks to everyone for everything.

\cleardoublepage
\pdfbookmark[1]{Contents}{toc}
\tableofcontents

\bookmarksetup{depth=4}

\mainmatter

\chapter{Lipsum 2}
\lipsum[2]

\end{document}

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.