# Running header: chapter and section in same line (KOMA)

I would like to have the chapter’s and section’s name appearing in the same line, one coming from the left, the other from the right end. My solution works perfectly fine as long as the chapters and sections aren’t too long. If this is the cause they are overlaid.

I am looking for a solution to put the section’s name in a second line if its name is too long, so it would interfere with the chapter’s name.

I am aware of Chapter title in header too long but I don’t want to use \chapter[<short title>]{<long title>} or \section[<short title>]{<long title>} since I don’t want to change the appearance in the table of contents.

Consider the following MWE:

\documentclass[
twoside=false,
open=right,
]{scrbook}
\usepackage{ragged2e}
\usepackage[
autooneside=false,
automark,
draft=false,
]{scrlayer-scrpage}
\rofoot{\bfseries\thepage}
\automark*[subsection]{}

\begin{document}
\chapter{Normal chapter title in a common document}
\clearpage
\section{No problem here}
\clearpage
\section{Very big problem here since the section title is too long for the line}
\end{document}


Here is how to calculate if it fits and then taking the decision whether to break it up. The 2em is to keep some space between the two parts.

\rohead{\sechead}
\newlength{\chaplength}
\newlength{\seclength}
\settowidth{\chaplength}{\leftmark}%
\settowidth{\seclength}{\rightmark}%
\ifdim \dimexpr\chaplength+\seclength+2em>\textwidth
\parbox{\dimexpr \textwidth-2em-\chaplength}{\RaggedLeft\rightmark}
\else\RaggedLeft\rightmark\fi}

• This works very fine, thank you. One question: How is it achievable to have the long section title as one (long) line in the line below - right now section title is splitted into two lines. – LukasCB Dec 1 '16 at 15:20
• ok, this may work to have the section’s name in one line below the chapter’s name \ifdim \dimexpr\chaplength+\seclength+2em>\textwidth \\[\baselineskip]\RaggedLeft\rightmark \else\RaggedLeft\rightmark\fi – LukasCB Dec 1 '16 at 15:35

You can have a short text in the header and a long text in the table of contents. You only need the option headings=optiontohead:

\documentclass[
twoside=false,
open=right,
]{scrbook}
\usepackage{ragged2e}
\usepackage[
autooneside=false,
automark,
draft=false,
]{scrlayer-scrpage}
\rofoot{\bfseries\thepage}
\automark*[subsection]{}