How to explicitly end a \part in LaTeX with hyperref
Asked Answered
C

1

24

I have a LaTeX document which contains the following:

\tableofcontents
\chapter{Chapter One}
\part{Part One}
...
\part{Final Part}
\chapter{Final Part Chapters}
\chapter{Chapter not Part of Part}

When I compile this to a PDF with hyperref, the last chapter is included as part of the final part in my bookmarks. (I'm including hyperref as shown below.)

\usepackage[xetex,breaklinks,a4paper]{hyperref}

What I would like to know is how to explicitly end the part before the final chapter, so that hyperref promotes this bookmark to top level when the PDF is created.

Any help would be appreciated.

Conglomeration answered 27/9, 2009 at 11:34 Comment(0)
M
39

Heiko Oberdiek's bookmark package (an improvement on his work in hyperref) allows you do to this with its \bookmarksetup command.

\documentclass{book}
\usepackage{bookmark,hyperref}
\begin{document}
\tableofcontents
\chapter{Chapter One}
\part{Part One}
\part{Final Part}
\chapter{Final Part Chapters}

\bookmarksetup{startatroot}% this is it
\addtocontents{toc}{\bigskip}% perhaps as well

\chapter{Chapter not Part of Part}
\end{document}

The \bigskip parts adds a little space in the printed table of contents to visually separate the final chapter from the preceding "part".

Midway answered 27/9, 2009 at 22:58 Comment(6)
I was unaware the bookmark package exists. Its a pity that the tex-live distribution with Ubuntu does not include it, but the solution works perfectly. Thanks.Conglomeration
How do you know that \bigskip is the right distance to choose? Is it fixed somewhere? Can it alter with different classes? How can I find out myself the right distance? Is there a pattern you used to find it out?Conal
@Conal What do you mean "the right distance"? This is just a visual gap in the ToC to give some separation between the chapters after the part finishes. You could use any space that looks appropriate to you.Midway
But of course I prefer spaces which have already been used in the layout. Some research documented here shows that for scrbook the skips are defined in em and that there is a set of values used for styling the TOC so I preferred to use one of them. It did not seem to visually fit for me when I used \bigskip and have yet another distance in my TOC. As I am new, I thought maybe \bigskip is always used for styling at that point, a kind of standard or so.Conal
@Conal — I see, thanks for the extra detail. For sure you can/should use a different length which is used elsewhere in the document for consistency, but yes, as you say, it will depend on the class.Midway
It's a messy that latex does not have \end{part} as ConTeXt has.Chowder

© 2022 - 2024 — McMap. All rights reserved.