1

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 …

4

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

  • Suggested solution works fine only if you have chapter and section on the same page of the document. If you put the chapter name and than type some text (for example next two or three pages) and than insert the section, you will have chapter short titles on both sides of the header all the way to the page where section is located, which is not so good... Is there any way to overcome this issue? Many Thanks! – Predrag_M May 7 at 14:07
  • @Predrag_M See my updated answer. – esdd May 7 at 14:46
  • That's exactly what I needed! Thanks! – Predrag_M May 8 at 16:38

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.