Latex PageUsing the fancyhdr package, is it possible to change(increase or decrease) the headrule length without changing the header length?

In the picture related, one can see that the headrule rectangle(in red) does not have the same size length as header. This is exactly what I want. Actually, I would like headrule and textwidth with the same length, but header should be bigger than both.

By using, for example:

\fancyheadoffset{1 cm} 

I can make the header bigger than textwidth. But the headrule grows as well, and both header and headrule have the same length.

In this other example that I am adding, one can see the expanded header, with the logo, and the headrule with the same size as the header. What if I want to make the headrule with the same size as the footrule (or with whatever size/align I want), keeping the header unchanged?

Another Example

  • Welcome to TeX.SX! Would you please clarify better what you need? Is it a twoside or oneside document? Where do you want to increase the rule length?
    – egreg
    May 15, 2012 at 21:58
  • Hi egreg. As soon as I get 10 more reputation I will post a picture that clarifies what I want.
    – S.V.
    May 15, 2012 at 23:21
  • You can already insert an image. Just use the button and remove the ! in front of the bracket; a user with enough rep will reinstate it.
    – egreg
    May 15, 2012 at 23:25
  • @user14628: I've updated my answer with some improvements. May 17, 2012 at 0:21

3 Answers 3


You can simply redefine \headrule; in the following example I used two new lengths \HFleft and \HFright to control the left and right trimming of the headrule, respectively; simply changing the values for those lengths you can shorten the headrule in the desired way. An auxiliary \FHoffset length is used as the argument of \fancyheadoffset. Some examples:

Initially, \FHoffset is set to 0cm as well as both trimmings:

\usepackage{lipsum}% just to generate filler text for the example

% Length to control the \fancyheadoffset and the calculation of \headline
% simultaneously



% these lengths will control the headrule trimming to the left and right 

% here the trimmings are controlled by the user

% The new definition of headrule that will take into acount the trimming(s)


\section{Test Section}
\subsection{Test Subsection}


enter image description here

Setting \FHoffset to 1cm and \FHleft and \FHright to 1cm, the width of the headrule will be equal to \textwidth and the headrule will span the text width:

enter image description here

Changing the settings to


the result is now

enter image description here

and with


we get

enter image description here

  • 1
    Fantastic! This is exactly what I want! How did you learn all these?
    – S.V.
    May 17, 2012 at 3:57
  • 3
    @user14628: that's a hard question to answer! Reading lots of code and documentation helped. May 17, 2012 at 4:09

Assuming that you want to put the page number in the margin, not widening the rule, this is how it can be accomplished:


In the right hand pages, the right field of the header consists of a zero width box, in which a 2cm wide box is typeset, with the page number flush right. In the left hand pages we do the opposite.

Here's a left hand page:

enter image description here

Here's a right hand page:

enter image description here

  • Thank you egreg! But I think I am looking for somethng different. Take a look at the new picture in the OP.
    – S.V.
    May 16, 2012 at 0:53

In fancyhdr.sty headrule is defined as

    \hrule\@height\headrulewidth\@width\headwidth \vskip-\headrulewidth}}

This something like

        \hrule\@height\headrulewidth\@width 2in \vskip-\headrulewidth}}

should do the trick (we changed the width of the header, \headwidth, in the definition, to a hardcoded size of 2 inches).

You can easily change this definition to move the headrule around.

  • I tried your suggestion. Although the headrule is in fact smaller, it keeps left aligned with the headerbox. As soon as I get 10 more points I will be able to post pictures and I will show you exactly what happens.
    – S.V.
    May 15, 2012 at 23:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .