1

I would like to use the geometry package alongside fancyhdr. To control the distance between header and main text in my article documentclass, this question recommends use of the headsep parameter:

\documentclass[11pt, a4paper]{article}
\usepackage[includehead, headsep=5pt]{geometry}
\usepackage{fontspec}
\usepackage{fancyhdr}


\pagestyle{fancy}
\fancyhf{}
\fancyhead[C]{A header}%\\a new line in the header}

\renewcommand{\headrulewidth}{1.5pt}

\begin{document}
  \section*{Education}

\end{document}

This seems to work fine, and modifying the headsep indeed modifies the distance between the header and the section title. enter image description here However, it so happens that my header is multi-line. as soon as I uncomment line 9 as follows:

\fancyhead[C]{A header\\a new line in the header}

The section title clashes with the header, which I do not want. enter image description here How can I get headsep to remain aware that my header is now multi line?

12
  • Perhaps you should also modify headheight?
    – Bernard
    Aug 18, 2021 at 9:22
  • It's just a bit confusing to me why that would be necessary, since according to the geometry package docs "If includehead is set to true, headheight and headsep are considered as a part of height". So I would argue that geometry should calculate the appropriate headheight for me ?
    – user32882
    Aug 18, 2021 at 9:26
  • Oh! sorry, I skimmed this point. What was your new value of headsep?
    – Bernard
    Aug 18, 2021 at 9:31
  • 1
    It's a key; you can change its value through the optional arguments for geometry in your preamble, or specify it with geometry{headheight=…}. I think it's better to specify it in the ex unit, so if you decide to modify the font size of your document, you shoudn't have any modification to do for headheight.
    – Bernard
    Aug 18, 2021 at 9:52
  • 1
    or set up fancyhdr first including then set up geometry after you have set up the heading, if you increase the size of the content after setting up the page the output you show isn't that surprising Aug 18, 2021 at 10:41

2 Answers 2

1

Starting with the OP's code, I just augmented the \headheight and decremented the \topmargin by equal amounts. Then, the header behaves as I presume the OP would desire.

MWEs below show single-line and double-line header.

\documentclass[11pt, a4paper]{article}
\usepackage[includehead, headsep=5pt]{geometry}
\headheight=\dimexpr\headheight+15pt 
\topmargin=\dimexpr\topmargin-15pt 
\usepackage{fontspec}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[C]{A header a new line in the header}

\renewcommand{\headrulewidth}{1.5pt}

\begin{document}
  \section*{Education}

\end{document}

enter image description here

\documentclass[11pt, a4paper]{article}
\usepackage[includehead, headsep=5pt]{geometry}
\headheight=\dimexpr\headheight+15pt 
\topmargin=\dimexpr\topmargin-15pt 
\usepackage{fontspec}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[C]{A header\\ a new line in the header}

\renewcommand{\headrulewidth}{1.5pt}

\begin{document}
  \section*{Education}

\end{document}

enter image description here

0

To get a nice layout of a page

z

use the layout package to understand the various dimensions involved in designing a page and their relationships.

To have two lines in the header space you need to set headheight=25pt (5) or more, if plan to add more lines or a figure. Then to separate the header from the text area set headsep=20pt (6) or similar. Finally to allocate enough space from the top of the physical page to the top of the text area set the top= 1in or more.

x . y y

The headheight, the headsep, and others are fixed spaces reserved for your use. They are not aware of overflows nor they collapse in the absence of content.

There’s more than one way to skin a cat. If you overspecify geometry will complain.

The log file is also instructive.

*geometry* driver: auto-detecting
*geometry* detected driver: luatex
*geometry* verbose mode - [ preamble ] result:
* driver: luatex
* paper: a4paper
* layout: <same size as paper>
* layoutoffset:(h,v)=(0.0pt,0.0pt)
* modes: includehead 
* h-part:(L,W,R)=(89.62709pt, 418.25368pt, 89.6271pt)
* v-part:(T,H,B)=(60.0pt, 683.6402pt, 101.40665pt)
* \paperwidth=597.50787pt
* \paperheight=845.04684pt
* \textwidth=418.25368pt
* \textheight=633.6402pt
* \oddsidemargin=17.3571pt
* \evensidemargin=17.3571pt
* \topmargin=-12.26999pt
* \headheight=25.0pt
* \headsep=25.0pt
* \topskip=11.0pt
* \footskip=30.0pt
* \marginparwidth=50.0pt
* \marginparsep=10.0pt
* \columnsep=10.0pt
* \skip\footins=10.0pt plus 4.0pt minus 2.0pt
* \hoffset=0.0pt
* \voffset=0.0pt
* \mag=1000
* \@twocolumnfalse
* \@twosidefalse
* \@mparswitchfalse
* \@reversemarginfalse
* (1in=72.27pt=25.4mm, 1cm=28.453pt)

This is a MWE

\documentclass[11pt, a4paper]{article}
\usepackage[ headheight=25pt, headsep=25pt, top = 60pt, includehead]{geometry}
\usepackage{fontspec}
\usepackage{fancyhdr}

\usepackage{layout}% added<<<<<

\pagestyle{fancy}
\fancyhf{}
\fancyhead[C]{A header \\ a new line in the header}

\renewcommand{\headrulewidth}{1.5pt}

\begin{document}
    \layout% added<<<<<
    \section*{Education}    
\end{document}

You must log in to answer this question.

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