# Get FancyHDR and geometry to work nicely

In the MWE, geometry is set to leave a top margin of 1cm on the top and on the back of the page. Yet, with FancyHDR on the top of that, occupy some parts of this margin and I have to manually tweak the margins in geometry to get an descent margin.

Is there some correction I could do to have this sorted out automatically ? NB: I compile with xelatex.

\documentclass[twoside]{report}
\usepackage{fontspec} %

\usepackage[top=1cm,bottom=1cm,left=0.5cm,right=0.5cm,asymmetric]{geometry}
\geometry{bindingoffset=2.1cm}
\usepackage{lipsum}

\usepackage{fancyhdr}

\fancypagestyle{style}{
\fancyhf{}
\renewcommand{\footrulewidth}{1pt}}
\pagestyle{style}

\begin{document}
\chapter{Chapter}

\lipsum[1-30]

\end{document}


It actually is very easy, and I should have read the manual for geometry before asking this question. But now it is asked, all there is to do is to add includeheadfoot in the options of the geometry package and problem solved.

\documentclass[twoside]{report}
\usepackage{fontspec} %

\geometry{bindingoffset=2.1cm}
\usepackage{lipsum}

\usepackage{fancyhdr}

\fancypagestyle{style}{
\fancyhf{}
\renewcommand{\footrulewidth}{1pt}}
\pagestyle{style}

\begin{document}
\chapter{Chapter}

\lipsum[1-30]

\end{document}


You have to fit your header and footer inside a narrow space; so you need to reduce headsep and footskip. Here's an example:

\documentclass[twoside]{report}

\usepackage[
top=1cm,
bottom=1cm,
left=0.5cm,
right=0.5cm,
footskip=20pt,
asymmetric,
bindingoffset=2.1cm
]{geometry}

\usepackage{fontspec}
\usepackage{fancyhdr}

\usepackage{lipsum}

\pagestyle{fancy}
\fancypagestyle{style}{%
\fancyhf{}
\renewcommand{\footrulewidth}{1pt}}
\pagestyle{style}

\begin{document}
\chapter{Chapter}

\lipsum[1-30]

\end{document}


Are you sure you want to use those specifications?

• Thanks, but this only moves the problem from having to tweak top and bottom margins to headsep and footskip. Is there a way it can automatically determine the size of the headings and footers, so if I type top and bottom to 0, the headings and footer touch the edges of the page. – HcN Sep 10 '15 at 14:29
• @HcN No, there isn't. – egreg Sep 10 '15 at 14:34