You are on page 1of 33

How to Write a Thesis in LaTeX pt 1 - Basic Structure

To see the corresponding video for this blog post click here.
In this series of blog posts were going to teach you how to write a basic thesis using
LaTeX. Your thesis could be the longest and most complicated document youll ever
write, which is why its such a good idea to use LaTeX instead of a common word
processor. LaTeX makes tasks that are difficult and awkward in word processors, far
simpler.
When writing something like a thesis its worth splitting up the document into multiple tex
files.
Its also wise to organise the project using folders. Therefore well create two new
folders, one for all the images used in the project and one for all the tex files making up
the main body of the thesis.

The Preamble
In this example, the main.tex file is the root document and is the tex file that will draw
the whole document together. The first thing we need to choose is a document class.
The article class isnt designed for writing long documents like thesis so well choose
the report class, but we could also choose the book class. We can also change the font
size by adding square brackets into the\documentclass command and specifying the
size. Well choose 12pt. Lets also prepare the document for images by loading the
graphicx package. Well also need to tell LaTeX where to look for the images using
the \graphicspath command, as were storing them in a separate folder. The start of
our preamble now looks like this:
\documentclass[12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\graphicspath{ {images/} }

Now we can finish off the preamble by filling in the title, author and date information. To
create the simplest title page we can add the thesis title, institution name and institution
logo all into the title command. E.g.
\title{
{Thesis Title}\\
{\large Institution Name}\\
{\includegraphics{university.jpg}}
}
\author{Author Name}
\date{Day Month Year}
This isnt the best way to alter the title page so well look at more elaborate ways of
customising title pages later on in the series, but this will suffice for now. This is what
the \maketitlecommand now produces for us:

The Front Matter


After the title page we need to add in an abstract, dedication, declaration and
acknowledgements section. We can add each of these in on separate pages using
unnumbered chapters. To do this we use the \chapter command and add an asterisk.
After these sections well add a table of contents using
the \tableofcontents command:
\chapter*{Abstract}

Abstract goes here


\chapter*{Dedication}
To mum and dad
\chapter*{Declaration}
I declare that..
\chapter*{Acknowledgements}
I want to thank...
\tableofcontents

The Main Body


Now for the main body of the document. In this example we will add five chapters in,
one of which will be an introduction and another will be a conclusion. However, instead
of just composing these chapters in the main tex file, well create a separate tex file for
each chapter in the chapters folder. We can then fill in these chapters with text
remembering to split them up into sections and subsections.

Then to add these chapters into the document, we use the \input command in the
root document. Remember to add in chapters/ before the file name so that LaTeX
knows where to find it.
\chapter{Introduction}
\input{chapters/introduction}
\chapter{Chapter Two Title}
\input{chapters/chapter02}
\chapter{Chapter Three Title}
\input{chapters/chapter03}
\chapter{Chapter Four Title}
\input{chapters/chapter04}
\chapter{Conclusion}
\input{chapters/conclusion}

The End Matter


We will now add in an appendix at the end of the document. To do this we use
the \appendixcommand to tell LaTeX that what follows are appendices. Again Well
write the appendix in a separate file and then input it.
\appendix
\chapter{Appendix Title}
\input{chapters/appendix}
If we now compile the document, all our chapters will be added to the document and the
table of contents will be automatically generated.

Now we have a basic structure for a thesis set up. In the next post I will show you how
to change the page layout and add headers in.
Posted by Josh Cassidy on 02 Aug 2013

How to Write a Thesis in LaTeX pt 2 - Page


Layout
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
well start customising the page layout using the geometry and fancyhdr packages.
Well 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:
\documentclass[12pt,twoside]{report}

The geometry package


Next well 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. Well change this to
a4paper. Next well 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:
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm]{geometry}
You will notice that on even pages the text is positioned slightly closer to the righthand
side and on odd pages its 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. Well choose to offset it by 6mm:
\
usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset
=6mm]{geometry}
You can see that the margins have now shifted:

The fancyhdr package


Next well add in headers and footers using the fancyhdr package. First lets load up
the package. Immediately after the \usepackage command we need to add
the \pagestylecommand and enter fancy into the curly brackets.
\usepackage{fancyhdr}
\pagestyle{fancy}

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 youre happy with this layout you can leave it like this. However Im going to show you
how you can customise it. To do this we use two new commands.
The \fancyhead and \fancyfootcommands. 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. Heres an example of how we might customise our headers and footers:
\fancyhead{}
\fancyhead[RO,LE]{Thesis Title}
\fancyfoot{}
\fancyfoot[LE,RO]{\thepage}
\fancyfoot[LO,CE]{Chapter \thechapter}
\fancyfoot[CO,RE]{Author Name}
In the first line weve entered a blank \fancyhead command. This is to clear all the
header fields. In the second line weve 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 weve 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 its 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:
Header:

Footer:

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 \rightmarkcommands.
Heres 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:

\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
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 well look at using
images and tables.

How to Write a Thesis in LaTeX pt 3 - Figures,


Subfigures and Tables
To see the corresponding video for this blog post click here.
In the last post we looked at configuring the page layout of our thesis using the
geometry and fancyhdr packages. In this post were going to look at using images and
tables. If youve never added images or tables into a LaTeX document, I recommend
you first check out the relevant posts in our beginners tutorial series. You can see our
post on using images here, and our post on tables here.

Images
For this project, every image we use we will store in the images folder to keep
everything tidy. In the first post we prepared the document for images by loading up the
graphicx package and by informing LaTeX where the images are stored using
the \graphicspath command.

Whenever we add an image into our thesis, we will use the figure environment. Heres
an example:
\begin{figure}[h]
\centering
\includegraphics[scale=0.5]{graph_a}
\caption{An example graph}
\label{fig:x cubed graph}
\end{figure}
Notice that Ive halved the size of the image and used the position specifier h to put it in
the document where the code is in the text. Its really important to add captions to
figures when writing a thesis. This is what it looks like compiled:

Notice that LaTeX has automatically numbered it according to what chapter its part of. It
is also really important to label each figure so you can accurately refer back to it in the
text using the \ref command. If you added this in the text:

\ref{fig:x cubed graph}


LaTeX would give you the figure number 2.1 in place of this command in the pdf.

Subfigures
When writing a thesis you may want to include some slightly more complicated figures
with multiple images. You can do this using subfigure environments inside a figure
environment. Before we can do this though, we need to load up the caption and sub
caption packages:
\usepackage{caption}
\usepackage{subcaption}
Well do an example with three images along side each other with separate captions
and labels. Heres some example code:
\begin{figure}
\centering
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{graph1}
\caption{$y=x$}
\label{fig:y equals x}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{graph2}
\caption{$y=3sinx$}
\label{fig:three sin x}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering

\includegraphics[width=\textwidth]{graph3}
\caption{$y=5/x$}
\label{fig:five over x}
\end{subfigure}
\caption{Three simple graphs}
\label{fig:three graphs}
\end{figure}
To start with, we create a new figure, centre it and then create a new subfigure. In the
subfigure command we need to add a placement specifier and then give it a width. As
we want three images next to each other we set a width of 0.3 times the text width. You
need to make sure that the sum of the widths you specify for the subfigures is less than
the text width if you want them all on the same line. When we add the image in we need
to specify the width using width= followed by the \textwidth command. The reason
this works is because the text width within in the subfigure is the width we specified in
the \begin{subfigure}command, i.e. 0.3 times the normal text width. Next we give
the subfigure a separate caption and label. We can then end the subfigure and add the
next two in. To add some spacing between the figures well use the \hfill command. If
you didnt want them all on the same line you could just leave blank lines instead of
the \hfill commands. Please note that the indents I have used do not affect the how the
code is processed, they just make it more readable. The beauty of these subfigures is
that we can refer to each of them individualy in the text due to their individual labels. But
we can also give the whole figure a caption and label.
This is what our figure will look like in the document:

Now if we add a \listoffigures command just after the table of contents, LaTeX will
generate a list of all the figure used in the thesis and inform us where each can be
found:

Tables
Now lets talk about tables. When writing a thesis you should enclose all your tables in
the table environment. Heres a basic example:
\begin{table}[h]
\centering
\begin{tabular}{l | l | l}
A & B & C \\
\hline
1 & 2 & 3 \\
4 & 5 & 6
\end{tabular}
\caption{very basic table}
\label{tab:abc}
\end{table}
Again make sure you add both a caption and a label.

Subtables
Just like with images, you may want to group tables together into a single table
environment. This can be done by using subtable environments inside a table
environment. Heres an example:
\begin{table}[h]
\begin{subtable}[h]{0.45\textwidth}
\centering
\begin{tabular}{l | l | l}
Day & Max Temp & Min Temp \\
\hline \hline
Mon & 20 & 13\\
Tue & 22 & 14\\
Wed & 23 & 12\\
Thurs & 25 & 13\\
Fri & 18 & 7\\
Sat & 15 & 13\\
Sun & 20 & 13
\end{tabular}
\caption{First Week}
\label{tab:week1}
\end{subtable}
\hfill
\begin{subtable}[h]{0.45\textwidth}
\centering
\begin{tabular}{l | l | l}
Day & Max Temp & Min Temp \\

\hline \hline
Mon & 17 & 11\\
Tue & 16 & 10\\
Wed & 14 & 8\\
Thurs & 12 & 5\\
Fri & 15 & 7\\
Sat & 16 & 12\\
Sun & 15 & 9
\end{tabular}
\caption{Second Week}
\label{tab:week2}
\end{subtable}
\caption{Max and min temps recorded in the first two weeks of
July}
\label{tab:temps}
\end{table}
Notice that in each \begin{subtable} command weve included a position specifier
and a width. Again we can give each subtable a label and caption as well as giving the
whole table figure a label and caption.

Now in the same way we added a list of figures after the table of contents we can add a
list of tables using the \listoftables command.

This concludes our discussion on images and tables. In the next section well look at
adding a bibliography to our thesis.

How to Write a Thesis in LaTeX pt 4 Bibliographies with Biblatex


To see the corresponding video for this blog post click here.
In the last post we looked at using images and tables in our thesis. In this post we are
going to look at adding a bibliography to our thesis. To do this we are going to use the
biblatex package. This involves creating a list of sources in a separate file called a bib
file.

The Bib File


When we create this file we need to choose a name for it and save it as a .bib file
rather than a .tex file.

Now every time we need to reference a source we can cite it in the text and then fill in
the source details in the bib file. First well look at filling in our .bib file and then well
move on to discussing citations.
To add a new entry to our bib file we need to first tell biblatex what type of source we
are referencing. We do this using an @ symbol followed immediately by the source
type.
@article{<citation key>,
author

= {},

title

= {},

journaltitle

= {},

year

= {}

}
@online{<citation key>,
author

= {},

title

= {},

year

= {},

url

= {}

}
@book{<citation key>,
author

= {},

title

= {},

year

= {}

}
Then comes an opening curly bracket and a citation key of our choice followed by a
comma. We then need to tell it all the details it wants for that particular type of source.
We do this using a list of keywords each followed by an equals sign and the
corresponding information in curly brackets. Items in the list are separated by commas.
Each recognised source type has a list of required details which we must provide. But
well often want to give more details. For example, for an article entry we need to use
the author, title, journaltitle and year or date keywords. For an online source we need to

use the author or editor, title, year or date and url keywords, and finally for a book its
the author, title and year or date keywords. Heres an example of what they might look
like filled in.
@article{einstein,
author

= {Albert Einstein},

title

= {Zur Elektrodynamik bewegter K{\"o}rper.

(German) [On the electrodynamics of moving bodies]},


journaltitle

= {Annalen der Physik},

year

= {1905},

volume

= {322},

number

= {10},

pages

= {891-921},

doi

= {http://dx.doi.org/10.1002/andp.19053221004}

}
@online{knuthwebsite,
author

= {Donald Knuth},

title

= {Knuth: Computers and Typesetting},

year

= {1984},

url

= {http://www-cs-

faculty.stanford.edu/~uno/abcde.html}
}
@book{latexcompanion,
author

= {Michel Goossens and Frank Mittelbach and

Alexander Samarin},
title

= {The \LaTeX\ Companion},

year

= {1993},

publisher

= {Addison-Wesley},

location

= {Reading, Massachusetts}

}
All of the information about the recognised source types and all the keywords you can
use can be found in the biblatex documentation.

Now lets return to the main tex file. To set it up for a bibliography we need to load up
the biblatex package using the \usepackage command. Also in the preamble we need
to specify which bib files we want to use by calling the \addbibresource command
and entering the file name in the curly brackets including the .bib extension.
\usepackage{biblatex}
\addbibresource{references.bib}

Citations
Now lets look at citations. To cite a source in the text we use one of the biblatex citation
commands. The simplest is the \cite command which prints the citation without any
brackets unless you are using the numeric or alphabetic styles. Well discuss styles a
little later on. For example we may cite a source in the text like this:
\cite{latexcompanion}
Another one is the \parencite command which prints citations in parentheses except
when using the numeric or alphabetic styles when it uses square brackets. There are
more citation commands available to you which again can be found in the
documentation.
The citation commands in biblatex also give us the option of adding a prenote and
postnote in as arguments. A prenote is a word or phrase like see that is inserted at
the start of the citation. A postnote is text you want inserted at the end of the citation.
To add these notes in you uses two sets of square brackets in the citation command. If
you only open one set of square brackets it will assume the contents of the brackets is a
postnote, so if you only want a prenote make sure you still open the second set of
square brackets and then just leave them empty. Here are some examples:
TEXT\parencite[see][p10]{latexcompanion}
TEXT\parencite[compare][]{knuthwebsite}
TEXT\parencite[e.g.][page 300]{einstein}

Styles

Now to actually get the bibliography printed in our thesis we use


the \printbibliographycommand at the end of the document. By default the
bibliography and citations use the numeric style which looks like this:

To change the style we pass more arguments into the \usepackage command in
square brackets. For example this specifies the alphabetic style.
\usepackage[style=alphabetic]{biblatex}
Which looks like this:

And this is the authoryear style.

Another thing we can change here is the way the bibliography is ordered. For example
this sorts entries by year, name, title.
\usepackage[style=authoryear,sorting=ynt]{biblatex}
While this doesnt sort them at all but displays them in the order they are cited.
\usepackage[style=authoryear,sorting=none]{biblatex}
More information about the numerous styles and sorting options available can be found
in the documentation. This concludes our discussion on adding a bibliography. In the
next post well look at customising some of the opening pages.

How to Write a Thesis in LaTeX pt 5 Customising Your Title Page and Abstract
To see the corresponding video for this blog post click here.
In the last post we looked at adding a bibliography to our thesis using biblatex. In this
post were going to look at customising some of the opening pages. In the first video we
made a rather make shift title page using the \maketitle command and by using
an\includegraphics command in the \title command. Although this works, it
doesnt give us as much flexibility as we may want.

The Title Page


A much better way to do this is to use the title page environment. Well do this in a
separate tex file and then input it. The first thing well do is enclose everything in the title
page in the center environment so its all aligned to the centre. Next we need to instruct
LaTeX to leave a gap between the top of the page and the first line of text. To do this we
use the \vspacecommand followed by a length. We also need to add an asterisk into
the command to make sure LaTeX doesnt decide to ignore the command. Next well
add the thesis title in bold font using the \textbf command. To leave a gap between
this and the next line of text we use the\vspace command again, this time without the
asterisk. Now well add in a subtitle followed by some more vertical space and then the
author name in bold font. This concludes what we want at the top of the title page. The
rest of the content well add at the bottom of the title page. To separate these two
sections out well use the \vfill command which will automatically add in the amount
of vertical space needed for the content to fill the page. Next well add in a line of text to
specify what degree the thesis is being submitted for. The double backslash is used to
create a new line. Well then add more space before adding in the university logo
specifying its width as a fraction of the text width. Finally well add in some information
about the university and the date.
\begin{titlepage}
\begin{center}
\vspace*{1cm}

\textbf{Thesis Title}
\vspace{0.5cm}
Thesis Subtitle
\vspace{1.5cm}
\textbf{Author Name}
\vfill
A thesis presented for the degree of\\
Doctor of Philosophy
\vspace{0.8cm}
\includegraphics[width=0.4\textwidth]{university}
Department Name\\
University Name\\
Country\\
Date
\end{center}
\end{titlepage}
Now in the main tex file we can replace the \maketitle command with an input
command linked to our new title page. If we now compile the code we can see all the
items have been correctly processed.

However the text is quite small so well go back and change the font sizes. To do this we
use one of the sizing commands. There are ten of these to choose from. From smallest
to largest they are:
\tiny
\scriptsize
\footnotesize
\small
\normalsize

\large
\Large
\LARGE
\huge
\Huge
Lets make the title as big as it can be using \Huge. Well then make the subtitle two
steps smaller using \large. When we use one of these commands they affect all the
text in its scope. Therefore in its current state all the remaining text on the page will
appear in the size of the subtitle. Well keep it like this for the author name and degree
title but well drop down one size for the university details and the date.
\begin{titlepage}
\begin{center}
\vspace*{1cm}
\Huge
\textbf{Thesis Title}
\vspace{0.5cm}
\LARGE
Thesis Subtitle
\vspace{1.5cm}
\textbf{Author Name}
\vfill
A thesis presented for the degree of\\
Doctor of Philosophy
\vspace{0.8cm}
\includegraphics[width=0.4\textwidth]{university}

\Large
Department Name\\
University Name\\
Country\\
Date
\end{center}
\end{titlepage}

The Abstract
We can also customise other pages like the abstract. Instead of using an unnumbered
chapter, well create a new tex file, customise the layout and then input it. At the top of
this file we need to change the page style to plain in order to stop the headers being
added in. Now in a similar way to the title page well add in some custom titles and then
the abstract text.
\thispagestyle{plain}
\begin{center}
\Large
\textbf{Thesis Title}
\vspace{0.4cm}
\large
Thesis Subtitle
\vspace{0.4cm}
\textbf{Author Name}
\vspace{0.9cm}
\textbf{Abstract}
\end{center}
Lorem ipsum dolor...
This is what it will look like added in.

This concludes our series on writing a basic thesis. If you want to play around with the
thesis weve created in this series you can open the project in ShareLaTeX by
clicking here.

You might also like