Page LayoutBookmark do not point at the right location with pdfbookmark

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
Tobias_Denmark
Posts: 18
Joined: Sun Jun 06, 2010 1:59 pm

Bookmark do not point at the right location with pdfbookmark

Post by Tobias_Denmark »

I can not get the \pdfbookmark to point at the right location. In my own created list of appendices, the \addcontentsline point to the correct location. I have tried placing the \pdfbookmark line of code before, in-between and after \chapter. The same problem occur with \section and \subsection. Hope anyone can help me out here :?:

Code: Select all

\documentclass{book}

% remove entry to toc, but keep no./letter in chapter/section:
\newcommand*{\nocontentsline}[3]{}
\newcommand*{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}

% chapter without toc entry, but listed in list of app and bookmarked:
\newcommand*\appChap[1]{%
\tocless%
\chapter{\thechapter{}: #1}%
\addcontentsline{app}{chapter}{\thechapter{}: #1}%
\pdfbookmark[0]{\thechapter{}: #1}{#1}%
}

% section, subsection and subsubsection:
\newcommand*\appSec[1]{\tocless\section{#1}\addcontentsline{app}{section}{\thesection{}: #1}\pdfbookmark[0]{\thesection{}: #1}{#1}}
\newcommand*\appSubSec[1]{\tocless\subsection{#1}\addcontentsline{app}{subsection}{\thesubsection{}: #1}\pdfbookmark[0]{\thesubsection{}: #1}{#1}}
\newcommand*\appSubSubSec[1]{\tocless\subsubsection{#1}\addcontentsline{app}{subsubsection}{\thesubsubsection{}: #1}}

% make list of appendices:
\makeatletter
	\newcommand*\listofappendices{\chapter{List of Appendices}\@starttoc{app}}
\makeatother

\usepackage{appendix}
\usepackage{hyperref}
\usepackage{bookmark}

\begin{document}
\frontmatter
\phantomsection
\pdfbookmark[0]{Table of Contents}{toc}
\tableofcontents
\listofappendices
\mainmatter
\chapter{Chapter one}
\chapter{Chapter two}
\appendix
\cleardoublepage
\bookmarksetupnext{level=part}
\addappheadtotoc         % adds a title to the table of contents
\appendixpage            % adds a separate title “Appendices” above the first appendix
\begin{appendices}
\appChap{Appendix a}
...(contents of appendix a)...
\appSec{Appendix a - section 1}
...(contents of appendix one)...
\appSubSec{Appendix a - subsection 1}
...(contents of appendix one)...
\appSubSubSec{Appendix a - subsubsection 1}
...(contents of appendix one)...
\appChap{Appendix b}
...(contents of appendix two)...
\appSec{Appendix b - section 1}
...(contents of appendix two)...
\end{appendices}
\backmatter
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Post Reply