14

I am looking to change the title which displays in the PDF bookmark tabs to match the format of how I have my chapters listed.

\documentclass[]{report}
\usepackage[hidelinks]{hyperref} %to add hyperlinks throughout document
\usepackage{titlesec} %reformatting the chapter headings
\titleformat{\chapter}[block]
    {\normalfont\LARGE\bfseries\centering}{CHAPTER \thechapter}{0em}{:\hspace{2mm}}
\begin{document}

\chapter{THE BEGINNING}
Hello.

\chapter{THE END}
Goodbye.
\end{document}

What i currently have is:

title format

with the option of creating bookmarks of:

bad bookmarks1 bad bookmarks2

What I want my bookmarks to look like is identical to how the chapter title is formatted:

good bookmark

I have found that I can input \pdfbookmark[0]{THE BEGINNING}{name1}, but I would need to remove the bookmarks created by hyperref (which would not be ideal if I have multiple chapters, sections, subsections, etc., and have to input them all manually using this method.)

Will I have to work with changing \chapter{THE BEGINNING} to \chapter{CHAPTER \thechapter: THE BEGINNING}, then worry about removing the chapter number from 'CHAPTER 1: THE BEGINNING' from the title and ToC?

UPDATE:

The best option I found is: How to remove chapter numbering without removing it from tableofcontents

I can use the code

\newcommand{\mychapter}[2]{
    \setcounter{chapter}{#1}
    \setcounter{section}{0}
    \chapter*{#2}
    \addcontentsline{toc}{chapter}{#2}}

I use TeXMaker, and I like the structure is provides for opening/organizing subfiles (i.e. using \input{...}). To keep this as organized as possible, I resorted to the following:

  1. Create .tex file titled Chapter.1.THEBEGINNING

  2. This subfile will include \mychapter{1}{CHAPTER \thechapter: THE BEGINNING}

  3. My main document will include \input{Chapter.1.THEBEGINNING}

This works well enough...although still looking for better options.

CiCLimits
  • 143
  • 1
    Maybe Heikos answer to this question will solve your problem: http://tex.stackexchange.com/questions/115008/how-do-i-add-section-subsection-numbers-to-pdf-bookmarks – DG' Jan 29 '14 at 16:46
  • 2
    Use \hypersetup{bookmarksnumbered} \renewcommand*{\thechapter}{\texorpdfstring{}{CHAPTER }\arabic{chapter}\texorpdfstring{}{:}} – karlkoeller Jan 29 '14 at 17:35
  • You may want to update \titleformat, otherwise you'll see : before every \chapter*. – Werner Jan 29 '14 at 18:12
  • @Werner I have modified \chapter{...} to \section{\LARGE\bfseries\centering...} for this. – CiCLimits Jan 29 '14 at 21:33

2 Answers2

13

This example provides a small modification of Werner's solution. Instead of patching the internal \Hy@writebookmark the redefinition of \numberline is done in the bookmark hook addtohook of package bookmark:

\documentclass{report}

\usepackage{hyperref}
\usepackage{bookmark}
\bookmarksetup{numbered}

\usepackage{titlesec} %reformatting the chapter headings
\titleformat{\chapter}[block]
  {\normalfont\LARGE\bfseries\centering}
  {CHAPTER\thechapter: }{0em}{}

\makeatletter
\bookmarksetup{%
  addtohook={%
    \ifnum\toclevel@chapter=\bookmarkget{level}\relax
      \renewcommand*{\numberline}[1]{CHAPTER #1: }%
    \fi
  },
}
\makeatother

\begin{document}

\tableofcontents

\chapter{THE BEGINNING}
Hello.
\section{A section}

\chapter{THE END}
Goodbye.
\end{document}

Result

Heiko Oberdiek
  • 271,626
6

You can insert a conditional to change the way \numberline functions when dealing with \chapters:

enter image description here

\documentclass{report}
\PassOptionsToPackage{hyperref}{hidelinks}
\usepackage{bookmark,etoolbox}
\bookmarksetup{numbered}
\usepackage{titlesec} %reformatting the chapter headings
\titleformat{\chapter}[block]
  {\normalfont\LARGE\bfseries\centering}{CHAPTER \thechapter:\hspace{2mm}}{0em}{}

\makeatletter
\patchcmd{\Hy@writebookmark}% <cmd>
  {\let\chapternumberline\Hy@numberline}% <search>
  {\ifx\Hy@toclevel\toclevel@chapter\def\numberline##1{CHAPTER ##1: }\fi}% <replace>
  {}{}% <success><failure>
\makeatother
\begin{document}

\tableofcontents

\chapter{THE BEGINNING}
Hello.
\section{A section}

\chapter{THE END}
Goodbye.
\end{document}

The default of \numberline (similarly \Hy@numberline used by hyperref is to set the number followed by a space:

\def\numberline#1{#1 }

I've just patched \Hy@writebookmark to correct \numberline when you're dealing with a \chapter using the conditional \ifx\Hy@toclevel\toclevel@chapter. The patch requires etoolbox. It can be updated to provide different prefixes for different sectional units/headings.

Werner
  • 603,163