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.

Please consider the following multipage MWE, which contains page number restarting; made to compile with pdflatex test.tex:

\documentclass[12pt]{article}

\usepackage{geometry}
\geometry{twoside,inner=50bp,outer=30bp,top=50bp,bottom=50bp}


% \usepackage{titlesec}
% \titleformat{\section}{\centering\normalsize}{\thesection}{1em}{}
% \titleformat{\subsection}{\centering\small}{\thesubsection}{1em}{}


\usepackage{layouts}
\usepackage{etoolbox}
\patchcmd{\drawpage}{\ifdrawparameters}{\iftrue}%
  {\typeout{^^J*******\string\drawpage fixed*******^^J}}%
  {\typeout{^^J*******\string\drawpage not fixed*******^^J}}

\usepackage{hyperref}
\usepackage{tikz,enumitem}
\usepackage{fix-cm}

\usepackage{lipsum}



\begin{document}


  \pagestyle{empty} % no page numbers on next few pages

% pg 1
    \begin{tikzpicture}[overlay,remember picture,yscale=-1, inner sep=0pt, outer sep=0pt,anchor=north west]

      \path (current page.center) node[anchor=center] (textX) {%

        Physical page 1 / Title

      };

    \end{tikzpicture}

  \clearpage

% pg 2
  Physical page 2 / Empty

  \clearpage

% pg 3
  Physical page 3 / TOC

  \tableofcontents

  \clearpage

% pg 4
  %Physical page 4 / Empty
  \ \\

  \clearpage

  \pagenumbering{arabic} % restart page numbering from 1
  \pagestyle{plain} % show page numbers

% pg 5
  Physical page 5

  \section*{Section One}
  \addcontentsline{toc}{section}{Section One}

  \subsection*{Subsection One}
  \addcontentsline{toc}{subsection}{Subsection One}

  \lipsum[1]

  \clearpage

% pg 6
  Physical page 6

  \subsection*{Subsection Two}
  \addcontentsline{toc}{subsection}{Subsection Two}

  \lipsum[2]

  \clearpage

% pg 7
  Physical page 7

  \section*{Section Two}
  \addcontentsline{toc}{section}{Section Two}

  \lipsum[3]

  \clearpage

% pg 8
  Physical page 8

  \subsection*{Subsection Two}
  \addcontentsline{toc}{subsection}{Subsection Two}

  \lipsum[4]

  \clearpage


\end{document}

When this is compiled (twice), there is absolutely no problems in the PDF - table of contents clickable links in PDF work as expected; note that for this correct case, we have test.toc:

\contentsline {section}{Section One}{1}{section*.2}
\contentsline {subsection}{Subsection One}{1}{section*.3}
\contentsline {subsection}{Subsection Two}{2}{section*.4}
\contentsline {section}{Section Two}{3}{section*.5}
\contentsline {subsection}{Subsection Two}{4}{section*.6}

and test.out:

\BOOKMARK [1][-]{section*.2}{Section One}{}% 1
\BOOKMARK [2][-]{section*.3}{Subsection One}{section*.2}% 2
\BOOKMARK [2][-]{section*.4}{Subsection Two}{section*.2}% 3
\BOOKMARK [1][-]{section*.5}{Section Two}{}% 4
\BOOKMARK [2][-]{section*.6}{Subsection Two}{section*.5}% 5

 

Now, uncomment the three lines around \usepackage{titlesec}, and recompile (deleting *.{out,toc,aux} previously if so desired). Eventually you can see pdflatex spitting:

Package hyperref Warning: The anchor of a bookmark and its parent's must not
(hyperref)                be the same. Added a new anchor on input line 72.

pdfTeX warning (ext4): destination with the same identifier (name{page.1}) has 
been already used, duplicate ignored

Now, basically the first link in the TOC (to "Section One") points to physical page 1 (start of document) - instead of physical page 5 (logical page 1, after restart), where it should be! In this case, test.toc is:

\contentsline {section}{Section One}{1}{Doc-Start}
\contentsline {subsection}{Subsection One}{1}{section*.1}
\contentsline {subsection}{Subsection Two}{2}{section*.1}
\contentsline {section}{Section Two}{3}{section*.1}
\contentsline {subsection}{Subsection Two}{4}{section*.2}

... and test.out is:

\BOOKMARK [1][-]{Doc-Start}{Section One}{}% 1
\BOOKMARK [2][-]{section*.1}{Subsection One}{Doc-Start}% 2
\BOOKMARK [2][-]{section*.1}{Subsection Two}{Doc-Start}% 3
\BOOKMARK [1][-]{section*.1}{Section Two}{}% 4
\BOOKMARK [2][-]{section*.2}{Subsection Two}{section*.1}% 5

 

My question is - can I somehow use the titlesec package in the above example, and yet still get correct hyperlinks for the table of contents in the PDF?

Many thanks in advance for any answers,
Cheers!

share|improve this question

2 Answers 2

up vote 2 down vote accepted

EDIT: What worked for me is to avoid titlesec, and do Changing the Section Headings the old way - by wrapping the recommended \renewcommand in \makeatletter/\makeatother in the preamble as so:

\makeatletter
\renewcommand{\section}{\@startsection
{section}%                   % the name
{1}%                         % the level
{\z@}%                       % the indent / 0mm
{-\baselineskip}%            % the before skip / -3.5ex \@plus -1ex \@minus -.2ex
{0.5\baselineskip}%          % the after skip / 2.3ex \@plus .2ex
{\centering\normalsize}} % the style

Ah well, turns out it's a known thing, apparently:

http://www.tug.org/applications/hyperref/ftp/README

titlesec
--------
  "nameref" supports titlesec, but hyperref does not
  (unsolved is the anchor setting, missing with unnumbered
  section, perhaps problems with page breaks with numbered ones).

Well, if anyone knows a workaround, would be great to hear it :)

Cheers!

share|improve this answer

Your setup seems to suggest that you're not interested in numbering your sectional units. So, continue to use \section and \subsection but add

\setcounter{secnumdepth}{0}

to your document preamble. Subsequently, using titlesec provides correct hyperlinks to sectional units from the ToC, despite some compiler warnings.

Here is your preamble:

\documentclass[12pt]{article}

\usepackage{geometry}
\geometry{twoside,inner=50bp,outer=30bp,top=50bp,bottom=50bp}

\setcounter{secnumdepth}{0}

\usepackage{titlesec}
\titleformat{\section}{\centering\normalsize}{\thesection}{1em}{}
\titleformat{\subsection}{\centering\small}{\thesubsection}{1em}{}

\usepackage{layouts}
\usepackage{etoolbox}
\patchcmd{\drawpage}{\ifdrawparameters}{\iftrue}%
  {\typeout{^^J*******\string\drawpage fixed*******^^J}}%
  {\typeout{^^J*******\string\drawpage not fixed*******^^J}}

\usepackage{hyperref}
\usepackage{tikz,enumitem}
\usepackage{fix-cm}
\usepackage{lipsum}

\begin{document}
share|improve this answer
    
Many thanks for that, @Werner - indeed, I do not need numbering here; however, I'm trying to recompile with this preamble, and I still get the same warnings and problems as in the question. I've tried to redefine \section the old way (as described in the edit of my post), and that seems to work OK so far. Many thanks again - cheers! –  sdaau May 16 '12 at 6:10

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.