Problem
I'm trying to create fancy headers for my documents using fancyhdr
. I want the headrule to be dotted, which can be achieved using
\renewcommand{\headrule}{\vbox to 0pt{\hbox to\headwidth{\dotfill}\vss}}
as stated in the fancyhdr
-documentation on page 12. Now I also want to move the rule nearer to the content of the header. For the footer, there is \footruleskip
, but unfortunately no . If I just elevate the box of the headrule by using \footruleskip
\raisebox
I get
Package Fancyhdr Warning: \headheight is too small (38.32509pt):
Make it at least 39.58127pt.
How do I automatically adjust \headheight
or how can I get rid of the overfull box produced by raising the headrule box.
Bonus: Currently I specify \setlength{\headheight}{3.5em}
because of the \Huge\thechapter
. How can I automatically set \headheight
?
MWE
\documentclass{scrbook}
% Display box around header
\usepackage{eso-pic}
\AddToShipoutPictureFG{
\AtTextUpperLeft{%
\put(0,\LenToUnit{\headsep}){%
\framebox(\LenToUnit{\textwidth},\LenToUnit{\headheight}){}%
}%
}%
}
\usepackage{fancyhdr}
\pagestyle{fancy}
\setlength{\headheight}{3.5em}
% From fancyhdr documentation
\fancyhf{}
\fancyhead[LE,RO]{\sffamily\chaptername\ \Huge\thechapter}
\fancyhead[RE,LO]{\sffamily\leftmark}
\begin{document}
\chapter{Test Chapter}
\eject
\renewcommand{\headrule}{\vbox to 0pt{\hbox to\headwidth{\dotfill}\vss}}
\hbox{}
\eject
\renewcommand{\headrule}{\raisebox{0.25\headheight}{\vbox to 0pt{\hbox to\headwidth{\dotfill}\vss}}}
\hbox{}
\end{document}
Output
\renewcommand{\headrule}{\vbox to 0pt{\hbox to\headwidth{\dotfill}\vss}}
\renewcommand{\headrule}{\raisebox{0.25\headheight}{\vbox to 0pt{\hbox to\headwidth{\dotfill}\vss}}}
\smash{\Huge\thechapter}
and use\renewcommand{\headrule}{\raisebox{0.25\headheight}{\makebox[\headwidth]{\dotfill}}}
, then I don't get any warnings. You still have to set\headheight
manually.