3

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[ 
headsepline, 
autooneside=false,
automark,
draft=false,
    ]{scrlayer-scrpage} 
\pagestyle{scrheadings}
\clearscrheadfoot
\rofoot{\bfseries\thepage}
\automark*[subsection]{}
\addtokomafont{pageheadfoot}{\normalfont\footnotesize\sffamily}
\lohead{\RaggedRight\leftmark}
\rohead{\RaggedLeft\rightmark}

\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}

enter image description here

3

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}
\newcommand{\sechead}{%
     \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
5

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,
headings=optiontohead
]{scrbook}
\usepackage{ragged2e}
\usepackage[
headsepline,
autooneside=false,
automark,
draft=false,
    ]{scrlayer-scrpage}
\pagestyle{scrheadings}
\clearscrheadfoot
\rofoot{\bfseries\thepage}
\automark*[subsection]{}
\addtokomafont{pageheadfoot}{\normalfont\footnotesize\sffamily}
\lohead{\RaggedRight\leftmark}
\rohead{\RaggedLeft\rightmark}

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

enter image description here

enter image description here

  • Thank you! Very good answer and a good to know option! But actually I was looking for a solution Piet has been offering so I accepted his code as solution for this thread. – LukasCB Dec 2 '16 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.