[Tex/LaTex] Header with section short title and chapter short title using KOMA-Script

chaptersheader-footerkoma-scriptsectioning

I'm trying to set header with chapter title on the right and section title on the left (with appropriate numbers in front of them). Also, I need to use short titles for header and long titles for ToC.

I am using single side document KOMA-Script Book with scrlayer-scrpage.

Please help …

Best Answer

Set option autoneside=false for package scrlayer-scrpage if you want to use both chapter and section titles in a onesided document.

Set class option headings=optiontohead if the optional argument of sectioning commands should be used for the page header and not for ToC by default.

Example:

\documentclass[
  headings=optiontohead,
  twoside=false
]{scrbook}

\usepackage[autooneside=false,automark]{scrlayer-scrpage}
\clearpairofpagestyles
\ihead{\leftmark}
\ohead{\rightmark}
\cfoot*{\pagemark}

\usepackage{lipsum}% only for dummy text
\begin{document}
\tableofcontents
\chapter[Short chapter title]{Long chapter title for document and TOC}
\section[Short section title]{Long section title for document and TOC}
\lipsum
\chapter{A chapter}
\section{A section}
\lipsum
\end{document}

enter image description here

enter image description here


Update (regarding a comment below)

To avoid two equal entries on both sides of the header (eg. in a TOC with more than one page or a chapter without sections) you can use

\ohead{\ifstr{\leftmark}{\rightmark}{}{\rightmark}}

Example:

\documentclass[
  headings=optiontohead,
  twoside=false
]{scrbook}

\usepackage[autooneside=false,automark]{scrlayer-scrpage}
\clearpairofpagestyles
\ihead{\leftmark}
\ohead{\ifstr{\leftmark}{\rightmark}{}{\rightmark}}
\cfoot*{\pagemark}

\usepackage{lipsum}% only for dummy text
\begin{document}
\tableofcontents
\chapter[Short chapter title]{Long chapter title for document and TOC}
\lipsum[1-12]
\section[Short section title]{Long section title for document and TOC}
\lipsum
\chapter{A chapter}
\section{A section}
\lipsum
\end{document}

screenshot

Related Question