This is going to be something so obvious that I'm almost embarrassed to ask! I've been using fancyhdr to put some fancy headers and footers in my thesis template – in fact, doing what it says on the tin! A sample from the code is as follows:

lmargin=37mm, rmargin=22mm, driver=pdftex,
heightrounded, headsep=7mm,
footskip=11mm, vmarginratio=1:1]{geometry}

\lhead{\small{Thesis Title}}
\rhead{\small{My Name}}
\lfoot{\small{Project Name}}
\rfoot{\small{Submission Date}}

I hope that's enough code for a diagnosis. Everything works fine, except that the header text is sitting immediately on top of the 'headrule' line with virtually no space between them – and I would like a little white space between the text and the line. Curiously all the examples in the fancyhdr documentation show space between the header text and the line, but I can't fathom how to achieve this! It's straightforward enough with a footer, because there's an extra parameter \footruleskip, but there doesn't seem to be an equivalent for the header. If anyone can help, it would be much appreciated.

  • It is recommand to use scrheadings2 with koma. I plays best with Koma Script Classes – someonr Jan 6 '12 at 18:05
  • Hi @someonr, I'm not entirely sure what you mean here (and most of the Google references to scrheadings seem to be in German, of which I am almost completely ignorant! Are you referring to the scrpage2 package? – Mark Birtwistle Jan 6 '12 at 19:49
  • Yeah sorry. I mean the scrpage2 package. Of cause you can use fancyheaders, but scrpage2 belongs to the Koma script class – someonr Jan 7 '12 at 0:38
  \fancyhead[L]{\rule[-2ex]{0pt}{2ex}\small Thesis Title} 
  \fancyhead[R]{\small My Name} 
  \fancyfoot[L]{\small Project Name}
  \fancyfoot[C]{-- \thepage\ --}
  \fancyfoot[R]{\small Submission Date} 

The "modern" notation for fancyhdr is preferable. Note that \small is not a command taking an argument, but rather a declaration.

Adjust the dimension of the strut, that is, the invisible \rule[-2ex]{0pt}{2ex} to suit you.

A strut is an invisible object that, however, contributes to the height (what's above the baseline) or the depth (what's below) of the line in which it is inserted. A rule of width zero is the ideal object, as we can control precisely its size. The \rule command has two mandatory arguments (width and height). With the optional argument we can dictate that it has also a depth. With this trick, the headline has a depth of 2ex (or what we prefer), so TeX will move down the headrule in order not to overlap the headline. It might turn out to be necessary to increase the space reserved for the headline; in this case fancyhdr will issue a warning that can be found in the .log file.

Note that LaTeX has a \strut command, which inserts an invisible rule roughly as high and deep as a parenthesis (in this application it's insufficient).

  • OK @egreg, that works fine – for which many thanks! However, if you could give me a little information about 'struts' and 'invisible' commands, that would be much appreciated. I've tried the fancyhdr documentation to no avail. And what exactly is the \rule[-2ex]{0pt}{2ex} actually doing (ie what are the various component parts for)? Thanks also for the tip on modern notation – as is entirely evident, I have a lot to learn! – Mark Birtwistle Jan 6 '12 at 18:06
  • Many thanks @egreg for your expanded explanation. – Mark Birtwistle Jan 6 '12 at 19:42

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.