Professional Documents
Culture Documents
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:
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}
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
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:
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:
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.
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:
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.
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
year
= {1905},
volume
= {322},
number
= {10},
pages
= {891-921},
doi
= {http://dx.doi.org/10.1002/andp.19053221004}
}
@online{knuthwebsite,
author
= {Donald Knuth},
title
year
= {1984},
url
= {http://www-cs-
faculty.stanford.edu/~uno/abcde.html}
}
@book{latexcompanion,
author
Alexander Samarin},
title
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
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:
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.
\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.