For the geometry
package, is it possible to \newgeometry{…}
and fully \restoregeometry
inside a group?
Minimal Example
In the following, the \restoregeometry
inside the {…}
restores frames, but still affects \stretch{…}
on page 3.
\documentclass{article}
\usepackage[showframe]{geometry}
\geometry{
paperwidth = 10cm,
paperheight = 6cm,
vmargin = 0.2cm,
}
\begin{document}
1 Top \par
\vspace{\stretch{1}}
1 Bottom
{
\newgeometry{vmargin = 1cm}
2 Top \par
\vspace{\stretch{1}}
2 Bottom
\clearpage
\restoregeometry % 👈 Here
}
3 Top \par
\vspace{\stretch{1}}
3 Bottom
\clearpage
4 Top \par
\vspace{\stretch{1}}
4 Bottom
\end{document}
I can get the following desired result by moving \restoregeometry
outside the group (after the }
).
But is it possible to achieve the same thing and keep \restoregeometry
inside the group?
Explanation of the phenomenon is also appreciated. Thanks in advance.
Background
I am developing a *.cls
, and I want to provide a command to generate a page with specific texts and special vertical margins. Therefore, \newgeometry{…}
and \restoregeometry
will be put into a group.
Further Info
Versions:
- Windows 10
- XeTeX 3.141592653-2.6-0.999996 (TeX Live 2024)
- geometry revision 61719
\newgeometry
is making settings in the pdf back end to set the page size (as well as TeX-level settings) TeX grouping doesn't really make sense at that level and the back end settings are not restored at the end of the group, you need an explicit restore.
\setlength\topmargin{…}
? @UlrikeFischerchangepage
instead. I don't know if there is anything newer. But it allows you to alter margins etc. for specific pages or for parts of pages. Don't set things like margins explicitly if you're usinggeometry
unless you really know what you're doing. (I don't, so I wouldn't.)