How to Set a Header with scrlayer-scrpage
At a glance
- 1. Load the package
Use scrlayer-scrpage, preferably with a KOMA-Script class such as scrartcl.
- 2. Choose header positions
Clear the existing page-style fields, then set inner, outer, or centered header content.
- 3. Add changing marks
Use automark and headmark to show the current section or chapter.
- 4. Activate and check
Select the scrheadings page style and check both odd and even pages if using two-sided layout.
The scrlayer-scrpage package lets you control headers and footers in LaTeX. You can put fixed text, page numbers, or automatically updated chapter and section titles in the header. The main commands select a position: inner, outer, left, right, or center.
The example below uses a two-sided KOMA-Script article. It places fixed text on the inner side of the header, the current section title on the outer side, and the page number in the footer.
A minimal working example
\documentclass[twoside]{scrartcl}
\usepackage[automark]{scrlayer-scrpage}
\clearpairofpagestyles
\automark{section}
\ihead{Example document}
\ohead{\headmark}
\cfoot{\pagemark}
\setheadsepline{0.4pt}
\pagestyle{scrheadings}
\begin{document}
\section{First section}
This page has the first section title in its outer header.
\newpage
\section{Second section}
The outer header now shows the second section title.
\end{document}
Compile this with a standard LaTeX engine. The scrartcl class is part of KOMA-Script, and scrlayer-scrpage is the package that provides the header and footer commands.
What the commands do
\clearpairofpagestylesremoves existing header and footer contents from the page styles managed by the package. This gives you a clean starting point.\automark{section}sets section titles as the running marks. Theautomarkpackage option enables automatic mark handling; the command specifies which document level supplies the marks.\ihead{...}puts content in the inner header position. In a two-sided document, this is the side near the binding.\ohead{...}puts content in the outer header position. Here,\headmarkinserts the current running mark, which in this example is the section title.\cfoot{\pagemark}centers the page number in the footer.\pagemarkprints the formatted page number.\setheadsepline{0.4pt}adds a rule below the header. Remove this command if you do not want a line.\pagestyle{scrheadings}applies the configured running page style.
With the twoside option, inner and outer positions switch sides on alternating pages so the inner header stays near the binding. With a one-sided document, use \ihead and \ohead if you want the content to keep those logical positions, or use \chead, \lhead, and \rhead to specify center, left, and right directly.
Set a fixed header instead
If the header should be the same on every page, put ordinary text in the selected field:
\ihead{Department of Mathematics}
\ohead{Course notes}
You can also put a page number in a header field, for example \ohead{\pagemark}. The \headmark command is useful when the header should follow the document structure rather than repeat fixed wording.
For a book or report, the usual running mark may be a chapter title, a section title, or both. For example, KOMA-Script classes support \automark[section]{chapter} to use section marks on one side of a two-sided layout and chapter marks on the other. Choose the mark levels to suit your class and layout; an article has sections but does not have chapters.
Chapter-opening pages
In the standard book and report layouts, the first page of a chapter often uses the plain page style rather than scrheadings. As a result, changing the running style may update later chapter pages but not the opening page. To apply the running style to chapter-opening pages in a KOMA-Script class, add:
\renewcommand*{\chapterpagestyle}{scrheadings}
If you only need to change one page, place \thispagestyle{scrheadings} after the relevant chapter or page-starting command. Whether the chapter-opening page should have a full header is a design choice; many books intentionally keep it simpler.
Common mistakes
Forgetting to activate the page style. Defining header fields does not necessarily apply them to the document. Include \pagestyle{scrheadings} for running pages.
Expecting a mark before LaTeX has set one. \headmark displays a running mark, not arbitrary text. It is normally set by sectioning commands and may be empty on pages before the first relevant heading. Use fixed text if you need a guaranteed label.
Changing only the running style. A page may use another style, such as plain, so it will not show the header you configured for scrheadings. This commonly affects chapter-opening pages.
Loading another header package for the same job. Avoid configuring fancyhdr and scrlayer-scrpage together for the same page layout. Use one system so that commands do not compete over page styles.
Assuming inner means left on every page. In a two-sided layout, inner and outer positions alternate between odd and even pages. If you need text fixed to the physical left or right, use the left and right fields instead.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.