Tx · LaTeX & TikZ

Why Does `scrartcl` Have Strange Spacing with `fancyhdr`?

Published By the 9to5Science editorial team

At a glance

  1. 1. Check the header height

    Look for a fancyhdr warning that the header is too tall for the current headheight.

  2. 2. Check the layout settings

    Review headheight and headsep, and avoid changing KOMA-Script type-area lengths without recalculating the layout.

  3. 3. Use KOMA's page tools

    Prefer scrlayer-scrpage, which is designed to work with KOMA-Script classes.

  4. 4. Compare page styles

    Check whether the first page uses a different style, such as plain, from the later pages.

The combination of scrartcl and fancyhdr can make the space above or below a header look unexpectedly large. The usual issue is that the header dimensions and the page layout were set by different systems: KOMA-Script calculates a type area, while fancyhdr supplies page-header and footer formatting.

The exact cause depends on the preamble and the header contents. Start by checking \headheight and \headsep; if you do not specifically need fancyhdr, use KOMA-Script’s scrlayer-scrpage package instead.

What the spacing lengths do

\headheight is the height reserved for the header itself. \headsep is the vertical distance between the bottom of the header and the start of the text area. They affect different parts of the page, so changing one is not a universal fix for the other.

A header can need more height than the default when it contains a larger font, multiple lines, or graphics. In that case, fancyhdr may warn that \headheight is too small. A header that exceeds the reserved height can cause warnings and make the page layout appear inconsistent.

KOMA-Script’s typearea mechanism calculates the printable text area using the page dimensions and layout settings. If you change a layout length after that calculation, the text area may no longer reflect the changed settings. \recalctypearea asks KOMA-Script to calculate it again.

Prefer scrlayer-scrpage with KOMA-Script

For a typical header showing a document label on the left and the page number on the right, use scrlayer-scrpage:

\documentclass[11pt]{scrartcl}
\usepackage[automark]{scrlayer-scrpage}

\clearpairofpagestyles
\ihead{Example document}
\ohead{\pagemark}
\setkomafont{pagehead}{\normalfont\small}
\pagestyle{scrheadings}

\begin{document}
\section{First section}
This page uses a KOMA-Script-compatible header.

\newpage
The header continues on the next page.
\end{document}

The scrlayer-scrpage package provides \ihead and \ohead for the inner and outer header fields. In a one-sided document, those correspond to the left and right sides. \clearpairofpagestyles removes the package’s default header and footer contents before you add your own. The pagehead font setting changes the header text size without altering the body text.

If you need to keep fancyhdr

First, make sure the header fits in the reserved height. For a simple one-line header, you might try a value such as 14pt, but the correct value depends on its font and contents. Use the value indicated by a fancyhdr warning when one is provided. Then recalculate the KOMA-Script type area:

\setlength{\headheight}{14pt} % Example only; choose a suitable height
\recalctypearea

Put these commands after defining the header and its font, so the height reflects the contents you intend to use. If the gap between the header and body is the problem, inspect \headsep instead; increasing \headheight is not the same as changing that gap.

Avoid making several compensating changes at once. In particular, do not add manual \vspace commands or alter \topmargin and \textheight until you have checked the header dimensions. Those changes can mask the cause and interfere with KOMA-Script’s page-layout calculation. If you also use a layout package such as geometry, choose one system to control the page dimensions and configure it consistently.

Common causes of apparently inconsistent spacing

  • The header is too tall. A larger font, two lines, or a logo can exceed \headheight.
  • The gap is being mistaken for header height. \headsep controls the gap between the header and the text block.
  • The layout was not recalculated. If you change relevant lengths after KOMA-Script has set up the type area, call \recalctypearea afterward.
  • The first page uses a different page style. Commands such as \maketitle can apply a plain style to the title page, while later pages use the main page style. Compare like-for-like pages before concluding the spacing changes randomly.
  • Multiple layout adjustments are competing. Mixing manual margin changes, a page-layout package, and KOMA-Script calculations makes it harder to identify which setting controls the result.

If the spacing remains unexpected, reduce the document to a minimal example containing the class declaration, packages, header definitions, and one or two pages. The exact preamble is needed to distinguish a header-height problem from a separate layout or page-style setting.

References

  1. KOMA-Script Guide
  2. The fancyhdr and extramarks packages: extensive control of page headers and footers

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