In addition to some other flags, geometry
stores the page configuration upon package load in the macro \Gm@restore@org
. For the standard article
document class (your minimal example) this contains:
\csname paperwidth\endcsname =614.295pt\relax
\csname paperheight\endcsname =794.96999pt\relax
\csname textwidth\endcsname =345.0pt\relax
\csname textheight\endcsname =550.0pt\relax
\csname evensidemargin\endcsname =62.0pt\relax
\csname oddsidemargin\endcsname =62.0pt\relax
\csname topmargin\endcsname =16.0pt\relax
\csname headheight\endcsname =12.0pt\relax
\csname headsep\endcsname =25.0pt\relax
\csname topskip\endcsname =10.0pt\relax
\csname footskip\endcsname =30.0pt\relax
\csname baselineskip\endcsname =12.0pt\relax
\csname marginparwidth\endcsname =65.0pt\relax
\csname marginparsep\endcsname =11.0pt\relax
\csname columnsep\endcsname =10.0pt\relax
\csname hoffset\endcsname =0.0pt\relax
\csname voffset\endcsname =0.0pt\relax
\csname Gm@layouthoffset\endcsname =0.0pt\relax
\csname Gm@layoutvoffset\endcsname =0.0pt\relax
\@twocolumnfalse
\@twosidefalse
\@mparswitchfalse
\@reversemarginfalse
This is overwritten at the start of the document to
\csname paperwidth\endcsname =614.295pt\relax
\csname paperheight\endcsname =794.96999pt\relax
\csname textwidth\endcsname =430.00462pt\relax
\csname textheight\endcsname =556.47656pt\relax
\csname evensidemargin\endcsname =19.8752pt\relax
\csname oddsidemargin\endcsname =19.8752pt\relax
\csname topmargin\endcsname =-13.87262pt\relax
\csname headheight\endcsname =12.0pt\relax
\csname headsep\endcsname =25.0pt\relax
\csname topskip\endcsname =10.0pt\relax
\csname footskip\endcsname =30.0pt\relax
\csname baselineskip\endcsname =12.0pt\relax
\csname marginparwidth\endcsname =65.0pt\relax
\csname marginparsep\endcsname =11.0pt\relax
\csname columnsep\endcsname =10.0pt\relax
\csname hoffset\endcsname =0.0pt\relax
\csname voffset\endcsname =0.0pt\relax
\csname Gm@layouthoffset\endcsname =0.0pt\relax
\csname Gm@layoutvoffset\endcsname =0.0pt\relax
\@twocolumnfalse
\@twosidefalse
\@mparswitchfalse
\@reversemarginfalse
To restore the page and text dimensions to what it was before geometry was called, you can make an explicit call to \Gm@restore@org
before \begin{document}
:
\usepackage[...]{geometry}% http://ctan.org/pkg/geometry
\makeatletter
\Gm@restore@org
\makeatother
It is possible to position the image without redefining the page geometry. Redefining the page geometry in general can give you problems.
First let us use some TikZ code to position a block at the top of the page. the block will be half an A4 size i.e., an A5 paper size. When we use an overlay as you see from the image below:

The MWE is shown below:
\documentclass[a4paper]{article}
\usepackage{tikz,lipsum}
\usepackage{hyperref}
\begin{document}
\thispagestyle{empty}
\begin{tikzpicture}[overlay,remember picture,anchor=north west,inner sep=0pt, outer sep=0pt]
\node at (current page.north west) {%
\begin{tikzpicture}[overlay,remember picture, inner sep=0pt, outer sep=0pt,anchor=north west]
\path[color=black,fill=purple]
(0,0) rectangle ++(\the\paperwidth,-0.5\paperheight);
\end{tikzpicture}
};
\end{tikzpicture}
\lipsum
\end{document}
Now of course this is not satisfactory as you want to position the text after the image or the TikZ picture. In order to achieve this you enclose the tikz picture in a \vbox
set at half-page height.

\documentclass[a4paper]{article}
\usepackage{tikz,lipsum}
\usepackage{hyperref}
\begin{document}
\vbox to 0.5\paperheight{\begin{tikzpicture}[overlay,remember picture,anchor=north west,inner sep=0pt, outer sep=0pt]
\node at (current page.north west) {%
\begin{tikzpicture}[overlay,remember picture, inner sep=0pt, outer sep=0pt,anchor=north west]
\path[color=black,fill=purple]
(0,0) rectangle ++(\the\paperwidth,-0.5\paperheight);
\end{tikzpicture}%
};%
\end{tikzpicture}}
\section{Test}
\lipsum
\end{document}
If you replace the code in the node with an includegraphics
command, your image should be imported at the top of the page with no problems.
It is also possible to do the same without any tikZ code. I will post this a bit later if this is what you are after.
As pdf uses different parameters for paperheight
and paperwidth
, I normally use the package hyperref
to ensure they are corrected. If you do not want to load it you can use:
\newcommand*{\fixpdflayout}{%
\pdfpageheight=\the\paperheight
\pdfpagewidth=\the\paperwidth
\ifxetex\else
\ifdim\pdfvorigin=0pt\pdfvorigin=1in\fi
\ifdim\pdfhorigin=0pt\pdfhorigin=1in\fi
\fi}
Best Answer
The following works in PDFLaTeX:
That should work with Xelatex. See the SO qn, Change paper size in the middle of a latex document?, for more.