Within the book.cls class, I redefined the \part section to customize the respective toc entry as follows:

\ifnum \c@secnumdepth >-2\relax
\addcontentsline{toc}{part}{\noindent\fcolorbox{ocre}{black!5}{\protect\makebox[\linewidth-2\fboxsep]{\Large\sffamily\strut #1}}}%

The problem is that the \fcolorbox somehow does not go well with the created part bookmark in the pdf file. For instance, instead of parttitle, I am getting the following bookmark in the built pdf file:

push0 g 0 Gpop[-2]parttitleocreblack!5push0 g 0 Gpoptowidthheightdepthottheight-0.5 -widthheightdepthd- widthheightdepthheightted

I have been trying some \protect commands, without success so far. Would you be aware of a systematic way to correct this behavior. If not, I can still redefine the part titles directly in the pdf.

1 Answer 1


Something like this:



\def\@myparttocformat #1{\noindent
       {\makebox[\linewidth-2\fboxsep-\@pnumwidth]{\Large\sffamily\strut #1}}}

  \ifnum \c@secnumdepth >-2\relax 
    \addcontentsline {toc}{part}
 \addcontentsline {toc}{part}{#1}\fi \markboth {}{}{\centering \interlinepenalty \@M \normalfont \ifnum \c@secnumdepth >-2\relax \huge \bfseries \partname \nobreakspace \thepart \par \vskip 20\p@ \fi \Huge \bfseries #2\par }\@endpart }




\chapter{A chapter}



I did this to keep close to your skeleton of a mwe, however, I would much rather redefine \l@part. (do not know in which device name xcolor option ocre is defined)

The hyperref link would admittedly then be only on the actual name of the Part, and not like here the entire shaded and framed box. But the whole thing would be cleaner.


with the bookmarks shown (now in Acrobat):

toc with acroread

  • Nice. Do you know why the part and chapter numbers are not included in the bookmarks?
    – pluton
    Feb 24, 2013 at 22:12
  • I think they never are for chapters and sections. They are for parts because standard LaTeX puts different things in the toc file then (no \numberline but a \hspace{1em}) and (I did not investigate more), presumably hyperref just filters out the \hspace{1em} which leaves the part number. Yes, I just tried with the memoir class and then even the parts do not get numbers in the bookmarks (memoir uses \partnumberline, \chapternumberline, ...)
    – user4686
    Feb 24, 2013 at 22:18
  • I just found a possible answer: tex.stackexchange.com/questions/11867/customize-pdf-bookmarks/…
    – pluton
    Feb 24, 2013 at 22:23
  • yes, that gives a fix. But does one really want numbers in bookmarks? bookmarks are supposed to be clicked upon... and the TOC already has the numbers.
    – user4686
    Feb 24, 2013 at 22:29
  • correct but when the document is long, numbered bookmarks do help a bit. Also, it looks like the \texorpdfstring command removes the automatic bookmark numbering.
    – pluton
    Feb 24, 2013 at 22:30

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.