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.
1. Appendix bookmark
Package bookmarks allows to restart the bookmark hierarchy at top level:
\bookmarksetup{startatroot}
If the appendix is something like
\chapter{Appendix}
then the entry in the table of contents is formatted as chapter, not as part.
Instead of
\bookmarksetup{startatroot}
\chapter{Appendix}
something like the following can be used:
\cleardoublepage
\phantomsection
\addcontentsline{toc}{part}{\appendixname}
\chapter*{\appendixname}
Explanation, see 2.
2. Index bookmark
\printindex
\addcontentsline{toc}{part}{Index}
Then you get the page number from the end of the index in the table of contents.
The bookmark also needs an anchor that can be set by \phantomsection
.
\cleardoublepage
\phantomsection % anchor setting
\addcontentsline{toc}{part}{\indexname}
\printindex
3. Page bookmark links
The following example shows, how the correct absolute page numbers can be
get from labels for use in \bookmark
. I use package zref
here for the
labels and references, because it provides absolute page numbers and expandable extraction methods.
\documentclass{book}
\usepackage[ngerman]{babel}
\usepackage{xcolor}
\usepackage{titlesec}
\titlespacing*{\chapter}{0pt}{-30pt}{20pt}
\titleformat{\chapter}[display]{\normalfont\huge\bfseries}{\chaptertitlename \thechapter}{20pt}{\Huge}
\usepackage[hidelinks,bookmarksopen=false]{hyperref}[2011/02/05]
\hypersetup{
pdftitle={test},
pdfauthor={\textcopyright test},
pdfsubject={test},
pdfkeywords={test},
}
\usepackage{bookmark}
\usepackage{shorttoc}
\usepackage{makeidx} % allows index generation
\makeindex
\usepackage{tocstyle}
\usetocstyle{allwithdot}
\usepackage{zref-abspage}
\makeatletter
\newcounter{zpage}
\renewcommand*{\thezpage}{pagelabel\the\value{zpage}}
\newcommand*{\pagebookmark}[2][]{%
\stepcounter{zpage}%
\zref@labelbyprops{\thezpage}{abspage}%
\zref@refused{\thezpage}%
\bookmark[{%
page=\zref@extractdefault{\thezpage}{abspage}{1},%
view={XYZ},%
#1%
}]{#2}%
}
\makeatother
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
\author{test}
\begin{document}
\pagestyle{empty}
\hypersetup{pageanchor=false}
\pagebookmark[rellevel=1,keeplevel,bold,color=blue]{Cover}
\begin{center}
\fbox{\bfseries\Huge Cover}
\end{center}
\newpage
\null\newpage % empty page
% Verlagsseite
\pagebookmark[rellevel=1,keeplevel,bold,color=blue]{Info}
\begingroup
\huge
\textbullet \hspace{0.1cm} test \hspace{-0.1cm} \textbullet
\vspace{7cm}
\large
test test
\vspace{4cm}
Die Verlagsseite
\newpage
\endgroup
\frontmatter
\pagestyle{headings}% or whatever
\hypersetup{pageanchor=true}
\chapter*{Dedication}
\chapter*{Foreword}
\chapter*{Preface}
\chapter*{Acknowlegements}
\cleardoublepage
\pagebookmark[rellevel=1,keeplevel,color=red]{Inhalts\"ubersicht}
\shorttableofcontents{Inhalts\"ubersicht}{1}
\cleardoublepage
\pagebookmark[rellevel=1,keeplevel,color=red]{Inhaltsverzeichnis}
\tableofcontents
\mainmatter
\part{First part}
\chapter{First chapter}
\index{first}
\chapter{Second chapter}
\index{second}
\part{Second part}
\chapter{Third chapter}
\index{third}
\chapter{Fourth chapter}
\index{fourth}
\backmatter
\appendix
\bookmarksetup{startatroot}
\chapter{\appendixname}
\listoffigures
\listoftables
\cleardoublepage
\phantomsection
\addcontentsline{toc}{part}{\indexname}
\printindex
\end{document}
The bookmark window:
4. Empty pages
\section*{}\newpage
is not the best way to create empty pages, the risk of side effects because of
the complex \section
is too large. A simple \null
is sufficient to get
something invisible on the page:
\null\newpage
Headers/footers can also be suppressed, if needed:
\begingroup
\thispagestyle{empty}
\null
\newpage
\endgroup
But in the cases above often a simple
\cleardoublepage
might suffice.
5. Invisible links
Because the document is intended for printing, invisible links make sense.
Since hyperref
2011/02/05 v6.82a option hidelinks
is added for this purpose.
Best Answer
Set a target on the page: