Customising running headers and footers

By default, the running headers in a two-sided book (resp. article) produced by LaTeX displays the chapter (resp. section) number + title and the page number on even pages; and the page number and section (resp. subsection) number + title on odd pages. On chapter pages, however, the running header is blank, and the page number is displayed in the centre of the footer.

All these default headers and footers can be customised, either with the facilities already provided by the memoir class, or via the fancyhdr package. Basically, you need to redefine the “plain” pagestyle for chapter pages, and the “headings” pagestyle for the non-chapter pages. Using memoir, you’d do something like


% respectively \makeevenhead{headings}…

While if you’re using the fancyhdr package:

  %% Clear all headers and footers
  %% e.g. if right footers on odd pages and left footers
  %% on even pages are some content:

  %% this applies to right headers on odd pages:
  %% and this to left headers on even pages:
  %% and this to centre headers on both even and odd:


As always, see the respective manuals/user guides for extensive instructions.

Here are some examples of what I’ve done:

(Download links of the .tex source files are at the end of this post)

Here are my specs:

  • On chapter pages:
    • page number in a coloured box on the right in the footer on odd pages;
    • ditto, but on the left in the footer on even pages;
    • blank running headers.
  • On non-chapter pages:
    • same footers as above;
    • on even pages, the chapter title on the left in the header, and a decorative line extending to the right all the way to the paper margin;
    • on odd pages, the section title on the right in the header, and a decorative line extending to the left all the way to the paper margin.

I used the tikz package for the coloured box containing the page number, as well as the decorative lines in the header.

You’ll probably notice that on the non-chapter pages, I’ve got some coloured background going on, too. I could’ve used the wallpaper package to achieve this effect, but just for kicks, I did them using the tikz package, using the headings pagestyle as a hook.

So here are the .tex source (plus the public domain images used) for producing the sample pages above:

Note that my examples require wallpaper.sty v2.5. If you’re using MikTeX, your wallpaper.sty is most likely v2.4, so you’ll have to grab the latest version yourself.

Fancy Chapter Headings

This is the 3rd post in the bookdesign series. Previous posts in this series:

If you look at my post that started this series, you might notice that the first page of every chapter in the Grid Computing Cluster report is rather fancy. I’ve initially got my inspirations from Stefan Kottwitz’s post on ‘Fancy chapter headings with TikZ‘.

Here are the samples of how the chapter pages would look like:

(Download links of the .tex source files are at the end of this post)

The chapter number and title are rendered with TikZ, similar to what’s described in Stefan Kottwitz’s post. I threw in a background image across the top of the page, and another one at the lower corner, using the wallpaper package.

Just so we can choose a different image for every chapter, I defined a new command that holds the image filename (\newcommand\chapterillustration{}) and re-define it at each chapter (\renewcommand\chapterillustration{cherry-tomatos}).

Notice that the positioning of the chapter title and the fern leaf background image is different depending on whether the chapter starts on an odd or even page. The memoir document class provides the commands \checkoddpage and \ifoddpage…\else\…\fi, so that you can define what to do in each case.  Don’t worry if you’re not using the memoir document class, these commands are also available via the changepage package.

Now to actually implement these definitions. The memoir document class lets you define chapter styles (e.g. \makechapterstyle{FancyChap}{\def\printchaptertitle##1{…}} see the manual on “Chapter Headings” for more details) in the preamble, which you would activate in the document body with \chapterstyle{FancyChap}.

On the other hand, if you’re not using the memoir document class, use the \titleformat and \titlespacing commands from the titlesec package instead.

Sorry I’m too tired to even post relevant snippets; here are the links to the .tex sources to produce the sample pages above. I’ve incorporated the code for Changing page size and sizes, too. (By the way I used the lipsum package to generate the dummy text. You know, Lorem ipsum dolor sit amet…)

The sample public domain images are from here (cherry tomatos), here (computer chips) and here (fern leaf).

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.)


%% The stock paper size

%% The ‘real’ page size

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


%% Spine and trim page margins from main typeblock

%% Top and bottom page margins from main typeblock

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


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


%% Apply and enforce layout

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:


%% Custom stock paper and page size

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




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




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:

   paperwidth=216mm, paperheight=303mm,
   left=23mm,  %% or inner=23mm
   right=18mm, %% or outer=18mm
   top=23mm, bottom=23mm,

Again, if you’re just going to print on A4 (or letter) paper, you can just do

   left=20mm,  %% or inner=20mm
   right=15mm, %% or outer=15mm
   top=20mm, bottom=20mm,

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