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 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}
share|improve this question

2 Answers 2

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.

share|improve this answer
    
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
up vote 2 down vote accepted

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}
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.