I'm trying to set the page size using the geometry
package as shown in the following MWE, compiled with xelatex test.tex
:
\documentclass[12pt]{article}
\usepackage[b5paper,pass]{geometry}
\geometry{b5paper}
\usepackage{tikz,enumitem}
\usepackage{fix-cm}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Junicode}
\usepackage{layouts}
\usepackage{etoolbox}
\patchcmd{\drawpage}{\ifdrawparameters}{\iftrue}%
{\typeout{^^J*******\string\drawpage fixed*******^^J}}%
{\typeout{^^J*******\string\drawpage not fixed*******^^J}}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\end{document}
If I then try to check the page size using pdfinfo
(on Ubuntu), I get size of US letter (?!):
$ pdfinfo -box -f 1 -l 1 test.pdf | grep Page
Pages: 1
Page 1 size: 612 x 792 pts (letter)
Page 1 MediaBox: 0.00 0.00 612.00 792.00
Page 1 CropBox: 0.00 0.00 612.00 792.00
Page 1 BleedBox: 0.00 0.00 612.00 792.00
Page 1 TrimBox: 0.00 0.00 612.00 792.00
Page 1 ArtBox: 0.00 0.00 612.00 792.00
However, if I enter b5paper
in \documentclass[b5paper,12pt]{article}
– then I can just as well delete all the other references to geometry
using b5paper
– because when I compile with that change, I get:
$ pdfinfo -box -f 1 -l 1 test.pdf | grep Page
Pages: 1
Page 1 size: 498.9 x 708.66 pts
Page 1 MediaBox: 0.00 0.00 498.90 708.66
Page 1 CropBox: 0.00 0.00 498.90 708.66
Page 1 BleedBox: 0.00 0.00 498.90 708.66
Page 1 TrimBox: 0.00 0.00 498.90 708.66
Page 1 ArtBox: 0.00 0.00 498.90 708.66
… which (I guess) corresponds to correct B5 measures.
Now, as far as I had believed until now – one should be able to change the paper size with geometry
– as long as those changes are issued before \begin{document}
, is that correct? If so, why doesn't it work here?
I'm wandering, because I wanted to set some custom page sizes with geometry
in this way (and which thus I couldn't propagate to the \documentclass
command).
Many thanks in advance for any suggestions on how to set a custom page size in this example,
Cheers!
Best Answer
Well, finally I think I got somewhere with switching between custom page sizes and page layouts with
geometry
in mid-document (the MWE is below (see also previous post ongeometry
'spass
); click on image for full size):First of all, a couple of words about geometry:
\geometry
only in preamble, and there multiple commands have simply the effect of replacing previously set values of parametersgeometry
first calculates a layout (margins etc) after\begin{document}
, which the manual calls layout L1\restoregeometry
can only restore L1!\newgeometry
can only be called after\begin{document}
(and thus, after L1 is created)\newgeometry
can be\save
/\loadgeometry
-ied\newgeometry
does NOT care about\paperwidth
/height
! In fact, if you thought you could cheat with: ,geometry
will care not a bit, and will in fact reset paperwidth/height back to the documentclass setting (or I guess, the last named page size setting ingeometry
, if any).geometry
does take into account parameters calledlayoutwidth
andlayoutheight
, which serve the purpose of page size limits.Thus, how
geometry
calculates margins, is independent of the actual page setting in\paperwidth
/\pdfpagewidth
. Having all this in mind, the following checklist can be submitted for managing custom page sizes and layouts:\generatePageLayouts
,\switchToLayoutPageA
and\switchToLayoutPageB
\begin{document}
, call first\generatePageLayouts
, not doing any actual page size switching with\paperwidth
/\pdfpagewidth
\newgeometry
withlayoutwidth
/height
set to respective custom pagesize newlengths, and then\savegeometry
\switchToLayoutPageA
and typeset content\paperwidth
/\pdfpagewidth
, and call respectiveloadgeometry
\switchToLayoutPageB
and typeset contentNote that even
\loadgeometry
resets\paperwidth
/height
- which can be seen on the image, in the table produced bylayouts
: there it is reported, on both pages, that:\paperwidth = 614.295pt
- even if neither of the pages is of that size:In any case, here is the MWE, compiled with
xelatex test.tex
:And finally - here is how the above image was generated:
Well, hope this helps someone,
Cheers!