Featured Post

We've moved to tex.my!

It’s been great writing on Blogger.com, but we’ve decided to move to a new platform, thanks to some valuable help from a great, great friend...

Thursday, October 29, 2009

Setting page size and margins

There's quite a bit of interest in the .tex code behind the Grid Computing Cluster report, but I think posting the raw code in its entirety would be a bit too overwhelming to quickly glean useful tips from it. (Also to avoid getting into any issues with my university... etc...)

So instead, I'll be doing a series of short posts on how I achieved certain effects and book design, starting with this one. It's probably faster for people to "zero-in" on what they need. ;-) Posts in this series will be tagged "book design". But before you implement your next major book project with LaTeX, do check with your printing company about the printing process used. If you'll be using on-demand laser printing, everything should go fine since the RGB colour model of your PDF should be adequate. However, if you're going with offset printing, your printing company will most likely prefer CMYK colour model to be used instead, and I haven't quite figured out how to tweak that perfectly with (pdf)LaTeX. In our case, only the book cover was printed with offset printing, and the effect was acceptable — so that ended well...

IMPORTANT DISCLAIMER: I am NOT a graphics designer, so my choice of colours/illustrations/etc probably sucks. Don't shoot me. :-)

Now there are multiple ways to achieve the same effect in LaTeX (that's FOSS for you). For this report, I've decided to use the memoir document class, which incorporates the functionalities of many other packages. (Do take some time to browse or search through the excellent manual with texdoc or mthelp.)

The flowfram package looks like a very interesting solution for designing dynamic layout, but I didn't find out about it until too late into my own project. Do find some time to look at it yourself. If you want to go with the standard document classes (report, book) or the koma-script classes, I'll indicate what extra packages you'll need where relevant.

In this first post we'll just look at how (custom) page sizes and margins can be specified. Basically my page design is:

  • Stock paper size is 303mm x 216mm. The stock paper is the raw original paper that a commercial printer will print the page on, which will be trimmed down to the page size
  • Page size is A4 i.e. 297mm x 210mm.
  • The printer advised us to leave a good 10mm from the page edges around any printed text.
  • I decided the main typeblock will be 20mm from the top, bottom and spine (inner) edge of the page, and 15mm from the outer edge.
  • Also, the running header should occupy the height of a line of text, 7mm from the top edge of the typeblock. Whereas the baseline of the running footer is 7mm from the bottom edge of the typeblock.

These are not necessarily good measurements for an aesthetically-pleasing book design, but more because I was trying to strike a balance between aesthetics and to fit everything in (Lesson: Get in touch with the printing company early to check with their printing specifications per minimum page margins, etc!)

These can be implemented using commands from the memoir class. (The notion of 'stock', although a common concept in publishing and printing industries, is only available in memoir, not in the standard document classes.)

\documentclass[twoside]{memoir}

%% The stock paper size
\setstocksize{303mm}{216mm}

%% The 'real' page size
\settrimmedsize{297mm}{210mm}{*}

%% The stock paper will be trimmed 3mm from the
%% top edge and 3mm from the left edge

\settrims{3mm}{3mm}

%% Spine and trim page margins from main typeblock
\setlrmarginsandblock{20mm}{15mm}{*}

%% Top and bottom page margins from main typeblock
\setulmarginsandblock{20mm}{20mm}{*}

%% Header occupies height of a single line;
%% Bottom edge of footer is 7mm from bottom edge
%% of typeblock

\setheadfoot{\baselineskip}{7mm}

%% Bottom edge of header is 7mm from top edge of
%% typeblock

\setlength\headsep{7mm}

%% Apply and enforce layout
\checkandfixthelayout


In my case, due to some later issues with colouring the 3mm bleeding edges too (as per our printing company's request), I decided to make the trimmed page size the same as my stock size and increased the page margins instead:

\documentclass[twoside]{memoir}

%% Custom stock paper and page size
\setstocksize{303mm}{216mm}
\settrimmedsize{\stockheight}{\stockwidth}{*}

%% Adjust margins accordingly to achieve
%% same previous layout

\setlrmarginsandblock{23mm}{18mm}{*}
\setulmarginsandblock{23mm}{23mm}{*}

\setheadfoot{\baselineskip}{7mm}
\setlength\headsep{7mm}

\checkandfixthelayout


If you just need to print on exactly A4-sized paper, you can forget about setting the stock and trimmed size explicitly and just do

\documentclass[a4paper,twoside]{memoir}

\setlrmarginsandblock...
\setulmarginsandblock...
...
\checkandfixthelayout


One last thing: if you're not using the memoir class, you can still change the page margins via a high-level interface with the geometry package:

\documentclass{article}
\usepackage{geometry}
\geometry{
   paperwidth=216mm, paperheight=303mm,
   left=23mm,  %% or inner=23mm
   right=18mm, %% or outer=18mm
   top=23mm, bottom=23mm,
   headheight=\baselineskip,
   headsep=7mm,
   footskip=7mm
}



Again, if you're just going to print on A4 (or letter) paper, you can just do
\usepackage[a4paper]{geometry}
\geometry{
   left=20mm,  %% or inner=20mm
   right=15mm, %% or outer=15mm
   top=20mm, bottom=20mm,
   headheight=\baselineskip,
   headsep=7mm,
   footskip=7mm
}


i.e. just pass the a4paper option to the geometry package; there's then no need to set the paper height and width explicitly.

8 comments:

  1. I have the following question:
    I would like to resize the dimensions of my page, keeping all proportions fixed (i.e. size of fonts compared to width of raws, number of raws per page, etc.). Any idea how do I do that for \documentclass{book}?

    ReplyDelete
  2. Hi ofer,

    If I understand correctly, do you mean you'd like to re-scale your page? Similar to photocopying your original page but at 75% of the original size? (Since you mention the font size) AFAIK there's no easy way to achieve that esp. for ratio of font size to text width.

    If you just need to resize your paper *size* but the main typeblock (area occupied by main text block) remains the same size, then you can just adjust the left, right, top, bottom margins accordingly with the geometry package.

    If you're looking for a solution to rescale your page (like photocopying to 75% of original page) a quick fix would be to use the pdfpages package. It lets you include specific pages from a PDF file with scaling options.

    ReplyDelete
  3. Indeed, I am looking for a method to rescale my page. I'll take a look at the pdfpages package. Thanks a lot!

    ReplyDelete
  4. dear Ofer:

    How to print 2 pages on 1 sheet of paper, on the landscape mode? Thanks

    ReplyDelete
  5. i mean using the geometry package since im already using it in my book

    ReplyDelete
  6. Sufi, try something similar to this (using the pdfpages package):

    \documentclass[a4paper]{book}
    \usepackage[a4paper]{geometry}
    \usepackage{pdfpages}

    \begin{document}

    ... Some text ...

    %% where HelloWorld.pdf is the
    %% external file you want to include
    \includepdf[pages={1-2},nup=1x2,landscape]
    {HelloWorld.pdf}

    ... some other text...
    \end{document}

    ReplyDelete
  7. Excellent article. How did you manage to print something in the trimmed area? I would like to use it to give a clear view of which chapter you are at when looking from the side of the book by adding colored boxes there but I have no idea how to add something in that margin.

    ReplyDelete
    Replies
    1. I hacked about a bit with some TikZ nodes with page anchors (extending _past_ the page margins and therefore into the trim areas), conveniently parked within the code for the running headers and footers: see http://latex-my.blogspot.com/2009/11/customising-running-headers-and-footers.html for the blog post and sample code download.

      You might also be interested in this link: http://tex.stackexchange.com/questions/31462/adding-chapter-marker-to-far-right-edge-of-page

      Delete