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!
