2

I need page breaks before each \section{...} of my document. According to this thread: Start new page with each section I am supposed to add following command:

\newcommand{\sectionbreak}{\clearpage} % page break before section

There is a problem using toc with hyperref though. Hyperlinks from toc to each section are set one page prior their actual page position. In the following example:

  • If in toc I click on hyperlink of Section 1 (which is on page 2), I will stay on page 1.
  • If in toc I click on hyperlink of Section 2 (which is on page 3), I will be carried to page 2.

Here is a ready to test code:

\documentclass[12pt,a4paper]{scrartcl} % A4 paper and 12pt font size

\usepackage{hyperref} % Hyperlinks
\usepackage{titlesec} % customizing sections

\newcommand{\sectionbreak}{\clearpage} % page break before section

\begin{document}

\tableofcontents

\section{Section 1}
Text
\subsection{Subsection 1.1}
Text
\subsection{Subsection 1.2}
Text

\section{Section 2}
Text
\subsection{Subsection 2.1}
Text
\subsection{Subsection 2.2}
Text
Text

\end{document}

I need either a fix for the wrong linkage in toc or some other method of inserting page breaks before sections, which is compatible with toc hyperlinks.

zunder
  • 507
  • 2
    Try \newcommand{\sectionbreak}{\clearpage\phantomsection} ? – Mike Renfro Dec 23 '14 at 02:11
  • 2
    Switch the loading order of titlesec and hyperref. You need to load hyperref after titlesec (see Which packages should be loaded after hyperref instead of before?). Also KOMA-script suggests avoid titlesec to modify the sectional units. – Werner Dec 23 '14 at 02:19
  • 1
    @MikeRenfro thanks, your solution almost worked for me, I still had some positioning problems (not pagewise though). Werner described the core of the problem. – zunder Dec 23 '14 at 02:29
  • @Werner Thanks a lot for elaborating, I switched hyperref and titlesec; hyperlinks started working as expected. Due to your hint on titlesec, I am going to extract sections to own .tex files and include them into the main .tex, so I am no longer in need of titlesec. I would accept your answer as correct if it would not be a plain answer to my question. Thanks a lot anyway. – zunder Dec 23 '14 at 02:29
  • Note that Mike Renfro's code does away with the need for titlesec while allowing you to keep everything in one file, should you wish to do so. – cfr Dec 23 '14 at 03:49
  • @cfr switching hyperref and titlesec, without modfiing the sectionbreak part, would as well allow me to keep everything in one file. Adding a phantomsection was not a solution, but a workaround, which builed on a broken order of package imports. Beside that, I still had some positioning problems on some other subsections, which was still a problem of wrong order of imports. – zunder Dec 23 '14 at 11:16

1 Answers1

3

Both hyperref and titlesec manipulate important, related elements of a document. As such, loading order should always be considered. In this case, the loading order should resemble

\usepackage{titlesec}
...
\usepackage{hyperref}

as implicitly suggested by Which packages should be loaded after hyperref instead of before?. However, you'll also find memoir mention the following in the .log about loading titlesec:

Class scrartcl Warning: Usage of package `titlesec' together
(scrartcl)              with a KOMA-Script class is not recommended.
(scrartcl)              I'd suggest to use the package only
(scrartcl)              if you really need it, because it breaks several
(scrartcl)              KOMA-Script features, i.e., option `headings' and
(scrartcl)              the extended optional argument of the section
(scrartcl)              commands .
(scrartcl)              Nevertheless, using requested
(scrartcl)              package `titlesec' on input line 4.

While packages are meant to extend certain "restrictions" imposed by a document class, flexible classes (like memoir) which provide their own functionality should be considered.

Werner
  • 603,163