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.

From this question I have used

\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage}

to ensure that sections start on their own page. However when using the hyperref package this results in the section bookmarks pointing to the end of the previous section instead of the start of the new one.

Here is a MWE:

\documentclass{article}
\usepackage[pdftex]{hyperref} % Generate PDF links and bookmarks.
\hypersetup{
  bookmarks=true,
  bookmarksnumbered=true
}

\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage}

\begin{document}
\section{First}
Some text

\section{Second}
More Text

\end{document}

If you use Adobe Reader or Preview on OSX and use the bookmarks you will notice that the second bookmark will be on the first page at the end of the previous section and not on the second page where the second section starts.

How can I fix this?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

Switch the load order of hyperref and titlesec:

\usepackage{titlesec}% http://ctan.org/pkg/titlesec
\usepackage{hyperref}% http://ctan.org/pkg/hyperref

From the hyperref documentation (section 2 Implicit behavior):

This package can be used with more or less any normal LaTeX document by specifying in the document preamble

\usepackage{hyperref}

Make sure it comes last of your loaded packages, to give it a fighting chance of not being over-written, since its job is to redefine many LaTeX commands.

Packages that can be loaded after is given in Which packages should be loaded after hyperref instead of before?

share|improve this answer

\sectionbreak gets executed at a wrong time after the anchor for the section (by \refstepcounter) is set. The \clearpage can also be added by redefining \section. This way \clearpage is the very first that is executed.

\documentclass{article}
\usepackage{hyperref} % Generate PDF links and bookmarks.        
\hypersetup{         
  bookmarksnumbered=true
}
\usepackage{bookmark}

\usepackage{titlesec}

\newcommand*{\OrgSection}{}
\let\OrgSection\section
\renewcommand*{\section}{\clearpage\OrgSection}

\begin{document}
\section{First} 
Some text

\section{Second}
More Text

\end{document}

Remarks:

  • Option bookmarks cannot only be set as package option in \usepackage. Otherwise you get the warning:

    Package hyperref Warning: Option `bookmarks' has already been used, (hyperref) setting the option has no effect on input line 6.

  • You can omit option pdftex. Package hyperref automatically sets the driver options that it is able to detect (pdfTeX/LuaTeX in PDF mode, XeTeX).

  • I recommend package bookmark, then you do not need two LaTeX runs to get updated bookmarks here.

share|improve this answer
    
Can you elaborate further on what I would have to do with the bookmark package? –  Zameer Manji Aug 6 '12 at 5:56

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.