[Tex/LaTex] \newgeometry fails to change page margin inside enumerate

#enumerategeometry

Please see the following code. Here, I try to change page margin inside
an enumerate environment.

\documentclass{article}

\usepackage[a4paper,top=115.0mm,bottom=65.0mm,left=40.0mm,right=25.0mm]{geometry}

\usepackage{lipsum}

\begin{document}

\begin{enumerate}
\item\lipsum[1]

\item\lipsum[2]

\item\lipsum[3]

  \newgeometry{top=25.0mm,bottom=25.0mm}

\item\lipsum[4]

\end{enumerate}

\end{document}

However, the page margins do not change in the second page. If the same
thing is tried without an enumerate environment, it works perfectly well.

What is it I could be missing and how can I correct this?

Best Answer

Although it's not explicit in the docs, \newgeometry is designed to be used at the 'top level' of a document, outside of any environments (it carries out local assigments). That is realistically to be expected: changing page geometry should be very rare and usually between distinct document parts. If you add more items you'll notice the list 'thinks' the page is longer than it is as a result.

It is possible to force the definitions set up by \newgeometry to apply globally using the TeX primitive \globaldefs

\documentclass{article}

\usepackage[a4paper,top=115.0mm,bottom=65.0mm,left=40.0mm,right=25.0mm]{geometry}

\usepackage{lipsum}

\begin{document}

\begin{enumerate}
\item\lipsum[1]

\item\lipsum[2]

\item\lipsum[3]

\globaldefs=1
\newgeometry{top=25.0mm,bottom=25.0mm}
\globaldefs=0

\item\lipsum[4]

\end{enumerate}

\end{document}

However, this may cause unexpected effects as the code inside geometry is not designed for this. Use at your own risk!