4

I define sectioning commands \task and \subtask similar to the ones in the MWE below. Somehow, placing a \label behind a \task and \subtask causes LaTeX to allow a page break between the two. Without the \label, the page break occurs before the \task (as it should).

Why is that?


\documentclass{scrartcl}

% create the sectioning commands \task and \subtask
\DeclareNewSectionCommand[%
    style=section, level=1, afterskip=1sp plus .2ex, beforeskip=-3.5ex plus -1ex minus -.2ex, font=\Large, indent=0em, tocindent=0em, tocnumwidth=1.5em%
    ]{task}
\DeclareNewSectionCommand[%
    style=section, level=2, counterwithin=task, afterskip=-0em, beforeskip=-2ex plus -1ex minus -.2ex, font=\Large, indent=0em, tocindent=2em, tocnumwidth=0em%
    ]{subtask}

\begin{document}

\task{one}
foo\\[47em]
bar

% here, the pagebreak occurs before the \task
\task{two}
\subtask{three}
baz

\clearpage

\task{one}
foo\\[47em]
bar

% here, the pagebreak occurs between the \task and the \subtask
\task{two}
\subtask{three}\label{asdf}
baz

\end{document}
2
  • 2
    it's generally safer to put a label in a heading or caption rather than after it Nov 1, 2017 at 20:44
  • 1
    This problem is independent from KOMA-Script. If you use \subsubsection instead of \task and \paragraph instead of \subtask you will have exact the same with article instead of scrartcl. An alternative to David's suggestion would be to add \leavemode before \label. Nov 2, 2017 at 12:03

0

You must log in to answer this question.

Browse other questions tagged .