Zum Inhalt springen

Update: September 2021

Some 4 years after it was first published, this article has been edited, renamed and republished to reduce its size and re-focus the scope of topics covered. The article originally included a LuaTeX-based LaTeX template which relied on old Overleaf V1 features. That template is now obsolete and no longer available.

Note: If you don’t need, or want, to understand finer details of LaTeX page layout, the Overleaf article Page size and margins explains the geometry package and is likely to be of more interest.

Introduction

Have you ever struggled to configure a book layout with LaTeX—setting the paper size, book page size (trim size) and margins? It can be tricky, even though there are many packages to assist with this task—including the excellent geometry package. (La)TeX uses nearly a dozen values to fully specify the page layout for publications that have different margins for left- and right-hand pages:

  • \hoffset, \voffset, \oddsidemargin, \topmargin, \headheight, \headsep, \textheight, \textwidth, \marginparsep, \marginparwidth, \footskip

Typically, these parameters are set through commands provided by packages or templates—such as those distributed by book publishers. However, at times you might want to understand what is going on “behind the scenes”—perhaps you need a greater degree of control for a particular type of document you want to create.

In this post we explore the relationship between LaTeX’s model of the page and the conventional model used within the world of print and design. Using a set of Google Slides, which contain detailed page-layout illustrations, we show, step-by-step, how to formulate some very simple equations which provide a link between LaTeX’s layout model and a typical specification that might be produced by a book designer or print-on-demand company. Using those equations you can, if you wish, directly calculate values for LaTeX’s parameters to implement your preferred book layout.

Short notes on pdfTeX and LuaTeX/LuaHBTeX

Note that in addition to the \hoffset and \voffset parameters listed above, pdfTeX also uses the parameters \pdfhorigin and \pdfvorigin. Traditionally, TeX engines output .dvi files which were converted to PostScript or PDF by software which assumed the page origin was at located at 1 inch (25.4mm) from the left of the page and 1 inch (25.4mm) from the top of the page. The values of the \hoffset and \voffset parameters are relative to that (1 inch, 1 inch) position. The pdfTeX parameters are slightly different insofar that they are relative to the top-left corner, i.e., at (0mm, 0mm). So, for example, if you set \pdfhorigin=30mm it is equivalent to setting \hoffset to 30–25.4=4.6mm because \hoffset is relative to a position that is already 25.4mm from the left of the page. Equally, an \hoffset value of 0mm is equivalent to \pdfhorigin=25.4mm. In the following discussions/diagrams we will use the parameters \hoffset and \voffset.

LuaTeX/LuaHBTeX

LuaTeX/LuaHBTeX also indirectly support \pdfhorigin and \pdfvorigin but, for compatibility with pdfTeX, those commands must be defined as follows (see Section 3 of The LuaTeX Referemce Manual):

\edef\pdfhorigin{\pdfvariable horigin}
\edef\pdfvorigin{\pdfvariable vorigin}

What is our objective?

The theme of this article, and the purpose of the resources we have provided, is based on the following objectives:

  1. We want to implement a layout specification provided by, for example, a book designer or publisher who does not use or support LaTeX—or perhaps we need to follow a specification provided by a print-on-demand company.
  2. We want to use the traditional book measurements (paper size, trim size and page margins) contained within the designer’s specification and convert them into parameters and values that LaTeX understands and can use to replicate the designer’s layout.
  3. We want our book page to be horizontally and vertically centred on the paper size we have chosen— i.e., centred within the area of the PDF pages created by LaTeX. We also want to choose an arbitrary paper size and not be restricted to a few standard options (A4, US Letter and so forth).

Quick reminder: How do you set the paper size?

LuaTeX, XeTeX and pdfTeX provide two commands that let you control the “paper size” of the PDF document they produce:

  • \pdfpagewidth
  • \pdfpageheight

Knowing that these commands represent the size of our paper we can now draw a diagram to show what we are trying to achieve:

Note that ΔX and ΔY are the values needed to centre the book page on the paper area—they are discussed in the Google Slides. From the diagram above you can see:

  • ΔX=½(\pdfpagewidth − book-page-width)
  • ΔY=½(\pdfpageheight − book-page-height)

The above diagram is also included in the Google Slides and is used as the starting point for arriving at the page-layout equations.

An aside: LuaTeX

LuaTeX no longer directly supports \pdfpagewidth or \pdfpageheight but now uses two new primitives called \pagewidth and \pageheight. Backwards compatibility can be achieved through \let\pdfpagewidth\pagewidth and \let\pdfpageheight\pageheight. Interested readers can find more details in LaTeX News (Issue 24, February 2016) and, of course, the official LuaTeX documentation.

Resources in this post

Here at Overleaf we like to try out new ideas so, in this post, we have included a range of resources which we hope will be useful:

  • Two sets of Google Slides: These slide sets contain identical content but one has animations and the other does not (some people prefer to view slides that don’t contain any animation). You can also download them in PDF format. The slides provide a very brief introduction to the basics of book page layout and explore the relationship between LaTeX’s page model and the one used in conventional print and design. The last few slides show how to arrive at simple equations which can be used to use convert a set of traditional measurements (page width/height and margins) into equivalent LaTeX parameter values to reproduce your book’s layout in LaTeX.
  • Page-layout diagrams: The Google Slides contain detailed page-layout diagrams which are used to formulate some simple equations to calculate various LaTeX parameters. If you would like to study those illustrations in more detail we’ve provided PDF versions for you to download.

How to use this article’s resources

The readership of this article is likely to have a spectrum of experience in using LaTeX so we felt it was preferable to provide a range of resources for readers to choose from—based on your personal experience, interests or preferences. We hope these resources are useful and meet the needs and interests of Overleaf’s LaTeX community.

There’s no defined order in which to use these resources but our suggestion would be as follows:

  1. view the Google Slides;
  2. (optional): download and study the page layout diagrams;

Step 1: View or download (in PDF) the Google Slides

The final slide (shown below) summarizes the equations formulated during the presentation.

For the convenience of readers we provide three options for viewing the slides:

  1. slides with animations;
  2. slides without animations;
  3. slides in PDF format for offline viewing or printing.

Step 2 (optional): Download and study the page-layout diagrams

If you would like to explore the page-layout diagrams in more detail, there is a link at the end of this article to download a PDF file which contains a double-page spread (facing pages) version of the diagrams contained in the Google Slides.

Notes on the page-layout parameters and equations

If you look at the equations presented in the Google Slides you might observe they contain many variables; consequently, there are multiple ways to use the equations depending on which LaTeX parameter values you want to calculate and which ones you’d like to set yourself. Let’s take a look at one of the graphics (and relevant equations) contained in the Google Slides:

Clearly, you need to decide which LaTeX parameter values you want to calculate and which ones you will provide as the starting point. One way to proceed is as follows:

  1. Set \hoffset and \voffset to 0mm (with \pdfhorigin=1in and \pdfvorigin=1in, if necessary)
  2. Use values for the following LaTeX parameters which affect the book page width:
    • \marginparsep
    • \marginparwidth
  3. Set preferred values for the following LaTeX parameters which affect the book page height:
    • \headheight
    • \headsep
    • \footskip
  4. Set values for your preferred paper size together with the desired width and height of the book page, plus the four book margin values you would like to use.
  5. Calculate the following LaTeX values to implement your book layout (centred on the paper size you selected):
    • \evensidemargin, \oddsidemargin, \textwidth, \textheightand \topmargin

Article resources

Here we list a number of resources that we have prepared to help you better understand the LaTeX page-layout parameters. The Google Slides provide details of the simple equations that you can, if you wish, use directly to calculate parameter values to suit the needs of any document.

Google Slides: With animations

Google Slides: Without animations

Google Slides: Converted to PDF

If you prefer to view the slides as a PDF document, or wish to print them out, you can download the slides in PDF format.

Download page-layout diagrams

If you want to study the page-layout diagrams in more detail, here is a double-page spread (i.e., facing pages) in PDF format.

In conclusion

We hope this article is useful and has provided some useful background information for exploring page layout using LaTeX. As always, we are delighted to hear from readers so do please contact us with your comments and feedback.

Happy (La)TeXing!

Overleaf guides

LaTeX Basics

Mathematics

Figures and tables

References and Citations

Languages

Document structure

Formatting

Fonts

Presentations

Commands

Field specific

Class files

Advanced TeX/LaTeX