Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
    \lhead{Fancy page style}    \chead{}            \rhead{}
    \lfoot{}                    \cfoot{}            \rfoot{\thepage}
    \renewcommand{\headrulewidth}{0.4pt}
    \renewcommand{\footrulewidth}{0.4pt}

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

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

\thispagestyle{headings}
\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?

share|improve this question

1 Answer 1

up vote 10 down vote accepted

A fix is using \fancyhfoffset after \newgeometry, so the widths are recalculated, such as

\newgeometry{left=1.5cm, right=1.5cm}
\fancyhfoffset[E,O]{0pt}

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

share|improve this answer
    
That worked like a charm. Thanks! –  Ross Churchley Nov 7 '11 at 3:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.