To see the corresponding video for this blog post click here.

In the last blog post we looked at setting up the basic structure for a thesis. In this post we’ll start customising the page layout using the ‘geometry’ and ‘fancyhdr’ packages. We’ll continue working on the same project as last time. The first thing we will do is make the document two sided so that we save paper by printing on both sides of the paper. To do this we add the keyword ‘twoside’ into the document class command:


The geometry package

Next we’ll load up the geometry package. To configure the page layout, we enter instructions into the square brackets of this command. The first thing we will do is change the paper size. By default the paper size is set to US letter. We’ll change this to ‘a4paper’. Next we’ll change the width of the text by entering the keyword ‘width’ followed by an equals sign and a number in millimetres. We can also change the margin sizes at the top and bottom of the page:


You will notice that on even pages the text is positioned slightly closer to the righthand side and on odd pages it’s closer to the left. Or in other words, the inner margin is smaller than the outer:


This is due to us specifying the ‘twoside’ option but it often confuses people. The reason LaTeX does this is because when you bind the document together, the smaller inner margins will be adjacent and then combined will be a similar size to the larger outer margins. This mean that the three columns of white space you get with a double page spread will be a similar size:


However you may also want to compensate for the actual binding. To do this we will use the ‘bindingoffset’ command. We’ll choose to offset it by 6mm:


You can see that the margins have now shifted:


The fancyhdr package

Next we’ll add in headers and footers using the ‘fancyhdr’ package. First let’s load up the package. Immediately after the \usepackage command we need to add the \pagestyle command and enter ‘fancy’ into the curly brackets.


If we now compile the code you will see that a header has been added to all the pages except the title page, the contents page and the first page of each new chapter. By default the headers have the chapter and section titles in:


If you’re happy with this layout you can leave it like this. However I’m going to show you how you can customise it. To do this we use two new commands. The \fancyhead and \fancyfoot commands. The standard format for these commands is the command followed by square brackets and then curly brackets.

\fancyhead[<position specifiers>]{<text>}

In the curly brackets we enter the text we want and in the square brackets we specify which parts of the header we want that text printed in. The fancyhdr package lets us add things in the left (L), right (R) and centre (C) of the header or footer and also lets us specify a different arrangement depending on whether its on an odd (O) or even (E) page. Here’s an example of how we might customise our headers and footers:

\fancyhead[RO,LE]{Thesis Title}
\fancyfoot[LO,CE]{Chapter \thechapter}
\fancyfoot[CO,RE]{Author Name}

In the first line we’ve entered a blank \fancyhead command. This is to clear all the header fields. In the second line we’ve told LaTeX that we want the text ‘thesis title’ on the right hand side of the header for the odd pages and the left for even pages. For the footer, again we’ve started by clearing the footer fields using a blank \fancyfoot command. The fourth line makes the page number appear on the left of the footer for an even page and the right for an odd. The \thepage command returns the page number of the page it’s used on. The \thechapter command in line five does a similar thing. Lines five and six add some text about the chapter and author into the footer again in different places depending on whether the page is odd or even. Now if we compile the document with this code in we can see the headers and footers have been added in:





Before moving on I should briefly introduce you to two more commands that you may find helpful when customising your headers and footers. The \leftmark and \rightmark commands.

Here’s an example of what the \leftmark command produces:


And an example of what the \rightmark command produces:


To change the thickness of the lines in the headers and footers we use this code entering a size in points:


I recommend you keep it fairly small to keep it looking sensible.

Finally I want to mention the \pagestyle command. If we have a page that we want completely clear of headers and footers, we can use this command entering the the keyword ‘empty’ in as an argument. E.g. \pagestyle{empty}. If we want a page with no headers or footers except for a simple page number at the bottom we would use the keyword ‘plain’. However you need to be aware that using this command changes the page style for all the pages following the command. Therefore we need to turn the page style back to fancy as soon as we want the headers back.

This concludes our discussion on page layout. In the next post we’ll look at using images and tables.

pt 1 - Basic Structure

pt 3 - Figures, Subfigures and Tables

pt 4 - Bibliographies with Biblatex

pt 5 - Customising Your Title Page and Abstract

Posted by Josh Cassidy on 06 Aug 2013