[Tex/LaTex] Storing the original document class page layout with geometry

geometrymargins

Is it possible, using the geometry package, to store (and restore) the original layout specified by the document class (in my case, the class is report)?

Here is some context. I have been editing a long document in the default page layout for the report document class. Now I found out that I need a title page. There is a particular title page layout, and in fact, it works perfectly if I just load the geometry package with its default and change just two settings. But then I want the rest of the document back in the original page layout! I can't do something like \restoregeometry, since I think geometry just overrides the class options… i.e. there doesn't seem to be anything to restore. Similarly, it seems I can't use \savegeometry or \loadgeometry. So how can I get back to my original layout for the rest of the document without painstakingly hard-coding in all of the specific page layout variables?


Here is a minimum working example:

\documentclass[a4paper,10pt]{report}

\RequirePackage[a4paper,dvips]{geometry} % g1
\geometry{top=2.5cm,bottom=2.3cm}        % g2

\begin{document}

\input{the_title_page}

\SomeGeometryCommandsHere  % g3

\input{the_rest}

\end{document}

If I run the above code with the lines labeled "g" commented out, then the title page does not have the correct page layout, but the rest of the document is formatted perfectly.

If I leave lines g1 and g2 uncommented, then the title page has exactly the correct layout, but no matter what I put for g3 (e.g. \loadgeometry, \restoregeometry, etc.) I can't recover the original layout that I had when g1 and g2 were commented.

Of course, I could completely specify the original layout exhaustively in line g3, and this should in principle work. However, I spent almost one hour on this last night and when I still couldn't get it formated correctly I decided I really needed a smarter solution.

Best Answer

With pass option, geometry package will change nothing and use the original layout. You can restore the original layout with \restoregeometry. For example,

\documentclass[a4paper,10pt]{report}
\usepackage[pass]{geometry}

\begin{document}%<-- the original layout for 'report' is saved here.
\newgeometry{top=2.5cm,bottom=2.3cm}
\input{the_title_page}
\restoregeometry %<-- the original layout is restored.
\input{the_rest}
\end{document}

The \newgeometry/\restoregeometry commands have been introduced since v5.0, but use v5.6 or later, because in v5.6 a bug was fixed where \newgeometry didn't work when pass is specified in the preamble.