Tx · LaTeX & TikZ

How to Customize Chapter and Section Headers with scrlayer-scrpage

Published By the 9to5Science editorial team

At a glance

  1. 1. Load the package

    Use scrlayer-scrpage with automatic marks in your scrbook document.

  2. 2. Choose mark levels

    Set chapter as the left mark and section as the right mark.

  3. 3. Place the marks

    Put the chapter and section marks in the header fields you want.

  4. 4. Check chapter pages

    Chapter-opening pages commonly use a plain page style instead of the running-header style.

With KOMA-Script’s scrbook class, scrlayer-scrpage can put chapter and section titles in running headers. The key is to distinguish which marks are updated from where those marks appear: \automark configures the marks, while commands such as \ihead and \ohead place content in header fields.

The example below puts the chapter mark in the inner header and the section mark in the outer header. In a two-sided book, inner and outer positions switch sides on even and odd pages.

A complete example

\documentclass[twoside]{scrbook}
\usepackage[automark,headsepline]{scrlayer-scrpage}

\clearpairofpagestyles
\automark[section]{chapter}
\ihead{\leftmark}
\ohead{\rightmark}
\cfoot{\pagemark}
\pagestyle{scrheadings}

\begin{document}

\chapter{First Chapter}
\section{A Section}
Text on this page. Add enough text to continue onto another page
and check how the running headers change.

\chapter{Second Chapter}
\section{Another Section}
More text.

\end{document}

Compile the example with LaTeX. The package option automark enables automatic running marks, and \automark[section]{chapter} specifies the levels: chapters supply the left mark, while sections supply the right mark. In the header setup, \leftmark refers to the chapter mark and \rightmark to the section mark. \ihead places its content at the inner edge of the page; \ohead places its content at the outer edge. \cfoot centers the page number in the footer.

With twoside, inner and outer edges swap between odd and even pages. For a one-sided document, you can use \lhead and \rhead instead if you want fixed left and right positions. The chapter and section marks can include their numbers, depending on the mark formatting in use.

Use the standard running mark instead

If you want the usual KOMA-Script behavior rather than chapter and section in separate fields, use \headmark:

\automark[section]{chapter}
\ihead{\headmark}
\ohead{\pagemark}

The class chooses the appropriate running mark for the page. This is often a good choice when you want one title in the header and the page number opposite it. Keep the same \clearpairofpagestyles and \pagestyle{scrheadings} setup from the full example.

Change how the marks look

The commands above choose content and position; they do not require you to change the chapter or section titles themselves. To change font styling for the header, KOMA-Script provides font elements. For example, add this after loading scrlayer-scrpage:

\addtokomafont{pagehead}{\small\sffamily}

This changes the font used for the page head. If you want to alter the text included in chapter or section marks—for example, to omit a number—customize the relevant mark-format commands rather than editing the page title. Check the KOMA-Script manual for the exact formatting hook that fits your class version and desired output.

Chapter-opening pages

A chapter-opening page commonly uses the plain page style, so it may not show the same running header as later pages in the chapter. That is intentional in many book layouts. If you need a header on chapter-opening pages too, configure the plain style provided by scrlayer-scrpage, or change the chapter page style. Do this separately from setting the running marks: changing \automark alone does not make a different page style display a header.

Common mistakes

  • Setting header fields without setting marks: \ihead and \ohead place text, but automatic chapter and section updates require \automark or suitable manual mark commands.
  • Expecting both titles in one field: \headmark normally selects a running mark according to the class’s conventions. Use \leftmark and \rightmark separately when you want separate fields.
  • Mixing header packages: Avoid loading fancyhdr alongside scrlayer-scrpage to configure the same headers. Use the KOMA-Script package’s own commands for a scrbook document.
  • Judging the setup on a chapter’s first page: Check a later page as well; the opening page can use a different page style.

For a custom design, first decide whether you want one standard running title or separate chapter and section marks. Then set the automatic mark levels and place the marks in the header fields that match your layout.

References

  1. KOMA-Script: A versatile LaTeX2ε bundle

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.