2

I am trying to setup the margins such that from the top of the header text and the bottom of the footertext there is exactly 1.5cm space. I was not able to achieve this so far and I would highly appreciate any help. Also, I would like that between the header start and the text start there is always a little space that is why I put headsep. This seems to work well, but I cannot figure out how to put the space on top and bottom to 1.5cm.

I looked at the description of the geometry package and I thought I can achieve this with includeheadfoot, but unfortunately it doesnt work.

Here is the minimial example that does not produce the right margins.

\documentclass[a4paper,11pt]{article}

\usepackage[top=1.5cm,hmargin=1.5cm,bottom=1.5cm,includeheadfoot]{geometry}

\usepackage{fancyhdr}

\pagestyle{fancy}

\fancyhead{}
\fancyfoot{}
\fancyhead[C]{Header}
\fancyfoot[C]{Footer}


\geometry{headheight=10pt,headsep=10pt}

\begin{document}
TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd
TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd
TESTd TESTd TESTdTESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd
TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd
TESTd TESTd TESTd TESTd TESTd TESTd
\end{document}

Many thanks!

  • Aren't geometry measuring from the baseline of the header/footer. You may need to add/subtract the headheight – daleif Aug 12 '13 at 21:09
  • How do I do this? Thanks! – user1513073 Aug 12 '13 at 21:32
2

The MWE triggers a warning:

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

If you update the value of headheight to 13.6pt, you should get your margins.

Some nit-picking:

  • Top margin: Package fancyhdr adds a \strut, its height is usually 0.7\baselineskip, a little higher than the letters A to Z and a to z. Thus the header could be moved a little bit (1.9158pt) to the top:

    \newlength{\corrlength}
    \settoheight{\dimen0 }{Header}
    \settoheight{\dimen2 }{\strut}
    \corrlength=\dimexpr \dimen2 - \dimen0\relax
    \ifdim\corrlength<0pt
      \setlength{\corrlength}{0pt}%
    \fi
    \typeout{* \string\corrlength=\the\corrlength}
    \usepackage[
      top=\dimexpr 1.5cm - \corrlength\relax,
      hmargin=1.5cm,
      bottom=1.5cm,
      includeheadfoot,
      headheight=13.6pt,
      headsep=10pt,
    ]{geometry}
    
  • Bottom margin: The bottom margin is measured from the bottom of the page to the base line of the footer. If there are letters in the footer with descenders (g, p,), then footer line could be corrected in a similar way as the header, by increasing the bottom margin by the depth of these letters.

Example

\documentclass[a4paper,11pt]{article}
\usepackage{pagegrid}
\pagegridsetup{top-left}

\newlength{\corrlength}
\settoheight{\dimen0 }{Header}
\settoheight{\dimen2 }{\strut}
\corrlength=\dimexpr \dimen2 - \dimen0\relax
\ifdim\corrlength<0pt
  \setlength{\corrlength}{0pt}%
\fi
\typeout{* \string\corrlength=\the\corrlength}
\usepackage[
  top=\dimexpr 1.5cm - \corrlength\relax,
  hmargin=1.5cm,
  bottom=1.5cm,
  includeheadfoot,
  headheight=13.6pt,
  headsep=10pt,
]{geometry}

\usepackage{fancyhdr}

\pagestyle{fancy}

\fancyhead{}
\fancyfoot{}
\fancyhead[C]{Header}
\fancyfoot[C]{Footer}

\begin{document}
TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd
TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd
TESTd TESTd TESTdTESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd
TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd TESTd
TESTd TESTd TESTd TESTd TESTd TESTd
\end{document}

The image shows the 15mm at the top of "Header":

Top

| improve this answer | |
  • If I do this, then I have more space at the top then from the sides. From left and right it is indeed 1.5cm, but from the top it is more. Any idea how to fix this? – user1513073 Aug 12 '13 at 21:27
  • 1
    @user1513073: I get the 15mm at the top, see example with image. – Heiko Oberdiek Aug 12 '13 at 21:34
  • One last question: Do you know how I can also make sure that the footer is 15mm away from the bottom? – user1513073 Aug 12 '13 at 22:18
  • @user1513073: If the footer only contains the page number with normal digits (not old-style), then nothing need to be done. Does your footer contain letters like g or p with descenders? – Heiko Oberdiek Aug 13 '13 at 6:10

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.