0

I have read a number of other threads about incorrect link anchors for PDF bookmarks but either the suggestions don't work for me or I don't understand them.

I have the following document for which I'd like to have PDF bookmarks. But the PDF bookmarks for the sections go to the wrong pages--they go to the page before the one they should actually go to. But this only happens when the previous section has subsections--if the previous section has no subsections, the section bookmarks go to the correct page.

I believe that this has something to do with the \clearpages in my styling of the section using titlesec. I would like to have the section title on its own page, but I cannot figure out how to get the bookmarks to work when I do it. The bookmarks for the sub- and subsubsections (not shown here) work fine, as far as I can tell.

MWE follows.

\documentclass[12pt]{article}

\usepackage[protrusion=true,expansion=true]{microtype}

\usepackage[margin=1.0in]{geometry}

\usepackage{mathpazo}
\usepackage[T1]{fontenc}
\linespread{1.05}

\usepackage[utf8]{inputenc}

\usepackage{titlesec}

\titleformat{\section}[display]%
{\clearpage\filcenter\Huge\bfseries\scshape}%
{\vspace*{\fill}}{0pt}{}[\vspace*{\fill}\thispagestyle{empty}\clearpage]

\titleformat{\subsection}{\Large\bfseries}{}{6pt}{}

\titleformat{\subsubsection}{\large\bfseries}{}{12pt}{}

\usepackage[stable]{footmisc}

\usepackage{xcolor}
\definecolor{navyblue}    {RGB}{0.  ,0.   ,139.}
\usepackage[hyperfootnotes=false]{hyperref}
\hypersetup{%
    colorlinks=true,
    breaklinks,
    citecolor=black,
    filecolor=black,
    linkcolor=red,
    urlcolor=navyblue,
    urlbordercolor=navyblue%
}

\title{Sample Doc}
\author{Me}
\date{\today}

\begin{document}

\maketitle
\thispagestyle{empty}

\tableofcontents

% -----------------------------------------------------------
\section{Section 1}
% ----------------------------------------------------------- 

    \subsection{Subsection 1}

% -----------------------------------------------------------
\section{Section 2}
% -----------------------------------------------------------

    \subsection{Subsection 1}

    \subsection{Subsection 2}

% -----------------------------------------------------------
\section{Section 3}
% -----------------------------------------------------------

% -----------------------------------------------------------
\section{Section 4}
% -----------------------------------------------------------

    \subsection{Subsection 1}

    \subsection{Subsection 2}

    \subsection{Subsection 3}

% -----------------------------------------------------------
\section{Section 5}
% -----------------------------------------------------------

    \subsection{Subsection 1}

    \subsection{Subsection 2}

    \subsection{Subsection 3}

\end{document}

1 Answers1

1

Simply remove the first \clearpage from the titleformat.

\documentclass[12pt]{article}
\usepackage[protrusion=true,expansion=true]{microtype}
\usepackage[margin=1.0in]{geometry}
\usepackage{mathpazo}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{titlesec}
\usepackage[stable]{footmisc}
\usepackage{xcolor}
\usepackage[hyperfootnotes=false]{hyperref}

\linespread{1.05}

\let\oldsection\section
\renewcommand{\section}{\clearpage\oldsection} % put the first clearpage here

\titleformat%
{\section}%
[display]%
{\filcenter\Huge\bfseries\scshape}%
{}%
{0pt}%
{\vspace*{\fill}}%
[\vspace*{\fill}\thispagestyle{empty}\clearpage] % second clearpage stays here

\titleformat{\subsection}{\Large\bfseries}{}{6pt}{}
\titleformat{\subsubsection}{\large\bfseries}{}{12pt}{}

\definecolor{navyblue}    {RGB}{0.  ,0.   ,139.}

\hypersetup{%
    colorlinks=true,
    breaklinks,
    citecolor=black,
    filecolor=black,
    linkcolor=red,
    urlcolor=navyblue,
    urlbordercolor=navyblue%
}

\title{Sample Doc}
\author{Me}
\date{\today}

\begin{document}

\maketitle
\thispagestyle{empty}
\tableofcontents

\section{Section 1}
\subsection{Subsection 1}

\section{Section 2}
\subsection{Subsection 1}
\subsection{Subsection 2}

\section{Section 3}

\section{Section 4}
\subsection{Subsection 1}
\subsection{Subsection 2}
\subsection{Subsection 3}

\section{Section 5}
\subsection{Subsection 1}
\subsection{Subsection 2}
\subsection{Subsection 3}

\end{document}
Jojo
  • 1,048