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.

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

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

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Something like this:

\documentclass{book}
\usepackage{xcolor}
\usepackage{hyperref}
\usepackage{calc}

\makeatletter

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

\def\@part[#1]#2{%
  \ifnum \c@secnumdepth >-2\relax 
    \refstepcounter{part}%
    \addcontentsline {toc}{part}
     {\texorpdfstring{\protect\@myparttocformat{#1}}{#1}}%
  \else
 \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 }

\makeatother

\begin{document}
\tableofcontents

\part{Hello}

\chapter{A chapter}

world

\end{document}

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.

toc

with the bookmarks shown (now in Acrobat):

toc with acroread

share|improve this answer
    
Nice. Do you know why the part and chapter numbers are not included in the bookmarks? –  pluton Feb 24 '13 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, ...) –  user700902 Feb 24 '13 at 22:18
    
I just found a possible answer: tex.stackexchange.com/questions/11867/customize-pdf-bookmarks/… –  pluton Feb 24 '13 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. –  user700902 Feb 24 '13 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 '13 at 22:30

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.