[Tex/LaTex] Specify distance from page margin to header with geometry

geometryheader-footermarginsspacing

With geometry, the placement of the header is set by specifying the distance from the text body below to the header above with headsep:

\documentclass{article}
\usepackage[showframe, headsep = 5mm]{geometry}
\usepackage{lipsum, fancyhdr}
    \pagestyle{fancy}
    \fancyhf{}
    \fancyhead[R]{A header plus the page number: \thepage}
\begin{document}
\lipsum
\end{document}

enter image description here

In MS Word, on the other hand, the placement of the header is set by specifying the distance from the page margin above to the header below:

enter image description here

My problem now is that I am given a guide that tells me the settings in MS Word, and I have to figure out how to translate that into LaTeX. And this setting I can't figure out. How can I with the help of geometry set the distance from the page margin above to the header below (in which case I would just set headsep = 0pt)?

Best Answer

You should specify top together with the includehead setting:

enter image description here

\documentclass{article}

\usepackage[showframe,includehead,top=5mm]{geometry}

\usepackage{lipsum, fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[R]{A header plus the page number: \thepage}
\begin{document}
\lipsum
\end{document}

From the geometry user's manual, Figure 2 displays the meaning of includehead (and includefoot):

enter image description here

If you now want to specify the distance from the top of the page (margin) to the top of the text body, additionally set headsep and headheight. For example, we can set headheight to \baselineskip by default, and then set

\geometry{
  showframe,
  includehead,
  top=5mm,
  headsep=\dimexpr20mm-\baselineskip,
  headheight=\baselineskip
}

to have the top of the body text exactly 25mm from the page top margin.

Related Question