# Problem with the header/ footer width

I have recently started using the geometry package to format the margins of my documents. Although, I've noticed that the width of the header/ footer remains the same. How can I correct this?

Here's a MWE:

\documentclass{article}

\usepackage{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{blindtext}

\lhead{}
\chead{Header}
\rhead{}
\lfoot{}
\cfoot{Footer}
\rfoot{\thepage}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{1pt}

\begin{document}

\newgeometry{margin=0.5in, bottom=1in, top=1in}
\Blinddocument

\end{document}


## 3 Answers

Loading fancyhdr and tweaking the header/footer content must be done after any margin changes effected by geometry, so that fancyhdr can detect those changes. In your example, \newgeometry after \begin{document} is not needed -- simply specify the margins changes as geometry package options.

\documentclass{article}

\usepackage[margin=0.5in,bottom=1in,top=1in]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{blindtext}

\lhead{}
\chead{Header}
\rhead{}
\lfoot{}
\cfoot{Footer}
\rfoot{\thepage}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{1pt}

\begin{document}

\Blinddocument

\end{document}

• Thank you for your quick reply lockstep. Out of curiosity, do you think there is a way to manually change a header/ footer width? – mkota Jan 5 '12 at 21:07
• Maybe @egreg's answer is helpful in that regard. – lockstep Jan 5 '12 at 21:09

If you really need to use \newgeometry to change the page shape after \begin{document}, the recent package titleps can be useful:

\documentclass{article}

\usepackage{geometry}
\usepackage{titleps}

\usepackage{blindtext}

\newpagestyle{jay}{%
\sethead{}{Header}{}%
\setfoot{}{Footer}{\thepage}%
\setheadrule{1pt}%
\setfootrule{1pt}%
}

\pagestyle{jay}

\begin{document}

\Blindtext

\newgeometry{margin=0.5in, bottom=1in, top=1in}

\Blinddocument

\end{document}


But stick to lockstep's recommendation if this change in shape is not required.

• Thank you very much for your response. This package seems promising. – mkota Jan 5 '12 at 21:19

Thanks, I had the same problem. I used this code and by trial and error I discovered that if you put 0.005\textwith then the text in a footer or heading is visible:

    \documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{lipsum}
\pagestyle{fancy}
\lhead{Exam}
\chead{}
\rhead{Page \thepage}
\lfoot{}
\cfoot{}
\rfoot{}
\usepackage[left=1.5cm, right=1.5cm, top=2cm, bottom=2cm]{geometry}
\fancyheadoffset{0.005\textwidth}
\begin{document}
\lipsum[1]
\newpage
\lipsum[1]
\end{document}

• Welcome to TeX - LaTeX! \fancyheadoffset{0pt} is simpler still. However, the best thing to do is simply to load the geometry package before calling \pagestyle{fancy} as in lockstep's answer. – Andrew Swann Aug 23 '15 at 12:18