# Change headsep only for \section titles

Problem

I would like to increase the headsep on pages that start with a section\subsection or paragraph title.

I redefined the chapter spacing settings (before and afterskip) according to my wishes and it looks brilliant in text. Just if the title is on top of the page the beforeskip doesnt seem to influence the spacing to the headerline. An example picture below:

Question

Is there a way to redifine the headsep for pages that start with some kind of section title or is it possible to define it somehow in the settings of the \sections ? I am using koma-script-report-class:

This is the fullcode:

Code

\documentclass[11pt,twoside,english,openright, bibliography=totoc]  {scrreprt}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[a4paper]{geometry}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setlength{\parskip}{\smallskipamount}
\setlength{\parindent}{0pt}
\usepackage{verbatim}
\usepackage{setspace}
\usepackage[authoryear]{natbib}
\onehalfspacing

\makeatletter
\usepackage{lscape}
\ifoot[Test]{Test}
\cfoot[]{}
\ofoot[\pagemark]{\pagemark}
\automark[chapter]{chapter}
\usepackage{pdfpages}
\RedeclareSectionCommand[beforeskip=12pt,afterskip=12pt]{chapter}
\setkomafont{chapter}{\sffamily\LARGE}
\RedeclareSectionCommand[beforeskip=12pt,afterskip=10pt]{section}
\RedeclareSectionCommand[beforeskip=12pt,afterskip=8pt]{subsection}
\RedeclareSectionCommand[beforeskip=-12pt,afterskip=8pt]{paragraph}
\setkomafont{paragraph}{\sffamily\normalsize}
\usepackage {blindtext}

\setkeys{Gin}{width=\textwidth}
\raggedbottom
\usepackage[hyphens]{url}
\makeatother
\usepackage{babel}
\begin{document}

\renewcommand{\thepage}{\roman{page}}
\chapter{Introduction}
\setcounter{page}{1}
\renewcommand{\thepage}{\arabic{page}}
\section{This is a Section}
\blindtext
\blindtext
\blindtext
\blindtext
\subsection{This is a Sub-section}
\blindtext
\end{document}


Note that this is unusual. It would be better to not use such a small headsep.

But if you really want to do this, you can use

\usepackage{xpatch}
\xpretocmd\sectionlinesformat{\vspace*{0pt}}{}{\PatchFailed}


Then the beforeskip is also inserted if the section titles (section, subsection etc.) are on top of a new page.

Do not set \parskip manually. Use the KOMA-Script option parskip=half- instead.

Replace \clearscrheadfoot by \clearpairofpagestyles. With both commands \cfoot[]{} is not needed. And if both the optional and the mandatory argument of \ifoot etc. are equal you can use the starred version.

To restart the page numbering use \pagenumbering and insert a \cleardoublepage or \cleardoubleoddpage before this command to ensure that it is excecuted on a righthand page.

Code:

\documentclass[11pt,twoside,english,openright, bibliography=totoc,
parskip=half-
]{scrreprt}

\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[a4paper]{geometry}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{verbatim}
\usepackage{setspace}
\usepackage[authoryear]{natbib}
\onehalfspacing

\makeatletter
\usepackage{lscape}
\automark[chapter]{chapter}
\clearpairofpagestyles
\ifoot*{Test}
\ofoot*{\pagemark}

\usepackage{pdfpages}
\RedeclareSectionCommand[beforeskip=12pt,afterskip=12pt]{chapter}
\setkomafont{chapter}{\sffamily\LARGE}
\RedeclareSectionCommand[beforeskip=-12pt,afterskip=10pt]{section}
\RedeclareSectionCommands[beforeskip=-12pt,afterskip=8pt]{subsection,subsubsection,paragraph}
\setkomafont{paragraph}{\sffamily\normalsize}

\usepackage{xpatch}
\xpretocmd\sectionlinesformat{\vspace*{0pt}}{}{\PatchFailed}

\usepackage{blindtext}% only for dummy text
\setkeys{Gin}{width=\textwidth}% default width for \includegraphics
\raggedbottom
\usepackage{babel}
\usepackage[hyphens]{url}

\begin{document}

\pagenumbering{roman}
\chapter{Introduction}
\Blindtext
\cleardoubleoddpage
\pagenumbering{arabic}
\chapter{A Chapter}
\section{This is a Section}
\blindtext
\blindtext
\blindtext
\blindtext
\section{A Second Section}
\subsection{This is a Sub-section}
\blindtext
\section{A Second Section}
\subsection{This is a Sub-section}
\Blindtext
\end{document}


If you want to use a smaller skip before section titles on a new page than the normal beforeskip, you can use something like

\usepackage{xpatch}
\makeatletter
\xpatchcmd\sectionlinesformat
{\@hangfrom{\hskip #2#3}{#4}}
{\parbox[b]{\textwidth}{\vspace*{7pt}\raggedsection\@hangfrom{\hskip #2#3}{#4}}}
{}{\PatchFailed}
\makeatother


But then you have to decrease the beforeskip by the same length. In the example beforeskip would be 12pt-7pt=5pt.

\RedeclareSectionCommand[beforeskip=-5pt,afterskip=10pt]{section}
\RedeclareSectionCommands[beforeskip=-5pt,afterskip=8pt]{subsection,subsubsection,paragraph}


Code:

\documentclass[11pt,twoside,english,openright, bibliography=totoc,
parskip=half-
]{scrreprt}

\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[a4paper]{geometry}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{verbatim}
\usepackage{setspace}
\usepackage[authoryear]{natbib}
\onehalfspacing

\makeatletter
\usepackage{lscape}
\automark[chapter]{chapter}
\clearpairofpagestyles
\ifoot*{Test}
\ofoot*{\pagemark}

\usepackage{pdfpages}

\RedeclareSectionCommand[beforeskip=12pt,afterskip=12pt]{chapter}
\setkomafont{chapter}{\sffamily\LARGE}
\RedeclareSectionCommand[beforeskip=-5pt,afterskip=10pt]{section}
\RedeclareSectionCommands[beforeskip=-5pt,afterskip=8pt]{subsection,subsubsection,paragraph}
\setkomafont{paragraph}{\sffamily\normalsize}

\usepackage{xpatch}
\makeatletter
\xpatchcmd\sectionlinesformat
{\@hangfrom{\hskip #2#3}{#4}}
{\parbox[b]{\textwidth}{\vspace*{7pt}\raggedsection\@hangfrom{\hskip #2#3}{#4}}}
{}{\PatchFailed}
\makeatother

\usepackage{blindtext}% only for dummy text
\setkeys{Gin}{width=\textwidth}% default width for \includegraphics
\raggedbottom
\usepackage{babel}
\usepackage[hyphens]{url}

\begin{document}

\pagenumbering{roman}
\chapter{Introduction}
\Blindtext
\cleardoubleoddpage
\pagenumbering{arabic}
\chapter{A Chapter}
\section{This is a Section}
\blindtext
\blindtext
\blindtext
\blindtext
\section{A Second Section}
\subsection{This is a Sub-section}
\blindtext
\section{A Second Section}
\subsection{This is a Sub-section}
\Blindtext
\end{document}

• Thanks for your answer! Could you maybe explain how the command you use works, so that I could adapt it that it fits my format ? I googled a bit but I dont really get it oO. Thanks in advance – KiW Jul 22 '16 at 8:41
• @KiW I haved added another version. But it would be much better if you simple enlarge headsep for all pages instead of patching \sectionlinesformat. A different skip above sections on top of a page and above normal text is unusual. – esdd Jul 22 '16 at 9:20
• Thanks a lot! Well unusual is not neccessarily bad is it ? But I will consider your advice! – KiW Jul 22 '16 at 10:25