# scrartcl and fancyhdr: Strange spacing behaviour

Consider the following piece of code:

\documentclass{scrartcl}
\usepackage{ifthen}
\usepackage{fancyhdr}
\pagestyle{fancy}
\ifthenelse{\equal{\thepage}{1}}{}{
\textbf{foo}\\
\textbf{bar}\\
\textbf{baz}
}
}
\lfoot{}
\cfoot{}
\rfoot{}

\begin{document}
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\newpage
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\newpage
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\end{document}


This is how pages 2 and 3 of the example look like:

as you can see the rows of x are not at the same height. Additionall baz does not start where foo and bar do - it is a bit more at the left.

Do you have any idea what the problem might be?

• You surely find, in the log file, a warning issued by fancyhdr about \headheight. – egreg Oct 31 '13 at 11:48
• And the spaces after the opening braces and some of the closing braces matter Use {% to hide them. – Ulrike Fischer Oct 31 '13 at 11:50
• @egreg please, could you write the answer? – doed Nov 3 '13 at 17:49
• The example code does not give the result of the images, because \  does not result in a line break but only a inter word space. – Schweinebacke May 16 '17 at 7:56

This is a well known and documented behavior of fancyhdr. If at the first usage of the defined header the package finds that the header is vertically bigger than \headheight, it will issue a message and change \headheight for the subsequent pages.

You will find the following message in your .log file:

Package Fancyhdr Warning: \headheight is too small (17.0pt):
Make it at least 38.8842pt.
We now make it that large for the rest of the document.
This may cause the page layout to be inconsistent, however.


Thus you know that you need to set:

\setlength{\headheight}{39pt}


in your preamble (rounding is better):

\documentclass{scrartcl}
\usepackage{ifthen}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\ifthenelse{\equal{\value{page}}{1}}%
{}%
{\bfseries
\makebox[0pt][r]{\smash{\vrule height 1cm depth 2cm}}boo\\
boo\\
boo%
}%
}

\begin{document}
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\newpage
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\newpage
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\end{document}

• Instead of changing \headheight I would recommend to use KOMA-Script option headheight or headlines so that typearea can take the large head into account while calculation of page areas. Also option headinclude could be useful with such a large head. – Schweinebacke May 16 '17 at 7:53

Usage of fancyhdr with a KOMA-Script class is not recommended. Nevertheless, if you switch to scrlayer-scrpage you will get a similar warning message, because the default height of the head is only one line. But KOMA-Script provides options headheight and headlines to setup the page with a larger head. In the example you are using three lines, so headlines=3 should be a good choice:

\documentclass[headlines=3]{scrartcl}
\usepackage{ifthen}
\usepackage{scrlayer-scrpage}
\manualmark

\begin{document}
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\newpage
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\newpage
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\end{document}


And if you don't want the head elements being centered but a left aligned block that is centered, you may use, e.g., a tabular inside the head definition. And to remove the slanted font, set also the font element pageheadfoot:

\documentclass[headlines=3]{scrartcl}
\usepackage{ifthen}
\usepackage{scrlayer-scrpage}
\manualmark

\begin{document}
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\newpage
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\newpage
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\end{document}


I would also suggest not to refer to the page number in the head but to use two different page styles:

\documentclass[headlines=3]{scrartcl}
\usepackage{ifthen}
\usepackage{scrlayer-scrpage}
\manualmark