[Tex/LaTex] Paper margins with fancyhdr package

fancyhdrheader-footer

When I use the fancyhdr package, the paper margins stretched and the white space decrease, how can I set the paper margins correctly when using the fancyhdr package?

Here is the code,

\documentclass[a4paper, 14pt,oneside]{extreport}
\usepackage[top=2cm,bottom=2cm,left=3cm,right=2cm]{geometry} 
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{lipsum}
\usepackage{fancyhdr}
\parindent=2cm
\sloppy 
\hyphenation{} 
\hyphenpenalty=4000
\exhyphenpenalty=4000
\begin{document}
\pagenumbering{arabic}
\pagestyle{fancy}
%\rhead{\nouppercase{\textbf{\textsc{\textsf{\thepage}}}}}
\rhead{}
\lhead{\nouppercase{\textbf{\textsc{\textsf{\leftmark}}}}}
\renewcommand{\headrulewidth}{1pt}
\fancyfoot{}
\cfoot{\nouppercase{\textbf{\textsc{\textsf{\thepage}}}}}
\chapter{Bla bla}
\lipsum
\end{document}

Best Answer

When you set the margins with geometry, the header and footer are not taken into consideration by default. You have to explicitly add the includehead and includefoot options for that.

Here's a better version of your code; note that sans serif bold small caps is not available with Computer Modern fonts (and I suggest using just one layer of emphasis, so either bold or small caps, not both).

\documentclass[a4paper, 14pt,oneside]{extreport}
\usepackage[
  top=2cm,
  bottom=2cm,
  left=3cm,
  right=2cm,
  headheight=17pt, % as per the warning by fancyhdr
  includehead,includefoot,
  heightrounded, % to avoid spurious underfull messages
]{geometry} 

\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{fancyhdr}

\usepackage{lipsum}

\pagestyle{fancy}
\fancyhf{} % clear all fields
\renewcommand{\headrulewidth}{1pt}
%\fancyhead[R]{\bfseries\sffamily\thepage}
\fancyfoot[C]{\bfseries\sffamily\thepage}
\fancyhead[L]{\nouppercase{\bfseries\sffamily\leftmark}}

\fancypagestyle{plain}{% for the chapter start pages
  \fancyhf{}% clear all fields
  \renewcommand{\headrulewidth}{0pt}%
  \fancyfoot[C]{\bfseries\sffamily\thepage}%
}

\begin{document}

\chapter{Bla bla}
\lipsum

\end{document}

enter image description here

Don't issue \sloppy. Your aim is to avoid problems in paragraph formatting, but this is not the solution as it allows very bad paragraphs.

Related Question