The geometry package

Hideo Umeki

                       umeki@ssel.toshiba.co.jp

1997/02/17 (v1.05)

1 Introduction

To set dimensions for page layout is not straightforward. For instance, when you have to write a document according to the following layout instructions:

The total allowable width of the text area is 6.5 inches wide by 8.75 inches high. The first line on each page should begin 1.2 inches from the top edge of the page. The left margin should be 0.5 inch from the left edge.

you will find a gap between comprehensible layout parameters and the L^{A}TEX dimensions to be specified. In this case, you need to specify

     \setlength\textwidth{6.5in}
     \setlength\textheight{8.75in}
     \setlength\topmargin{0.2in}
     \setlength\oddsidemargin{-0.5in}
     \setlength\headheight{0pt}
     \setlength\headsep{0pt}

This package allows L^{A}TEX 2ε users to customize the page layout (page size) by an easy and flexible user interface \geometry. One can realize the above page layout by putting, for example,

     \usepackge{geometry}
     \geometry{body={6.5in,8.75in}, top=1.2in, left=2cm, nohead}

in the preamble.

The name geometry comes from -geometry option for specifying a size and location of a window in X Window System. In the system one can set a window with the option like

     -geometry 150x200+8-10.

Setting a window on the root window corresponds to setting a total text area, including page header and footer, on the paper in this package; for instance,

     \geometry{ width=7in, height=9in, top=.5in, bottom=1in }.

The previous version of the geometry package was called pagesize, but was renamed because the package is totally rewritten to use the L^{A}TEX 2ε keyval^{1} interface and to introduce a new algorithm for determining layout parameters. As a result, the package provides more flexible user interface and new specification for page layout while it does not work in L^{A}TEX209 environment.

1The geometory package requires David Carlisle’s keyval package, which can be found in the graphics bundle of standard L^{A}TEX 2ε packages.

2 Page structure for layout

To realize a straightforward setting for page layout, the following page structure is introduced: A paper contains a total body and margins. The total body consists of a body, a header, a footer and a marginal note, which is optional. The margins are defined as a left-, right-, top-^{2} and bottom-margin.

paper : total body and margins
total body : head, body and foot ( plus marginal notes )
margins : left-, right-, top- and bottom-margin

A body is also called a text area, size of which can be modified by \textwidth and

\textheight.

The layout parts and the corresponding dimensions in the package are listed below.

Dimensions in geometry

Parts  Horizontal  Vertical

             paper  paperwidth          paperheight
         total body  width or totalwidth  height or totalheight
              body  textwidth           textheight

left margin  left or lmargin  —
right margin  right or rmargin  —
top margin  —  top or tmargin
bottom margin  —  bottom or bmargin

marginal notes marginparwidth plus

                      marginparsep

—

              head  —  headheight plus
                                           headsep

              foot  —  footskip

For example, left means a horizontal distance between the left edge of a paper and that of a body.

The dimensions for paper, total body and margins have the following relations.

                     paperwidth = left + width + right
                    paperheight = top + height + bottom

Suppose paper size is pre-defined, if two dimensions out of three in the right-hand side of each equation are given, the remnant dimension will be determined. The partitioning algorithm in each direction is as follows.

Settings  Results
left  width right  left  width right
top  height bottom  top  height bottom
*       *       *  m  ℓ  m  Default.
α  *       *  α  R_{1}  α  Balancing.
*       *  α  α  R_{1}  α  Balancing.
*  α  *  ⟹ R_{2}  α  R_{2}  Centering.
α  *  β  α  R_{3}  β
α  β  *  α  β  R_{3}
*  α  β  R_{3}  α  β
α  γ  β  α  R_{3}  β  Margins win.

The mark ‘*’ denotes the parameter not specified, which means the parameter will be determined by other ones. R_{n} (n=1, 2, 3) are remnant lengths which can be determined by

2It is different from the ordinary L^{A}TEX dimension \topmargin.

α, β and L (paperwidth or paperheight) :

\begin{aligned}R_{1} & = & L − 2α \\ R_{2} & = & (L − α)/2 \\ R_{3} & = & L − α − β \end{aligned}

If none of three dimensions is specified in each direction, default setting is used: In horizontal direction, ℓ and m are 80% and 10% of paperwidth respectively. In vertical, 90% and 5%

of paperheight.

The size of the total body, width and heigth, is defined as the following relations.

            width := textwidth (+marginparsep + marginparwidth)
           height := textheight + headheight + headsep + footskip

Each of the seven dimensions in the right-hand side of the above equations corresponds to the ordinary L^{A}TEX control sequence with the same name. The width definition can be switched by includemp option. The dimensions for a header and a footer can be also controlled by options (mode keys) as well as direct specification of lengths.

Mode keys  Effects

      nohead  sets headheight=0pt, headsep=0pt at the end.
      nofoot  sets footskip=0pt at the end.
      noheadfoot  equals nohead, nofoot

includemp  includes marginal notes in defining width.

                     width := textwidth + marginparsep + marginparwidth
                     ( width := textwidth for default, includemp=false)

3 The user interface

3.1 General features

The \geometry command takes one mandatory argument which specifies neccessary (not all) parameters for the page layout. The argument consists of a list of comma-separated options, which are specified by the keyval interface: ⟨key⟩=⟨value⟩. The specification of \geometry argument has the following features:

• Option list with multiple lines is allowed.

• Any spaces between words are ignored.

• Options are basically order-independent. (There are some exceptions. See Section 8 for details.)

For instance,

      \geometry{  a5paper ,  hmargin = { 3cm,
                      .1\w } , height
               =  10in }

is equivalent to

     \geometry{height=10in,a5paper,hmargin={3cm,0.1\w}}.

Note that when a value has a sub-list of values, for instance hmargin={3cm,0.1\w}, the order in the sub-list of values is important. Here \w and \h are defined as paperwidth and paperheight respectively in \geometry argument. Blank lines are not allowed.

3.2 Option types

There are five types of options:

1. Boolean type (mode)

takes a boolean value (true or false). If no value, true is set for default.

⟨key⟩=true false.

⟨key⟩ with no value is equivalent to ⟨key⟩=true.

Examples: verbose=true, nohead, twoside=false.

Paper name is the exception. The preferred paper name should be set with no values. Even if any value is given, it is ignored. For instance, a4paper=XXX is equivalent to

a4paper.

2. Single-value type

takes a mandatory value, namely dimension: ⟨key⟩=⟨value⟩.

Examples: width=8in, left=1.25in, footskip=1cm, height=.86\h.

3. Two-value type

takes a pair of comma-separated values in braces. The two values can be shortened to one value if they are identical. ⟨key⟩={⟨value1 ⟩,⟨value2 ⟩}. ⟨key⟩=⟨value⟩ is equivalent to ⟨key⟩={⟨value⟩,⟨value⟩}.

Examples: hmargin={1.5in,1in}, scale=0.8, body={7in,10in}.

4. Three-value type

takes three mandatory, comma-separated values in braces. ⟨key⟩={⟨value1 ⟩,⟨value2 ⟩,⟨value3 ⟩}

Examples: hdivide={2cm,*,1cm}, vdivide={3cm,19cm, }, divide={1in,*,1in}.

4 List of options

4.1 Boolean keys

The boolean keys are also called mode keys and can be turned on by putting in the package option list, except for the reset option. For instance,

\usepackage[verbose,landscape]{geometry},

which is equivalent to

\usepackage{geometry}
\geometry{verbose,landscape,· · ·}

The boolean keys are listed below.

verbose typeouts warnings and list of resulted page parameters. landscape switches the paper orientation to landscape mode. portrait switches the paper orientation to portrait mode. twoside switches on two-sided printing. includemp takes account of spaces for margin notes,

\marginparwidth and \marginparsep, when adjusting horizontal partition.

nohead eliminates spaces for the head of page, which is equivalent to

            “\headheight=0pt, \headsep=0pt”.

nofoot eliminates spaces for the foot of page, which is equivalent to

            \footskip=0pt.

noheadfoot eliminates spaces for the head and foot of page, which is equivalent to

nohead and nofoot, i.e.,
“\headheight=0pt, \headsep=0pt, \footskip=0pt”.

reset initializes all the modes above to be false except paper name. The reset option, if necessary, must be used in the \geometry argument and precede all other options. Note that reset=false cannot cancel the previous reset(=true), just do nothing.

a1paper, a2paper, a3paper, a4paper, a5paper,
b1paper, b2paper, b3paper, b4paper, b5paper,
letterpaper, executivepaper, legalpaper

specifies paper name. These must be used with no values. Note that if a paper name is written in the argument, the paper is set regardless of the value, even false!. For example, the followings are all the same:

“a5paper”, “a5paper=true”, “a5paper=false” and “a5paper=XXXX”.

Some of the above options can be set as the document class options. For instance, you can

set \documentclass[a4paper]{article}, then the paper size is inherited to the geometry

package.

4.2 Single-valued keys

The keys with a mandatory value are listed below.

paper  papername

paper name predefined in the geometry package. paper=⟨paper name⟩.

For instance paper=a4paper.

paperwidth width of the paper. paperwidth=⟨paper width⟩. paperheight height of the paper. paperheight= ⟨paper height⟩.

width  totalwidth

width of the total body. width=⟨width⟩ or totalwidth=⟨width⟩. This dimension should not be confused with textwidth. Generally, width ≥ textwidth because width includes the width of marginal notes when the includemp key or dimensions for marginal notes is set. If textwidth and width are specified at a time, width will be ignored.

height  totalheight

height of the total body (including header and footer).

height=⟨height⟩ or totalheight=⟨height⟩. If textheight and height

are specified at a time, height will be ignored.

left lmargin left margin of the total body. In other words, the distance between the

left edge of the paper and that of the total body. left=⟨left margin⟩.

right rmargin right margin of the total body. right=⟨right margin⟩. top tmargin top margin of the total body. top=⟨top margin⟩. bottom bmargin bottom margin of the total body. bottom=⟨bottom margin⟩. hscale ratio of width of the total body to \paperwidth. hscale=⟨h-ratio⟩.

hscale=0.8 is equivalent to width=0.8\w, where \w is defined as an abbreviation of \paperwidth and valid in the geometry argument.

vscale ratio of height of the total body to \paperheight. vscale=⟨v-ratio⟩. vscale=0.9 is equivalent to width=0.9\h, where \h is an abbreviation

of \paperheight.

textwidth modifies \textwidth, width of text (body). textwidth=⟨width⟩. textheight modifies \textheight, height of text (body). textheight=⟨height⟩.

marginparwidth  marginpar modifies \marginparwidth, width of the marginal notes.

When this option is set, includemp is also set true automatically.

marginparwidth=⟨length⟩.

marginparsep modifies \marginparsep, separation between body and marginal notes.

includemp is also set true automatically. marginparsep=⟨length⟩.

headheight  head modifies \headheight, height of header.

headheight=⟨length⟩ or head=⟨length⟩.

headsep modifies \headsep, separation between header and text (body).

headsep=⟨length⟩.

footskip foot modifies \footskip, distance separation between baseline of last line

of text and baseline of footer. footskip=⟨length⟩ or foot=⟨length⟩.

hoffset  modifies \hoffset. hoffset=⟨length⟩.
voffset  modifies \voffset. voffset=⟨length⟩.

twosideshift specifies extra space added to left-margin of odd-numbered pages and subtracted from that of even-numbered pages. twoside mode is also set. twosideshift=⟨length⟩. The default is 20pt.

4.3 Two-valued keys

The following list shows keys taking two values in braces or one value for short.

papersize width and height of the paper.

papersize= {⟨width⟩,⟨height⟩}, or papersize=⟨length⟩.

total width and height of the total body.

total= {⟨width⟩,⟨height⟩}, or total=⟨length⟩.

body text textwidth and textheight of the body of page.

body= {⟨width⟩,⟨height⟩}, or body=⟨length⟩.

scale ratio of the total body length to the paper’s.

scale= {⟨h-ratio⟩,⟨v-ratio⟩}, or scale=⟨ratio⟩.

hmargin left and right margin.

hmargin= {⟨left margin⟩,⟨right margin⟩}, or hmargin=⟨length⟩.

vmargin top and bottom margin.

vmargin= {⟨top margin⟩,⟨bottom margin⟩}, or vmargin=⟨length⟩.

margin           margin={α,β} is equivalent to “hmargin={α,β}, vmargin={α,β}”.
margin=α equals “hmargin=α, vmargin=α”.

offset horizontal and vertical offset.

offset= {⟨hoffset⟩,⟨voffset⟩}, or offset=⟨length⟩.

4.4 Three-valued keys

The keys taking three comma-separated values in braces are listed below.

hdivide horizontal partitions (left,width,right).

hdivide={⟨left margin⟩,⟨width⟩,⟨right margin⟩}. Note that you should not specify all of the three parameters. Specify two out of three with the rest parameter set empty or ‘*’. For example, when you set hdivide={2cm,15cm, }, the margin from the rightside edge of page is determined later calculating paperwidth - 2cm - 15cm.

vdivide vertical partitions (top,height,bottom).

vdivide={⟨top margin⟩,⟨height⟩,⟨bottom margin⟩}.

divide           divide={α,β,γ} is equivalent to
“hdivide={α,β,γ}, vdivide={α,β,γ}”.

5 Package options

As described in the previous section, the boolean keys except for reset option can be used in the package option list. There is another package option:

dvips writes the paper size in the PostScript output with the \special macro. If you use ‘dvips’ command, this option is very useful. For instance, to

                 print a document with \geometry{a3paper,landscape} on A3 paper

in landscape mode, you don’t need options “-t a3 -t landscape” to the ‘dvips’ command.

Note that the dvips option cannot be used as an argument of \geometry, and cannot be reset by reset option since dvips option executes an \AtBeginDocument command.

6 Configuration file

You can set up a configuration file so that some of the boolean options and package ones always take effect, even if not specified in the document/package option or argument of \geometry command. To do this, produce a file geometry.cfg ( like graphics.cfg of graphics package) containing, for instance,

     \ExecuteOptions{a4paper,dvips}

and install it to the TEXINPUTS directory with geometry.sty.

7 Option priority

low ⟶ high (priority)

               • \{ \begin{matrix}hscale \\ vscale \end{matrix} \} < \{ \begin{matrix}width \\ height \end{matrix} \} < \{ \begin{matrix}textwidth \\ textheight \end{matrix} \} ,

               • \{ \begin{matrix}head(height) \\ headsep \\ foot(skip) \end{matrix} \} < \{ \begin{matrix}nohead \\ nofoot \\ noheadfoot \end{matrix} \} .

For instance,

     \geometry{hscale=0.8, textwidth=7in, width=18cm }
is the same as \geometry{textwidth=7in}.

8 Order dependence

The options are basically order-independent, but there are some exceptions. When the redundant or repeated specification is given, the final setting is dependent on the order of appearance in the argument. For instance,

     \geometry{verbose=true, verbose=false}

obviously results in verbose=false.

Here is another example. If you set

     \geometry{hmargin={3cm,2cm},left=1cm},

the left-margin is overwritten by left=1cm. As a result, it is equivalent to

     \geometry{hmargin={1cm,2cm}}.

The reset option should precede all other options in the \geometry argument. If you set

\geometry{nohead, reset} ,

then nohead takes no effect.

9 Default Settings

Once you write \usepackage{geometry} in the preamble, the package will perform the default layout, namely scale={0.8, 0.9}, by internal execution of \geometry{}.

10 Examples

• Set the width of the total body to be 70% that of the paper. The total body is then centered horizontally. Either of the following settings will do.

\geometry{hscale=0.7},
\geometry{ width=0.7\w },
\geometry{hdivide={*,0.7\w,*}},
\geometry{ hmargin=0.15\w },
\geometry{ left=0.15\w },
\geometry{left = .15\w, right= 0.15\w},
\geometry{ rmargin= .15\w },

and so on.

In this case, the default is used for vertical layout: vscale=0.9.

• Set the height of the total body to be 10in, the bottom-margin 3cm, and the width default. Then the top-margin is automatically calculated in the package.

\geometry{height=10in,bottom=2cm},
\geometry{bmargin = 2cm ,totalheight= 10in },
\geometry{vdivide  = { *, 10in ,2cm } },

and so on.

• Set the left-, right-, and top-margin 3cm, 2cm and 2.5in respectively. The page header is not used. The body is 40 lines of text in height.

\geometry{left=3cm,right=2cm, nohead,
               top=2.5in, textheight=40\baselineskip},
\geometry{ hmargin = {3cm, 2cm} , head=0pt, headsep=0pt
             tmargin = 2.5in, textheight=40\baselineskip},

and so on.

• Include marginal notes when adjusting horizontal partition.

\geometry{ includemp },
\geometry{ includemp = true },

and so on.

• Modify the width of marginal notes to 3cm. and include marginal notes when adjusting horizontal partition

\geometry{ marginpar=3cm },
\geometry{ marginparwidth=3cm },
\geometry{ marginpar=3cm , includemp }, (redundant!)

and so on.

• Use A5 paper in landscape mode and a full scale of the paper as the body.

         \geometry{ a5paper, landscape, scale=1.0 , noheadfoot},
         \geometry{ landscape = TRUE , paper =a5paper,
                      noheadfoot , total={\w,\h} },

and so on.

11 Acknowledgements

I would like to thank Friedrich Flender and Piet van Oostrum for their pointing out bugs and suggesting improvements.

12 The implementation

The actual code of geometry package is as follows.

This package requires David Carlisle’s keyval package.

1 ⟨∗package⟩

 2 \RequirePackage{keyval}[1995/09/21]

Internal switches are declared.

 3 \newif\ifGeom@verbose
 4 \newif\ifGeom@landscape
 5 \newif\ifGeom@nohead
 6 \newif\ifGeom@nofoot
 7 \newif\ifGeom@includemp
 8 \newif\ifGeom@@includemp
 9 \newif\ifGeom@sethtotal
10 \newif\ifGeom@setvtotal
11 \newif\ifGeom@setwidth
12 \newif\ifGeom@setheight
13 \newif\ifGeom@settextwidth
14 \newif\ifGeom@settextheight
15 \newif\ifGeom@setlmargin
16 \newif\ifGeom@setrmargin
17 \newif\ifGeom@settmargin
18 \newif\ifGeom@setbmargin

\Geom@checknum The counter for determining directional partition is declared.

19 \newcount\Geom@checknum
\Geom@Oheadheight \Geom@Oheadsep \Geom@Ofootskip The original lengths of \headheight, \headsep and \footskip are saved. These lengths

are set everytime \geometry is called.

20 \edef\Geom@Oheadheight{\the\headheight}
21 \edef\Geom@Oheadsep{\the\headsep}
22 \edef\Geom@Ofootskip{\the\footskip}

\Geom@Dhscale \Geom@Dvscale The default values for the horizontal and vertical scale are defined.

23 \def\Geom@Dhscale{0.8}
24 \def\Geom@Dvscale{0.9}

\Geom@Dtwosideshift The default for twosideshift is defined.

25 \def\Geom@Dtwosideshift{20pt}

The modes and the flag are initialized here. But twoside should not be reset here because it may be inherited from the class option.

26 \Geom@verbosefalse
27 \Geom@landscapefalse
28 \Geom@noheadfalse

29 \Geom@nofootfalse
30 \Geom@includempfalse
31 \Geom@@includempfalse% checking setting of |includemp|
\Geom@reset
32 \def\Geom@reset{%
33 \@twosidefalse
34 \@mparswitchfalse
35 \Geom@verbosefalse
36 \Geom@landscapefalse
37 \Geom@noheadfalse
38 \Geom@nofootfalse
39 \Geom@includempfalse
40 \Geom@@includempfalse}

The option keys are defined below.

`paper' `papername' paper or papername takes paper name as its value. Available paper names are listed below.

41 \define@key{Geom}{paper}{\setkeys{Geom}{#1}}
42 \let\KV@Geom@papername\KV@Geom@paper
`a1paper' `a2paper' `a3paper' `a4paper' `a5paper' `b1paper' `b2paper' `b3paper' `b4paper' `b5paper' `letterpaper' `legalpaper' `executivepaper' Thirteen standard paper names are available.
43 \define@key{Geom}{a1paper}[true]{\def\Geom@paper{a1paper}}
44 \define@key{Geom}{a2paper}[true]{\def\Geom@paper{a2paper}}
45 \define@key{Geom}{a3paper}[true]{\def\Geom@paper{a3paper}}
46 \define@key{Geom}{a4paper}[true]{\def\Geom@paper{a4paper}}
47 \define@key{Geom}{a5paper}[true]{\def\Geom@paper{a5paper}}
48 \define@key{Geom}{b1paper}[true]{\def\Geom@paper{b1paper}}
49 \define@key{Geom}{b2paper}[true]{\def\Geom@paper{b2paper}}
50 \define@key{Geom}{b3paper}[true]{\def\Geom@paper{b3paper}}
51 \define@key{Geom}{b4paper}[true]{\def\Geom@paper{b4paper}}
52 \define@key{Geom}{b5paper}[true]{\def\Geom@paper{b5paper}}
53 \define@key{Geom}{letterpaper}[true]{\def\Geom@paper{letterpaper}}
54 \define@key{Geom}{legalpaper}[true]{\def\Geom@paper{legalpaper}}
55 \define@key{Geom}{executivepaper}[true]{\def\Geom@paper{executivepaper}}
`papersize'
`paperwidth'
`paperheight'

56 \define@key{Geom}{papersize}{\Geom@branch{#1}{paperwidth}{paperheight}}
57 \define@key{Geom}{paperwidth}{\setlength\paperwidth{#1}%
58  \let\Geom@paper\undefined}
59 \define@key{Geom}{paperheight}{\setlength\paperheight{#1}%
60  \let\Geom@paper\undefined}
`total'
`width'
`height'
`totalwidth'
`totalheight'

61 \define@key{Geom}{total}{\Geom@branch{#1}{width}{height}}
62 \define@key{Geom}{width}{\Geom@sethtotaltrue\Geom@setwidthtrue%
63  \edef\Geom@width{#1}}
64 \define@key{Geom}{height}{\Geom@setvtotaltrue\Geom@setheighttrue%
65  \edef\Geom@height{#1}}
66 \let\KV@Geom@totalwidth\KV@Geom@width
67 \let\KV@Geom@totalheight\KV@Geom@height
`body'
`text'
`textwidth'
`textheight'

68 \define@key{Geom}{body}{\Geom@branch{#1}{textwidth}{textheight}}
69 \let\KV@Geom@text\KV@Geom@body
70 \define@key{Geom}{textwidth}{\Geom@sethtotaltrue\Geom@setwidthtrue%
71  \Geom@settextwidthtrue%
72  \edef\Geom@textwidth{#1}}
73 \define@key{Geom}{textheight}{\Geom@setvtotaltrue\Geom@setheighttrue%
74  \Geom@settextheighttrue%
75  \edef\Geom@textheight{#1}}

`scale' `hscale' `vscale'
76 \define@key{Geom}{scale}{\Geom@branch{#1}{hscale}{vscale}}
77 \define@key{Geom}{hscale}{\Geom@sethtotaltrue\edef\Geom@hscale{#1}}
78 \define@key{Geom}{vscale}{\Geom@setvtotaltrue\edef\Geom@vscale{#1}}
`margin'
`hmargin'
`vmargin'
`lmargin'
`rmargin'
`tmargin'
`bmargin'
`left'
`right'
`top'
`bottom'

79 \define@key{Geom}{margin}{\Geom@branch{#1}{lmargin}{tmargin}%
80  \Geom@branch{#1}{rmargin}{bmargin}}
81 \define@key{Geom}{hmargin}{\Geom@branch{#1}{lmargin}{rmargin}}
82 \define@key{Geom}{vmargin}{\Geom@branch{#1}{tmargin}{bmargin}}
83 \define@key{Geom}{lmargin}{\Geom@setlmargintrue\edef\Geom@lmargin{#1}}
84 \define@key{Geom}{rmargin}{\Geom@setrmargintrue\edef\Geom@rmargin{#1}}
85 \define@key{Geom}{tmargin}{\Geom@settmargintrue\edef\Geom@tmargin{#1}}
86 \define@key{Geom}{bmargin}{\Geom@setbmargintrue\edef\Geom@bmargin{#1}}
87 \let\KV@Geom@left\KV@Geom@lmargin
88 \let\KV@Geom@right\KV@Geom@rmargin
89 \let\KV@Geom@top\KV@Geom@tmargin
90 \let\KV@Geom@bottom\KV@Geom@bmargin

`divide' `hdivide' `vdivide' Provide useful ways to partition each direction of paper.

91 \define@key{Geom}{divide}{\Geom@divideParser{#1}{lmargin}{width}{rmargin}%
92  \Geom@divideParser{#1}{tmargin}{height}{bmargin}}
93 \define@key{Geom}{hdivide}{\Geom@divideParser{#1}{lmargin}{width}{rmargin}}
94 \define@key{Geom}{vdivide}{\Geom@divideParser{#1}{tmargin}{height}{bmargin}}
`offset' `hoffset' `voffset'
95 \define@key{Geom}{offset}{\Geom@branch{#1}{hoffset}{voffset}}
96 \define@key{Geom}{hoffset}{\setlength\hoffset{#1}}
97 \define@key{Geom}{voffset}{\setlength\voffset{#1}}
`headheight'
`headsep'
`footskip'
`head'
`foot'

98 \define@key{Geom}{headheight}{\Geom@noheadfalse\setlength\headheight{#1}}
99 \define@key{Geom}{headsep}{\Geom@noheadfalse\setlength\headsep{#1}}
100 \define@key{Geom}{footskip}{\Geom@nofootfalse\setlength\footskip{#1}}
101 \let\KV@Geom@head\KV@Geom@headheight
102 \let\KV@Geom@foot\KV@Geom@footskip
`marginparwidth' `marginparsep' `marginpar' To keep order-independence, if includemp is not found at this point of time, includemp is
set true.
103 \define@key{Geom}{marginparwidth}%
104  {\ifGeom@@includemp\else\Geom@includemptrue\fi%
105  \setlength\marginparwidth{#1}}
106 \define@key{Geom}{marginparsep}%
107  {\ifGeom@@includemp\else\Geom@includemptrue\fi%
108  \setlength\marginparsep{#1}}
109 \let\KV@Geom@marginpar\KV@Geom@marginparwidth
`twosideshift'
110 \define@key{Geom}{twosideshift}{\@twosidetrue\def\Geom@twosideshift{#1}}

`reset' reset option resets the modes and the includemp flag to prevent them from being inherited. This should precede all other options if it is used.

111 \define@key{Geom}{reset}[true]%%
112  {\lowercase{\expandafter\csname if#1\endcsname
113  \Geom@reset\fi}}
`verbose'
`twoside'
`includemp'
`nohead'
`nofoot'
`noheadfoot'
`landscape'
`portrait'

114 \define@key{Geom}{verbose}[true]%%
115  {\lowercase{\expandafter\csname if#1\endcsname
116  \Geom@verbosetrue\else\Geom@verbosefalse\fi}}

11

117 \define@key{Geom}{twoside}[true]%%
118  {\lowercase{\expandafter\csname if#1\endcsname
119  \@twosidetrue\@mparswitchtrue
120  \else\@twosidefalse\@mparswitchfalse\fi}}
121 \define@key{Geom}{includemp}[true]%%
122  {\Geom@@includemptrue
123  \lowercase{\expandafter\csname if#1\endcsname
124  \Geom@includemptrue\else\Geom@includempfalse\fi}}
125 \define@key{Geom}{nohead}[true]%%
126  {\lowercase{\expandafter\csname if#1\endcsname
127  \Geom@noheadtrue\else\Geom@noheadfalse\fi}}
128 \define@key{Geom}{nofoot}[true]%%
129  {\lowercase{\expandafter\csname if#1\endcsname
130  \Geom@nofoottrue\else\Geom@nofootfalse\fi}}
131 \define@key{Geom}{noheadfoot}[true]%%
132  {\lowercase{\expandafter\csname if#1\endcsname
133  \Geom@noheadtrue\Geom@nofoottrue\else
134  \Geom@noheadfalse\Geom@nofootfalse\fi}}
135 \define@key{Geom}{landscape}[true]%%
136  {\lowercase{\expandafter\csname if#1\endcsname
137  \Geom@landscapetrue\else\Geom@landscapefalse\fi}}
138 \define@key{Geom}{portrait}[true]%%
139  {\lowercase{\expandafter\csname if#1\endcsname
140  \Geom@landscapefalse\else\Geom@landscapetrue\fi}}

Package options are declared.

141 \DeclareOption{verbose}{\Geom@verbosetrue}
142 \DeclareOption{a1paper}{\setkeys{Geom}{a1paper}}
143 \DeclareOption{a2paper}{\setkeys{Geom}{a2paper}}
144 \DeclareOption{a3paper}{\setkeys{Geom}{a3paper}}
145 \DeclareOption{a4paper}{\setkeys{Geom}{a4paper}}
146 \DeclareOption{a5paper}{\setkeys{Geom}{a5paper}}
147 \DeclareOption{b1paper}{\setkeys{Geom}{b1paper}}
148 \DeclareOption{b2paper}{\setkeys{Geom}{b2paper}}
149 \DeclareOption{b3paper}{\setkeys{Geom}{b3paper}}
150 \DeclareOption{b4paper}{\setkeys{Geom}{b4paper}}
151 \DeclareOption{b5paper}{\setkeys{Geom}{b5paper}}
152 \DeclareOption{letterpaper}{\setkeys{Geom}{letterpaper}}
153 \DeclareOption{legalpaper}{\setkeys{Geom}{legalpaper}}
154 \DeclareOption{executivepaper}{\setkeys{Geom}{executivepaper}}
155 \DeclareOption{portrait}{\Geom@landscapefalse}
156 \DeclareOption{landscape}{\Geom@landscapetrue}
157 \DeclareOption{twoside}{\@twosidetrue}
158 \DeclareOption{nohead}{\Geom@noheadtrue}
159 \DeclareOption{nofoot}{\Geom@nofoottrue}
160 \DeclareOption{noheadfoot}{\Geom@noheadtrue\Geom@nofoottrue}
161 \DeclareOption{includemp}{\Geom@@includemptrue\Geom@includemptrue}
162 \DeclareOption{dvips}{\AtBeginDocument{\AtBeginDvi{%
163 \special{papersize=\the\paperwidth,\the\paperheight}}}}
164 \DeclareOption*{\PackageWarningNoLine{geometry}
165  {Unknown option `\CurrentOption'}}

portrait is a default option.

166 \ExecuteOptions{portrait}

A local configuration file may define more options. If a site wants a default paper, it needs

 to put \ExecuteOptions{a4paper} in a geometry.cfg file.
167 \InputIfFileExists{geometry.cfg}{}{}

Options are processed in the order that they appear in the option-lists. First the global options, and then the local ones.

168 \ProcessOptions*

\Geom@checkbool \Geom@checkdef Macros for printout of page layout parameters.

169 \def\Geom@checkbool#1{%
170  \csname ifGeom@#1\endcsname #1\else\fi}
171 \def\Geom@checkdef#1{%
172  \@ifundefined{Geom@#1}{---}{\@nameuse{Geom@#1}}}

\Geom@det@one Determine #4 by #1(paperwidth or paperheight), #2 and #3.

173 \def\Geom@det@one#1#2#3#4{% determine #4.
174  \setlength\@tempdima{\@nameuse{paper#1}}
175  \setlength\@tempdimb{\@nameuse{Geom@#2}}
176  \addtolength\@tempdima{-\@tempdimb}
177  \setlength\@tempdimb{\@nameuse{Geom@#3}}
178  \addtolength\@tempdima{-\@tempdimb}
179  \ifdim\@tempdima<\z@
180  \Geom@warning{`#4' results in NEGATIVE (\the\@tempdima).
181  ^^J\@spaces Parameters of `#2' and `#3' should be shortened}
182  \fi
183  \expandafter\edef\csname Geom@#4\endcsname{\the\@tempdima}}

\Geom@det@two Determine #2 and #3 by #1(paperwidth or paperheight) and #1(width or height).

184 \def\Geom@det@two#1#2#3{% determine #2 and #3.
185  \setlength\@tempdima{\@nameuse{paper#1}}
186  \setlength\@tempdimb{\@nameuse{Geom@#1}}
187  \addtolength\@tempdima{-\@tempdimb}
188  \divide\@tempdima\tw@
189  \ifdim\@tempdima<\z@
190  \Geom@warning{`#2' and `#3' result in NEGATIVE (\the\@tempdima).
191  ^^J\@spaces Parameter for `#1' should be shortened}
192  \fi
193  \expandafter\edef\csname Geom@#2\endcsname{\the\@tempdima}
194  \expandafter\edef\csname Geom@#3\endcsname{\the\@tempdima}}

\Geom@det@all Determine directional partition.

195 \def\Geom@det@all[#1]#2#3#4{%
196  \Geom@checknum\z@
197  \if#1h
198  \ifGeom@setlmargin\advance\Geom@checknum4\relax\fi
199  \ifGeom@sethtotal \advance\Geom@checknum2\relax\fi
200  \ifGeom@setrmargin\advance\Geom@checknum1\relax\fi
201  \else
202  \ifGeom@settmargin\advance\Geom@checknum4\relax\fi
203  \ifGeom@setvtotal \advance\Geom@checknum2\relax\fi
204  \ifGeom@setbmargin\advance\Geom@checknum1\relax\fi
205  \fi
206  \ifcase\Geom@checknum             % 0:(*,*,*)
207  \if#1h
208  \Geom@warning{Horizontal partition is set default\space
209  (hscale=\Geom@Dhscale)}
210  \edef\Geom@width{\Geom@Dhscale\paperwidth}
211  \else
212  \Geom@warning{Vertical partition is set default\space
213  (vscale=\Geom@Dvscale)}
214  \edef\Geom@height{\Geom@Dvscale\paperheight}
215  \fi
216  \Geom@det@two{#2}{#3}{#4}
217  \or                               % 1:(*,*,S) goto (5)
218  \Geom@warning{`#2' and `#3' not unique. #3 <= #4}
219  \expandafter\edef\csname Geom@#3\endcsname{\@nameuse{Geom@#4}}
220  \Geom@det@one{#2}{#3}{#4}{#2}
221  \or\Geom@det@two{#2}{#3}{#4}      % 2:(*,S,*)
222  \or\Geom@det@one{#2}{#2}{#4}{#3}  % 3:(*,S,S)

223  \or                               % 4:(S,*,*) goto (5)
224  \Geom@warning{`#2' and `#4' not unique. #4 <= #3}
225  \expandafter\edef\csname Geom@#4\endcsname{\@nameuse{Geom@#3}}
226  \Geom@det@one{#2}{#3}{#4}{#2}
227  \or\Geom@det@one{#2}{#3}{#4}{#2}  % 5:(S,*,S)
228  \or\Geom@det@one{#2}{#2}{#3}{#4}  % 6:(S,S,*)
229  \or                               % 7:(S,S,S) goto (5)
230  \Geom@warning{Redundant specification in `#1'-direction.
231  ^^J\@spaces `#2' (\@nameuse{Geom@#2}) is ignored}
232  \Geom@det@one{#2}{#3}{#4}{#2}
233  \else\fi}

\Geom@divideParser The macro for parsing (h,v)divide options.

234 \def\Geom@divideParser#1#2#3#4{%
235  \def\Geom@star{*}
236  \@tempcnta\z@
237  \@for\Geom@tmp:=#1\do{%
238  \expandafter\KV@@sp@def\expandafter\Geom@frag\expandafter{\Geom@tmp}
239  \edef\Geom@value{\Geom@frag}
240  \ifcase\@tempcnta\relax% cnta == 0
241  \edef\Geom@key{#2}
242  \or    \edef\Geom@key{#3}
243  \else  \edef\Geom@key{#4}
244  \fi
245  \@nameuse{Geom@set\Geom@key false}
246  \ifx\empty\Geom@value\else
247  \ifx\Geom@star\Geom@value\else
248  \setkeys{Geom}{\Geom@key=\Geom@value}
249  \fi\fi
250  \advance\@tempcnta\@ne

251 }

252  \let\Geom@star\relax}

\Geom@branch The macro for ‘branching’ or duplicating a option.

253 \def\Geom@branch#1#2#3{%
254  \@tempcnta\z@
255  \@for\Geom@tmp:=#1\do{%
256  \KV@@sp@def\Geom@frag{\Geom@tmp}
257  \edef\Geom@value{\Geom@frag}
258  \ifcase\@tempcnta\relax% cnta == 0
259  \setkeys{Geom}{#2=\Geom@value}
260  \or% cnta == 1
261  \setkeys{Geom}{#3=\Geom@value}
262  \else\fi
263  \advance\@tempcnta\@ne

264 }

265  \ifnum\@tempcnta=\@ne
266  \setkeys{Geom}{#2=\Geom@value}
267  \setkeys{Geom}{#3=\Geom@value}
268  \fi}

Various paper size are defined.

269 \@namedef{Geom@a1paper}{%
270 \setlength\paperwidth{595mm}\setlength\paperheight{841mm}}
271 \@namedef{Geom@a2paper}{%
272 \setlength\paperwidth{420mm}\setlength\paperheight{595mm}}
273 \@namedef{Geom@a3paper}{%
274 \setlength\paperwidth{297mm}\setlength\paperheight{420mm}}
275 \@namedef{Geom@a4paper}{%
276 \setlength\paperwidth{210mm}\setlength\paperheight{297mm}}
277 \@namedef{Geom@a5paper}{%

278 \setlength\paperwidth{149mm}\setlength\paperheight{210mm}}
279 \@namedef{Geom@b1paper}{%
280 \setlength\paperwidth{707mm}\setlength\paperheight{1000mm}}
281 \@namedef{Geom@b2paper}{%
282 \setlength\paperwidth{500mm}\setlength\paperheight{707mm}}
283 \@namedef{Geom@b3paper}{%
284 \setlength\paperwidth{353mm}\setlength\paperheight{500mm}}
285 \@namedef{Geom@b4paper}{%
286 \setlength\paperwidth{250mm}\setlength\paperheight{353mm}}
287 \@namedef{Geom@b5paper}{%
288 \setlength\paperwidth{176mm}\setlength\paperheight{250mm}}
289 \@namedef{Geom@letterpaper}{%
290 \setlength\paperwidth{8.5in}\setlength\paperheight{11in}}
291 \@namedef{Geom@legalpaper}{%
292 \setlength\paperwidth{8.5in}\setlength\paperheight{14in}}
293 \@namedef{Geom@executivepaper}{%
294 \setlength\paperwidth{7.25in}\setlength\paperheight{10.5in}}

\Geom@showParam The macro for typeout of geometry status and parameters.

295 \def\Geom@showParam{%
296  \typeout{----------------------- Geometry parameters}
297  \typeout{mode: \Geom@checkbool{landscape}\space
298  \Geom@checkbool{nohead}\space
299  \Geom@checkbool{nofoot}\space
300  \Geom@checkbool{includemp}\space
301  \if@twoside twoside\space\fi}
302  \@ifundefined{Geom@paper}{}{\typeout{paper: \Geom@paper}}
303  \typeout{hdivide: \Geom@checkdef{lmargin}, %
304  \Geom@checkdef{width}, \Geom@checkdef{rmargin}}
305  \typeout{vdivide: \Geom@checkdef{tmargin}, %
306  \Geom@checkdef{height}, \Geom@checkdef{bmargin}}
307  \if@twoside
308  \typeout{twosideshift: \Geom@twosideshift}
309  \fi
310  \typeout{----------------------- LaTeX parameters}
311  \typeout{\string\paperwidth\space\space\the\paperwidth}
312  \typeout{\string\paperheight\space\the\paperheight}
313  \typeout{\string\textwidth\space\space\the\textwidth}
314  \typeout{\string\textheight\space\the\textheight}
315  \typeout{\string\oddsidemargin\space\space\the\oddsidemargin}
316  \typeout{\string\evensidemargin\space\the\evensidemargin}
317  \typeout{\string\topmargin\space\space\the\topmargin}
318  \typeout{\string\headheight\space\the\headheight}
319  \typeout{\string\headsep\@spaces\the\headsep}
320  \typeout{\string\footskip\space\space\space\the\footskip}
321  \ifGeom@includemp
322  \typeout{\string\marginparwidth\space\the\marginparwidth}
323  \typeout{\string\marginparsep\space\space\space\the\marginparsep}
324  \fi
325  \typeout{\string\hoffset\space\the\hoffset}
326  \typeout{\string\voffset\space\the\voffset}
327  \typeout{(1in=72.27pt, 1cm=28.45pt)}
328  \typeout{-----------------------------------------}}
329 \AtBeginDocument{%
330  \ifGeom@verbose
331  \Geom@showParam
332  \fi}

\geometry The user interface \geometry{⟨key-val parameters⟩} is defined here.

333 \def\geometry#1{%

{\w \atop \h} \w and \h are abbreviations for \paperwidth and \paperheight respectively. They are valid only in the argument of \geometry.

334  \@ifundefined{w}{\let\Geom@ow\relax}{\let\Geom@ow\w}
335  \@ifundefined{h}{\let\Geom@oh\relax}{\let\Geom@oh\h}
336  \let\w\paperwidth
337  \let\h\paperheight

Initialization of switches and parameters.

338  \Geom@sethtotalfalse
339  \Geom@setvtotalfalse
340  \Geom@setwidthfalse
341  \Geom@setheightfalse
342  \Geom@setlmarginfalse
343  \Geom@setrmarginfalse
344  \Geom@settmarginfalse
345  \Geom@setbmarginfalse
346  \setlength\hoffset{0pt}
347  \setlength\voffset{0pt}
348  \setlength\headheight{\Geom@Oheadheight}
349  \setlength\headsep{\Geom@Oheadsep}
350  \setlength\footskip{\Geom@Ofootskip}
351  \def\Geom@twosideshift{\Geom@Dtwosideshift}

The argument is processed here.

352  \setkeys{Geom}{#1}

If paper option is specified, the predefined paper dimensions are set.

353  \@ifundefined{Geom@paper}{}{\@nameuse{Geom@\Geom@paper}}

If landscape option is specified, the paper orientation is changed to landscape.

354  \ifGeom@landscape
355  \setlength\@tempdima{\paperwidth}
356  \setlength\paperwidth{\paperheight}
357  \setlength\paperheight{\@tempdima}
358  \fi

If nohead option is specified, the vertical spaces for the head of page are all set to 0pt. If

 nofoot, the \footskip is set 0pt.
359  \ifGeom@nohead
360  \setlength\headheight{0pt}
361  \setlength\headsep{0pt}
362  \fi
363  \ifGeom@nofoot
364  \setlength\footskip{0pt}
365  \fi

The width of the total body \Geom@width is determined.

366  \ifGeom@sethtotal
367  \ifGeom@setwidth
368  \ifGeom@settextwidth
369  \setlength\@tempdima{\Geom@textwidth}
370  \ifGeom@includemp
371  \addtolength\@tempdima{\marginparwidth}
372  \addtolength\@tempdima{\marginparsep}
373  \fi
374  \edef\Geom@width{\the\@tempdima}
375  \fi
376  \else
377  \edef\Geom@width{\Geom@hscale\paperwidth}
378  \fi
379  \fi

The height of the total body \Geom@height is determined.

380  \ifGeom@setvtotal
381  \ifGeom@setheight
382  \ifGeom@settextheight
383  \setlength\@tempdima{\Geom@textheight}
384  \addtolength\@tempdima{\headheight}
385  \addtolength\@tempdima{\headsep}
386  \addtolength\@tempdima{\footskip}
387  \edef\Geom@height{\the\@tempdima}
388  \fi
389  \else
390  \edef\Geom@height{\Geom@vscale\paperheight}
391  \fi
392  \fi

The horizontal and vertical partitionings are determined here.

393  \Geom@det@all[h]{width}{lmargin}{rmargin}
394  \Geom@det@all[v]{height}{tmargin}{bmargin}

\textwidth is calculated.

395  \setlength\textwidth{\Geom@width}
396  \ifGeom@includemp
397  \addtolength\textwidth{-\marginparwidth}
398  \addtolength\textwidth{-\marginparsep}
399  \fi

\textheight is calculated.

400  \setlength\textheight{\Geom@height}
401  \addtolength\textheight{-\headheight}
402  \addtolength\textheight{-\headsep}
403  \addtolength\textheight{-\footskip}

\topmargin is calculated here.

404  \setlength\topmargin{\Geom@tmargin}
405  \addtolength\topmargin{-1in}
 \oddsidemargin and \evensidemargin are finally obtained.
406  \setlength\oddsidemargin{\Geom@lmargin}
407  \addtolength\oddsidemargin{-1in}
408  \if@twoside
409  \setlength\evensidemargin{\Geom@rmargin}
410  \addtolength\evensidemargin{-1in}
411  \setlength\@tempdima{\Geom@twosideshift}
412  \addtolength\oddsidemargin{\@tempdima}
413  \addtolength\evensidemargin{-\@tempdima}
414  \ifGeom@includemp
415  \if@mparswitch
416  \setlength\@tempdima{\marginparwidth}
417  \addtolength\@tempdima{\marginparsep}
418  \addtolength\evensidemargin{\@tempdima}
419  \fi
420  \fi
421  \else
422  \setlength\evensidemargin{\oddsidemargin}
423  \fi

The local abbreviations \w and \h are replaced by the original definitions or \relax if these are not predefined.

424  \let\w\Geom@ow
425  \let\h\Geom@oh

426 }

A hack for silent execution of the default geometry setting.

427 \let\Geom@warning\@gobble

The default geometry command is executed in silent mode.

428 \geometry{}

The macro for typeout of warning is defined.

\Geom@warning
429 \def\Geom@warning#1{%
430  \ifGeom@verbose
431  \typeout{^^JWarning(geometry):\space #1.}
432  \fi}

433 ⟨/package⟩