I'm working on a document consisting of several pages of text and a series of full-page figures. Since the figures are larger than the normal text width, I've used the geometry package's \newgeometry command to change the margins on the pages they're on. So far, so good.

The problem arises when I try to give the document fancy headers and footers with the fancyhdr package. My fancy page styles (unlike LaTeX's default page styles) don't adjust to the \newgeometry: the header moves to respect the new left margin, but doesn't change its width to reach the right margin.

The following example should show what I mean. The first page, with a fancy page style but no \newgeometry is fine. The second page invokes \newgeometry and the fancy page style has not adjusted. The third page has the same \newgeometry but uses a non-fancy page style; note that the header in this case does extend all the way to the right margin.

\documentclass{article}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{lipsum}
\pagestyle{fancy}
\lfoot{}                    \cfoot{}            \rfoot{\thepage}
\renewcommand{\footrulewidth}{0.4pt}

\begin{document}
\lipsum[1-5]
\clearpage

\newgeometry{left=1.5cm, right=1.5cm}
\lipsum[1-5]
\clearpage

\lipsum[1-5]
\end{document}


I've tried everything I can think of, including defining my fancy page style after the \newgeometry declaration, but the behaviour is still the same. Is there any way I can put fancy headers on a page with altered margins?

A fix is using \fancyhfoffset after \newgeometry, so the widths are recalculated, such as
\newgeometry{left=1.5cm, right=1.5cm}

After I added \fancyhfoffset[E,O]{0pt} to your code, both header and footer are adjusted to the new margin.