Outils pour utilisateurs

Outils du site


issue207:latex

Ceci est une ancienne révision du document !


Welcome back to another adventure with Latex. This time we are going to explore the geometry package. Geometry is a page layout package. The user sets some dimensions of objects on each page of the document and the package can calculate the remaining values. Values are specified using key/value pairs which is advantageous for both clarity and uniformity with other packages. In most cases, there are a number of different sets of settings which can produce the same result. For example, setting the paper size, margin ratio and the left margin will determine the right margin; or setting the paper size, margin ratio and right margin will determine the left margin. Any key setting which violates one (or more) of the others will generate a warning and geometry will ignore one of the key settings.

Before we continue, a few words about paper sizes, which are the controlling factors in page design. Most countries in the world use A4 paper as the default paper size. Canada, the Philippines, and the USA use a default paper size called “letter”. A4 is part of a series of ISO-recognized paper sizes. A0 is the largest, an A0 sheet is one square metre (841mm x 1189mm, rounded to the closest mm). Each sheet size is exactly half of the previous largest size, actual size is determined by folding the larger size parallel to its shorter sides. So A1 is ½ of A0, A2 is ½ of A1, etc. A4 is 210mm x 297mm. Letter size is 216mm x 279mm, larger in the short dimension (usually the horizontal dimension). and smaller in the long dimension. The aspect ratio of all paper sizes generated from A0 is √2 or 1:1.41421 (short:long). The aspect ratio of letter size is 1:1.29.

The geometry package also accepts several other less frequently used paper sizes: b0paper – b6paper, c0paper – c6paper, b0j – b6j (Japanese sizes), as well as letterpaper (216mm x 279mm), legalpaper (216mm x 356mm), and executivepaper (184mm x 267mm) to accommodate North American standards. It is also possible to set paperwidth and paperheight to specific dimensions if necessary or desirable.

Geometry supports either portrait (short dimension horizontal), or landscape (long dimension horizontal) orientation for paper. Portrait is default, and need not be specified. Geometry does not support changing orientation for specific pages in a document. If that is required then the lscape package is also required.

Geometry supports two-sided printing with the twoside Boolean key. If a document is to be printed two-sided, it may require extra space for the inner margin to allow for the space required for binding. This key is bindingoffset – which adds the specified amount to the inner margin.

I have set up some example pages to show a small part of the flexibility of the geometry package. Example one is a fairly standard page: [paper=letterpaper, lmargin=36mm, marginratio=1:1, headheight=25mm]. Since the left margin is set to 32.5mm and the margin ratio is 1:1, the right margin will also be 32.5mm. (These settings are comparable to reasonably acceptable defaults for word processing.

One magazine I subscribe to has a final paper size of 19cm x 26cm. It has two columns of text printed on both sides of the page. The outside margin is 2.5cm, the inside margin is also 2.5cm including the space required for binding. The top margin is 2.3cm and the bottom margin is 3.3cm. The footer appears 2.5cm below the text block. Geometry does not control what happens inside the text block, so setting for two columns and setting the space between columns is in the control of another package. Settings for this magazine could be: Example 2 settings: [paperheight=26cm, paperwidth=19cm, top=2.3cm, bottom=2.3cm, left=2.5cm, right=2.5cm].

This combination of settings is only one way to specify the layout for this magazine. The page designer could also work from letter size paper or A4 paper, and use the four margins to control the size of the text block. There are often two or more ways to use the many settings available in the geometry package to specify a layout.

Remember the goal of Latex / Tex is to generate a standard PDF file which can be read on screen, or printed. When doing page design, it is important to know what the readers expect. It may be desirable for some design elements to be different if the document is to be read on screen compared to being printed.

Changing geometry mid document (1)

\newgeometry{options} changes the page layout mid-document. \newgeometry is almost similar to \geometry except that \newgeometry disables all the options specified by \usepackage and \geometry in the preamble and skips paper size-related options.

\restoregeometry restores the page layout specified in the preamble. This command has no arguments. \savegeometry{name} saves the page dimensions as ‘name’ where you put this command. \loadgeometry{name} loads the page dimensions saved as ’name’.

Types of options for geometry are: Boolean (true – false), one option, (key=value) two option key={value1,value2}, three option (key={value1,value2, value3}. Two value options can be shortened to one value if both values are identical. For three-value options, all options must have a value or a null, (use * for null). You should specify at least one value. Setting all three values to null makes no sense.

Options available

There are five pages of options in five different categories in the documentation for the geometry package. The ones in this article are only a few of the common ones.

The papersize category includes all of the sizes I discussed at the beginning of this article plus others. Paperwidth and paperheight can be given using the papersize parameter with two values: width, height. The papersize category includes portrait, landscape, and screen. Screen is a special size for presentations: 225mm x 180mm. This gives an aspect ratio of 1.25:1 or 5:4 which is close to the old standard for screens of 640×480 or 4:3.

The layout size group has a small number of options useful to set layout sizes which are not dependent on paper size. This is another set of options for adjustments for the magazine whose final size is smaller than standard letter paper.

Next is a long list of parameters in the body size group. (Body refers to the text body, the container for the contents of the article, book, journal, etc.) This group is followed by margin size. I hope it is obvious that body size and margin size are dependent on each other. It is often possible to get the desired body size using appropriate margin sizes and vice versa.

Finally, there is a group called native size. These options can override the defaults built into Latex. For example, the default spaces allocated for headers and footers can be eliminated. For another example, look at either of the two images. There is space set aside in the right margin for margin notes (or outside margin in two-sided layouts). Using the reversemarginpar instruction puts that space in the left margin (or inside margin in two-sided layouts).

Changing geometry mid-document (2)

The newgeometry command allows changing all options in the geometry package except page orientation (portrait, landscape) and paper size: • If used it must appear after the \begin{document} command. • It can contain changes to one or more of the parameters set originally in the preamble. • The newgeometry command can be issued more than once in a document. • To return to the original settings, issue the command \restoregeometry (which takes no parameters). • Both \newgeometry and \restoregeometry issue \newpage commands before changing the page layout.

As mentioned above, it is also possible to build a collection, a library of geometry “styles” using the \savegeometry{name}. For example, assume you regularly published PDF files using two or more different page layouts. Assume they are called L1 and L2. Start the document in the usual way and include the geometry package. After the \begin{document} command, issue the appropriate \loadgeometry{L1} command for an L1 layout. No need to remember what the various layout dimensions are. This ability would also allow for quick and easy use of different page layouts for pages with illustrations and pages without illustrations in the same document, for example.

Documentation

I strongly urge you to read through the documentation for the geometry package (as I have done for all packages I have discussed). The first 17 pages contain all of the information most users will need. The rest of the 42 pages gives the code and explanations. Pages 16-17 contain eleven annotated examples from simple to complex. There is probably at least one of them that can be the base for the page layout you wish to use.

Special note:

To generate views of page layouts like those in this article, the following code is very useful. Place it in the preamble, i.e. before the \begin{document} instruction. This needs to be used with each command on a separate line; otherwise any command immediately after a percent sign will be treated as a comment – which will cause errors.

\usepackage{layouts} \newcommand\showpage{%

\setlayoutscale{0.5}%
\setlabelfont{\large}%
\printheadingsfalse
\printparametersfalse
\currentpage\pagedesign}

Put any parameters for the geometry package below these layouts package commands. In the body of the document, use the \showpage command to generate the view of the layout. If you set the layout scale to 1, you will get an image that will be the finished size of the layout design. It can be saved as a PDF file and printed if desired. However the image will be shown or printed inside the margins of a standard page, and so will probably flow past the existing right and bottom margins.

Thanks again for reading and following along in my adventures with Latex. So far, it has been not only interesting but also educational. I have learned a lot and I hope you have too. Talk to you again in the next issue.

issue207/latex.1722068629.txt.gz · Dernière modification : 2024/07/27 10:23 de auntiee