# newgeometry shifting content vertically

I'm having an issue with the geometry package. After assigning a \newgeometry mid-document my page content shifts vertically.I'm aware that \newgeometry 'disables all the options specified in the preamble' but I'm almost giving the \newgeometry the same variables as geometry in the preamble (I'm using a .sty file for my settings). Here are my document in a mws'ish fashion:

\documentclass[11pt, oneside, a4paper]{memoir}
\usepackage{eso-pic}
\usepackage[left=24mm,right=14mm,top=18mm,bottom=40mm]{geometry}
\usepackage{lipsum}

\makepagestyle{strucrep}
\begin{tabularx}{0.6\textwidth}{@{}l X r | l r}
\textbf{Sag:}   & & Building 231 & \textbf{Dok. dato:} & 2017-05-21 \\
\textbf{Sags nr.:}  & & A-2341  & \textbf{Rev. dato:} & 2017-05-28 \\
\textbf{Doc. ID:} & & K09\_B2.2 &\textbf{Revision:}  & A \\
\multicolumn{3}{@{}l |}{\textbf{A. Konstruktionsdokumentation}} &\textbf{Side:} & \thepage \\
\multicolumn{4}{@{}l }{\Large\textbf{A1. Projektgrundlag}}  & \rule{0pt}{6mm} \\
\end{tabularx}
}{}{}

\pagestyle{strucrep}

\newcommand\BackgroundPicture{%
\setlength{\unitlength}{1mm}
\put(10, 10){\framebox(192,247){}}
}

\begin{document}

\section{\TeX}
\lipsum
\newpage

\ClearShipoutPicture

\newgeometry{left=24mm, right=44mm, top=18mm, bottom=40mm, marginparsep=10mm, marginparwidth=20mm}
\edef\marginnotetextwidth{\the\textwidth}
\section{\LaTeX}
\lipsum

\end{document}


It produces the following correct header:

And after the \newgeometry it produces this incorrect heading:

I've tried repeating the \setlength{\headheight} and \setlength{\headsep} command after the \newgeometry, to no avail.

I guess I could just set top=XXmm to force it down to the correct position, however I'd really like to know how to fix it in a way I understand.

• Don't change geometry lengths like \headheight and \headsep after setting up the geometry using geometry. geometry provides options for these! May 19 '17 at 12:27
• Hi @Schweinebacke. Thank you so much, you've helped me figure it out! As per default in geometry my header was not 'included' and hence it had to reside in the 'top', which I'd only given 18mm. Somehow my setlengths had fixed it for the initial geometry. Edit: Oops, enter = post... So I set the headheight and headsep in the geometry like you suggested and expanded 'top'. I did it in geometry and newgeometry, and the problem is solved. Again thank you. Edit: added tag May 19 '17 at 12:44

The issue, as pointed out by @Schweinebacke, was that I used \setlength after defining geometry, this fixed an incorrectly defined geometry.

The correct way is to define the 'top' to include the header (and headsep and headheight) and define headheight and headsep in the definition of geometry. This has to be done in both geometry and \newgeometry.

So the correct way would be:

\usepackage[left=24mm,right=14mm,top=40mm,bottom=40mm, headheight=32mm, headsep=8mm]{geometry}


and

\newgeometry{left=24mm, right=44mm, top=40mm, bottom=40mm, marginparsep=10mm, marginparwidth=20mm, headheight=32mm, headsep=8mm}


(You can include the header in the text-area using includehead, but I like this way more)

Thanks to @Schweinebacke