1

I am trying to create a custom header including an image with a certain height. In an recent project, I have used the fancyhdr which worked pretty well. However, as the usage of fancyhdr together with KOMA classes is discouraged I would like to switch to scrlayer-scrpage.

Basically, it works but extra vertical space is added below the image. This looks strange and yields an overfull vbox warning. The following MWE demonstrates this behaviour:

\documentclass[twoside]{scrartcl}
%
\newlength{\theLogoHeight}
\setlength{\theLogoHeight}{10mm}
%
\usepackage[showframe]{geometry}
\newgeometry{top=3\theLogoHeight,
  headheight=\theLogoHeight,
  headsep=\theLogoHeight,
  footskip=\theLogoHeight,
  bottom=2\theLogoHeight,
  inner=2\theLogoHeight,
  outer=2\theLogoHeight
}
%
\RequirePackage{scrlayer-scrpage}
\pagestyle{scrheadings}
\clearpairofpagestyles
\newpairofpagestyles{firstpage}{%
  \chead{%
    \rule{0.1cm}{\theLogoHeight}%
  }%
}
%
\begin{document}
\thispagestyle{firstpage}
Test Text Test Text Test Text Test Text Test Text Test Text
\end{document}

What is the reason for this extra vertical space? And how can I get rid of it?

2
1

headheight is the total height of the page header, i.e. the height plus the depth of the header. Your logo is put on the baseline with the height \theLogoHeight. So the height of the header must be at least \theLogoHeight, but there is also the depth of the header which depends on the font size.

Example to visualize the size of header depth:

\chead{%
  \rule[-\dp\strutbox]{0.1cm}{\dp\strutbox}% to visualize the depth of the header
  Example%
  \rule[-\dp\strutbox]{0.1cm}{\dp\strutbox}% to visualize the depth of the header
  \rule{0.1cm}{\theLogoHeight}%
}

enter image description here

You can enlarge headheight and reduce headsep or you can raise down the logo by \dp\strutbox:

\documentclass[twoside]{scrartcl}
%
\newlength{\LogoHeight}
\setlength{\LogoHeight}{10mm}
%
\usepackage[showframe]{geometry}
\newgeometry{top=3\LogoHeight,
  headheight=\LogoHeight,
  headsep=\LogoHeight,
  footskip=\LogoHeight,
  bottom=2\LogoHeight,
  inner=2\LogoHeight,
  outer=2\LogoHeight
}

\usepackage{scrlayer-scrpage}% sets page style scrheadings automatically
\clearpairofpagestyles
\newpairofpagestyles{firstpage}{%
  \chead{\raisebox{-\dp\strutbox}{\rule{0.1cm}{\LogoHeight}}}% <- raise down the logo
}

\begin{document}
\thispagestyle{firstpage}
Test Text Test Text Test Text Test Text Test Text Test Text
\end{document}

enter image description here

The remaining space between the logo and the text body is defined by the value of headsep in your geometry options. You can reduce this value or remove the option to get a smaller sep between page header and text body.

2
  • Thanks a lot, it works like a charm now! Tricky follow-up problem though, as I want to position three lines of text next to the logo. But I'll play around first... – carlosvalderrama Jan 12 '20 at 0:54
  • I ended up just adding some extra space to headheight -- then both text (in a vbox) and image fitted in nicely without any warning. The extra space is calculated with 0.3\baselineskip or \dp\strutbox, which should yield the same, right? – carlosvalderrama Jan 12 '20 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.