You are on page 1of 21

Learning LATEX

Andreea-Ina Radu
March 16, 2021

1 Introduction
Welcome to the LATEX tutorial. This is a cheat-sheet to get you started with
LATEX and by the end of it, you will have knowledge to recreate (most of) this
document.

2 Structure
This is a high-level overview of how a LATEX document is structured. We first
declare the class, then any packages we use (explained just next). We can
then create custom document-wide commands, or set parameters, either for
our packages or typesetting ones e.g. if we’d want to change the geometry or
margins of all pages, if we’d want all the document to be landscape, if we want
all bullets from bullet lists to be ∗ instead of •. Then, we can declare what the
title, author and date of our document is.
We then declare the document environment. This is the main “body” of the
document. The content of our document (text, images, tables, etc) will go in
here. The \maketitle command generates the (printed) title from the previ-
ously declared commands. We usually put this just after \documentclass{...},
as we want these details at the top of our document.
Before we close the document environment, we have to declare the bibliog-
raphy, if we have any. In this example, we will use a separate bibliography file.
We will choose the bibliography and referencing style with

\bibliographystyle{...}
and will let our main document know the name of our bib file with the command
\bibliography{...}

1
\documentclass{article}
\usepackage{hyperref}
... Declare packages here
Preamble

(optional) Declare custom


commands document-wide
changes to settings here

\title{Learning \LaTeX} Declare your title, author


\author{Andreea-Ina Radu} and (optionally) date here
{\begin{document}
Creates doc title from
\maketitle
above commands
\section{Introduction}
...

The main content of your


document will go here

\bibliographystyle{...} Here we declare the


\bibliography{...} bibliography info
\end{document}

2
3 Document Classes
Any LATEX file will start with the \documentclass[OPTIONS]{...} declaration.
With the document class, you can choose what type of document you want.
For example, if you’re writing an assignment, you probably want the article
class. If you’re writing a long report, you probably want report and for a book
you can use book. A full list of possible classes can be found here: https:
//ctan.org/topic/class. The book and report classes also have chapters,
whereas article does not. Not all of them may be installed on your system or
Overleaf. You can also write your own custom class, but that’s a story for
another day . This document uses

\documentclass[a4paper]{article}

4 Packages
Very plain LATEX can do a good number of things on its own, but packages
make life easier. They can add all sorts of features to our document, or make
things more customisable, in a simpler fashion than directly modifying all sorts
of LATEX parameters. We need to declare that we want to use a package at the
top of the LATEX file, just after we specify the document class. For example, if
I want to have a URL link in my document, and I want that URL to open in a
browser when I click on it, I can use the package hyperref and I can declare it
with

\usepackage{hyperref}

and use the url command in the text with


\url{URL_GOES_HERE}
the result being, for example: https://ctan.org/topic/class (click it!)

5 Headers
If you’re writing a document for an assignment or a report, you would organise
it into sections, subsections, subsubsections and paragraphs:

\section{Hi, I'm a section!}


\subsection{Hi, I'm a subsection!}
\subsubsection{Hi, I'm a subsubsection!}
\paragraph{Hi, I'm a paragraph!} And this is some more text after
that paragraph.

6 Hi, I’m a section!


6.1 Hi, I’m a subsection!
6.1.1 Hi, I’m a subsubsection!
Hi, I’m a paragraph! And this is some more text after that paragraph.

3
If you don’t want the sections, subsections, subsubsections to be numbered,
you can use the starred version of the respective command:

\subsection*{Hi, I'm a subsection without a number!}

Hi, I’m a subsection without a number!


Some document classes, such as report and book, also provide the \chapter{...}
and \chapter*{...} headers.

LATEX differentiates between a paragraph heading and paragraph text.


The above command is used for a paragraph heading.

7 Basic typesetting knowledge


There are a couple of key things to remember about LATEX:
• To start a new text paragraph, use a blank line between the chunks of
text:

This is a first (very short) paragraph.

And this is a second paragraph, the blank line breaks it up.


Result:
This is a first (very short) paragraph.
And this is a second paragraph, the blank line breaks it up.
You can force line breaks with \\, \newline or \linebreak. They all force-
fully introduce a new line, but have slightly different behaviours. I’ll let you
test them out! However, it is best practice to not force line breaks, let LATEX
take care of the flow! It knows best.
• Quote marks “some text” are actually typeset with: `` for opening quotes
and '' for closing quotes.
• Bold is achieved through \textbf{...} (bold face).
• Italics is achieved through \textit{...}.
• Fixed width font is achieved through \texttt{...}.
• Comments in the LATEX source code are placed with %.

8 Lists
8.1 Unordered lists
\begin{itemize} • This is my first item
\item This is my first item
\item This is my second item • This is my second item
\end{itemize}

4
8.2 Ordered (numbered) lists
\begin{enumerate}
\item This is my first item 1. This is my first item
\item This is my second item
2. This is my second item
\begin{enumerate}
\item Second item first subitem (a) Second item first
\item Second item second subitem subitem
\end{enumerate}
(b) Second item second
\end{enumerate}
subitem

8.3 Changing the list marker


We need to use the enumitem package. Insert

\usepackage{enumitem}

at the top of the document, where we said we’ll declare packages we use, in
the preamble.
Then, we can set the label either globally, still in the preamble:

\setlist[enumerate,1]{label={(\Alph*.)}}

The 1 refers to the depth of the list. In case you have nested lists, and you
want to change lower level labels, you need to set those too.
Or only for one list (in which case you don’t need to set it in the preamble!),
in the text:
\begin{enumerate}[label=\Alph*.]
\item This is my first item A. This is my first item
\item This is my second item
B. This is my second item
\end{enumerate}

8.4 List spacing


If you want to change the spacing between the elements of the list (you can see
they have quite a bit of space), you can set it for the whole document in the
preamble with:

\setlist{nosep}

Or only for one list (in which case you don’t need to set it in the preamble!),
in the text:
\begin{enumerate}[nosep]
1. This is my first item
\item This is my first item
2. This is my second item
\item This is my second item
\end{enumerate}

9 Graphics
You can insert images into you document easily. We’ll use the graphicx package
for that. In your preamble add:

5
\usepackage{graphicx}

Then, in the text, where you want the image to appear, use the following
command:

\includegraphics[OPTIONS]{PATH_TO_FILE}

For example, if I want to include the daffodil.jpg image, and I want it to


be as wide as half the allocated document line width, I would use:

\includegraphics[width=0.5\linewidth]{daffodil.jpg}

Result:

The image will always be placed where you insert the command. You can
also horizontally center the image in the page, by surrounding it with the center
environment:

\begin{center}
\includegraphics[width=0.5\linewidth]{daffodil.jpg}
\end{center}

Result:

You can use center on text as well!

\begin{center}
This text will be centred on the page!
\end{center}

Result:

This text will be centred on the page!

6
Figure 1: This is my daffodil.

10 Floats
“Floats are containers for things in a document that cannot be broken over a
page”. They float in the document, and may be cleverly re-positioned to get
the best flow. You can have as much or as little control over their positioning
as you want.
We now know how to insert an image, but what if we want to add a caption?
Also, inserting it as above will not allow LATEX to work its typesetting magic
and determine the best place for our image. So, the best practice is to use a
figure environment:

\begin{figure}
\centering
\includegraphics[width=0.5\linewidth]{daffodil.jpg}
\caption{This is my daffodil.}
\end{figure}

Let’s dissect the above code:


1. \centering is the equivalent of the center environment, however it doesn’t
add any vertical space and is preferred when we want to center something
that is already in an environment (like figure).
2. \includegraphics[width=0.5\linewidth]{daffodil.jpg} is inserting
our image.
3. \caption{This is my daffodil.} will place our caption under the im-
age. Captions should usually explain what the figure represents.
You can see that LATEX decided the best place to put my figure, in this case,
is at the top of the page. The figure environment can take a number of options,
though which we tell LATEX where we would prefer our figure be placed. These
are:

• t – top
• b – bottom
• p – a special page only for floats

7
• h – here; approximately where we placed it in the (source) text, but it
may be moved if it breaks the flow terribly

• ! – force the figure to be placed where I specify; this overrides LATEX’s


internal algorithms for determining the best place to put the figure
• H – exactly here! (you need to use the float package for this to work)

These location options can be used by themselves or can be combined in an


order of preferences:

\begin{figure}[ht]
\centering
\includegraphics[width=0.5\linewidth]{daffodil.jpg}
\caption{This is my daffodil -- ht.}
\end{figure}

Figure 2: This is my daffodil – ht.

E.g. ht tells it I want the figure here, but if it really doesn’t work in that
place, it can put it at the top of the page (it may put it on the next page at the
top!).

11 Tables
Tables follow a similar approach as figures. The floating environment for tables
is table. Then, we define how we want our table to be structured. Now, there
are many environments that can be used to do that. I will show my favourite
one, but you can look others up. The package used to create the tables in this
document is tabularx1 and we need to add that to the preamble:

\usepackage{tabularx}

Let’s consider a small table:


1 http://mirror.ox.ac.uk/sites/ctan.org/macros/latex/required/tools/tabularx.

pdf

8
\begin{table}[h!]
\caption{My first table}
\centering
\begin{tabularx}{0.9\linewidth}{ l | c | r | X }
Column 1 & Column 2 & Column 3 & Column 4 \\
\hline
item 11 & item 12 & item 13 & stretchy paragraph column 1 \\
left item 21 & centred item 22 & right item 23 & stretchy
paragraph column 2 \\
\hline
\end{tabularx}
\end{table}

Result:

Table 1: My first table


Column 1 Column 2 Column 3 Column 4
item 11 item 12 item 13 stretchy paragraph
column 1
left item 21 centred item 22 right item 23 stretchy paragraph
column 2

Let’s dissect it!

• \caption{My first table} is the table caption. In this case, I placed it


at the top of the table, just to show you can move it.
• \begin{tabularx}{0.7\linewidth}{ l | c | r | X } is the beginning
of our tabularx environment, where we tell it how wide we want the table
to be (90% of the line width), and what type of columns we want it to
have. These alignment formats apply to the whole column. They are:
– l is a left aligned column; width of column determined by text con-
tent;
– c is a centred column; width of column determined by text content;
– r is a right aligned column; width of column determined by text
content;
– X is a paragraph column, left-aligned; it means that the width of
this column is automatically calculated from the width we specified
(90% line width) and the other columns’ content. Whatever is left is
allocated to the X column. And long text will wrap around, forming
a paragraph, such as not to exit the bounds of the table we specified.
X is a tabularx-specific column-type.
– (not shown in the example) p{WIDTH} is a paragraph column of a
specified fixed width (e.g. a p{3cm} column will always be 3cm wide).
The vertical bars between the column specifiers (|) indicate whether and
where column lines should be drawn.

9
• Column 1 & Column 2 & Column 3 & Column 4 \\ is the first row of
the table; cell content is separated by the & marker. We then mark that
the row has ended by the new line marker \\.
• \hline triggers a horizontal line spanning the width of the table.

12 Labels and referencing


When writing a document, you may want to refer to a header, figure or table in
text. This can be done by assigning a label to said header, figure or table where
we declare them, and referencing them somewhere else in the document.
For example, all my headings have labels associated with them, with
\label{LABEL_NAME}. This section’s heading has the label \ref{sec:labels}.
The full line looks like this:
\section{Labels and referencing}\label{sec:labels}
I can then reference it in text with \ref{sec:labels}, and it automatically
creates a clickable hyperlink (because we’re using the hyperref package):
I explain labels in Section~\ref{sec:labels}.
Result:
I explain labels in Section 12.
I use the ~ marker to tell LATEX to not insert a line break between the word
Section and the number generated by the reference command, because that
would look weird.
The benefit of this is that if I change the order of the sections (e.g I would
move this section before the floats section, thus this becoming section 10), the
\ref{...} command will automatically generate the correct number for it.
You can add labels to figures (I sneakily added one in the first figure of this
document, Figure 1):
\begin{figure}
\centering
\includegraphics[width=0.5\linewidth]{daffodil.jpg}
\caption{This is my daffodil.}\label{fig:daffodil}
\end{figure}
and in tables (like in Table 1):
\begin{table}[h!]
\caption{My first table}\label{tab:mytable}
\centering
\begin{tabularx}{0.9\linewidth}{ l | c | r | X }
Column 1 & Column 2 & Column 3 & Column 4 \\
\hline
item 11 & item 12 & item 13 & stretchy paragraph column 1 \\
left item 21 & centred item 22 & right item 23 & stretchy
paragraph column 2 \\
\hline
\end{tabularx}
\end{table}

10
You’ll notice that the name of my labels includes a prefix that gives me
an idea of what they are (sec:LABEL NAME for section, fig:LABEL NAME for
figure, tab:LABEL NAME for table). This is not mandatory, but it helps me
keep organised. It’s also great if you have some form of autocompletion (like
Overleaf does). When you type \ref{...} it will show you all the labels you’ve
placed, so using prefixes is a sort of filtering system (e.g. if I type \ref{sec
the autocomplete will only show me the section labels). If I label a subsection,
I would usually include the section label name in it too. For example, for
Subsection 8.2, I libelled the subsection with \label{subsec:lists:ordered},
so I know it’s part of the Lists section. But it’s fully up to you how you want
to organise your document.

13 Maths
Maths mode has a plethora of cool things you can do, and we could have a
whole workshop only on this! I’m going to try and give you a crash course into
its basic usage, but really, even I haven’t discovered all the ways to use it!
LATEX differentiates between text mode (what we’ve been using so far), and
maths mode, which beautifully typesets mathematical content. Let’s see what
we can do.

13.1 In-line mode


There are two types of in-line maths markers:

• $...$ is generally used if you want to insert short, letter-based maths into
the text; e.g. a variable name: Let x be. . . (Code: Let $x$ be).
• \(...\) if you have longer, more complex maths; e.g. an equation:
The sum of the first n natural numbers can be calculated as
P n n(n+1)
i=1 = 2 .
Code:
The sum of the first $n$ natural numbers can be calculated
as \( \sum_{i=1}^{n}=\frac{n(n+1)}{2} \).
Let’s dissect it!
P
– \sum is a macro for the symbol
– _ and ^ are the symbols for subscript and superscript, respectively
(or powers and indices); if the subscript or superscript contains more
than one characters we need to enclose it with {...}.
– \frac{...}{...} is a command that lets us typeset fractions. The
first argument is the numerator and the second argument is the de-
nominator.

11
13.2 Display mode
13.2.1 Unnumbered
If we want the equation we write to be on its own line, we need to use the
\[...\] markers (you may or may not have a blank line between the text and
this type of maths mode; I prefer to have it for consistency):

The sum of the first $n$ natural numbers can be calculated as:

\[ \sum_{i=1}^{n}=\frac{n(n+1)}{2} \]

The sum of the first n natural numbers can be calculated as:


n
X n(n + 1)
=
i=1
2
You can see this type of maths also centres the equation, and that the
subscripts and superscripts are placed differently, because there is enough space.

13.2.2 Numbered
If we also want to add a number to this equation (and even a label!), we need to
use a different environment. The equation environment is the most basic and
doesn’t require other packages:
n
X n(n + 1)
= (1)
i=1
2
The sum of the first n natural numbers can be calculated with the formula
in Equation 1.
Code:

\begin{equation}\label{eq:sum_n}
\sum_{i=1}^{n}=\frac{n(n+1)}{2}
\end{equation}

The sum of the first $n$ natural numbers can be calculated with the
formula in Equation~\ref{eq:sum_n}.

13.2.3 Alignment
If we want to align some equations based on a character, for example we have
a pair of equations to solve, or we are showing the steps of how we worked
something out, we can use the align environment, from the amsmath package:

2x − 5y = 8 (2)
3x + 9y = −12 (3)

or (proving that the sum of any 3 even natural numbers is a multiple of 6):

12
2n + (2n + 2) + (2n + 4) = 6n + 6
= 6(n + 1)

Code:

\begin{align}
2x - 5y &= 8 \\
3x + 9y &= -12
\end{align}

\begin{align*}
2n + (2n + 2) + (2n + 4) &= 6n + 6 \\
&= 6(n + 1)
\end{align*}

You can notice that the starred version of the environment does not number
the equations.

13.3 Useful symbols


A comprehensive list can be found at https://mathvault.ca/wp-content/
uploads/Comprehensive-List-of-Mathematical-Symbols.pdf. All these sym-
bols need to be used in one of the maths modes.

Greek letters: Logic operators:


α – \alpha ∀ – \forall
β – \beta ∃ – \exits
γ – \gamma ¬ – \lnot
Γ – \Gamma ∧ – \land
π – \pi ∨ – \lor
Π – \Pi Comparisons:
φ – \phi ≤ – \le
ϕ – \varph ≥ – \ge
Φ – \Phi Sets:
µ – \mu ∈ – \in
 – \epsilon ∈
/ – \notin
⊆ – \subseteq

13.4 An example from reasoning


Let us compute the disjunctive normal form for (P ∨ ¬Q) → R:

(P ∨ ¬Q) → R ∼
= ¬(P ∨ ¬Q) ∨ R

= (P ∧ ¬¬Q) ∨ R

= (P ∧ Q) ∨ R

Code:

13
\begin{align*}
(P \lor \lnot Q) \to R &\cong \lnot (P \lor \lnot Q) \lor R \\
&\cong (P \land \lnot \lnot Q) \lor R \\
&\cong (P \land Q) \lor R
\end{align*}

14 Listings and code


There are a number of environments we can use for presenting (pseudo-)code.

14.1 Verbatim
This is the most basic environment. It does not require any additional packages.
The verbatim environment prints out exactly the text you give it. It also has an
in-line version, \mintinline{latex}{...}. Remember, an ad literam package
such as verbatim does not play nicely if nested with itself.

\begin{verbatim}
This is a verbatim environment

if __name__ == "__main__":
print("Hello world!")
\end{verbatim}

Result:

This is a verbatim environment

if __name__ == "__main__":
print("Hello world!")

14.2 Algorithms
The algorithm2e2 package is very useful for algorithms. You don’t always
need to give the exact source code, you may want to just explain an algorithm.
While the package is called algorithm2e, the environment is called algorithm.
There are other packages as well, but I’ll only be showing this one. Have fun
experimenting with others!

\begin{algorithm}
\SetKwInOut{Input}{input}
\SetKwProg{Fn}{def}{\string:}{end}
\SetKwFunction{FnLen}{length}
\SetKwFunction{FnSwap}{swap}

\Fn{bubbleSort(L)}{\Input{$L$ -- list to be sorted}


\BlankLine
$n \leftarrow \FnLen(L)$\;
2 http://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/algorithm2e/doc/

algorithm2e.pdf

14
$swapped \leftarrow true$\;

\While{$swapped$}{
$swapped \leftarrow false$\;
\For{$i=0$ \KwTo $n-1$}{
\If{$L[i] > L[i+1]$}{
$\FnSwap(A[i], A[i+1])$\;
$swapped \leftarrow true$\;
}
}
}
}
\caption{Bubblesort algorithm}\label{alg:bubblesort}
\end{algorithm}

def bubbleSort(L):
input: L – list to be sorted
n ← length(L);
swapped ← true;
while swapped do
swapped ← f alse;
for i = 0 to n − 1 do
if L[i] > L[i + 1] then
swap(A[i], A[i + 1]);
swapped ← true;
end
end
end
end
Algorithm 1: Bubblesort algorithm

Let’s analyse it!


• \SetKwInOut{Input}{input} creates the \Input macro and defines its
style
• \SetKwProg{Fn}{def}{\string:}{end} defines the macro \Fn and how
it will be typeset, to be used as an algorithm’s function which we will
describe
• \SetKwFunction{FnLen}{length} and \SetKwFunction{FnSwap}{swap}
define the \FnLen and \FnSwap macros, respectively; they typeset func-
tions, and they are mostly used for functions which are not defined in the
algorithm (can be used for built-in functions, for example, like Python’s
len())
• \Fn{Program name}{BODY_OF_PROGRAM} is used to define the program (or
function) typeset in the algorithm; there can be multiple \Fns in one
algorithm

15
• \Input is the above defined macro; we simply state what the input to the
bubbleSort function is

• \BlankLine inserts a vertical space


• We then have the instructions/operations of the algorithm; we end a line
with \;
• \While, \For and \If are loops and conditional statements; they generally
follow the rule \Conditional{condition...}{instruction(s)\;}

• At the end, we add a caption and a label, for later referencing in text
algorithm2e has a lot of keywords and options which can be customised,
feel free to explore them.

14.3 Source code


There are two packages we’ll be talking about when it comes to source code. One
is listings, which typesets source code in a style similar to algorithm2e, and
minted, which typesets source code as closely as possible to how it would look
like in your text editor or IDE. minted has syntax highlighting support, but it
requires the pygmentize binary to be installed on your system (you can get it by
installing python-pygments on Ubuntu (sudo apt install python-pygments)
or ArchLinux (sudo pacman -S python-pygments)).
We’re going to look at how their typesetting differs; I’ll use python as a
programming language example. Both listings and minted support a wide
range of languages. Check out their manuals.

14.3.1 Listings
While the package name is listings3 , the environment we need to use is
lstlisting. The syntax is (the language name needs to be capitalised):

\begin{lstlisting}[language=YOUR_LANGUAGE]
CODE GOES HERE
\end{lstlisting}

Example output:
def b u b b l e s o r t ( o u r l i s t ) :
swapped = True

while ( swapped ) :
swapped = F a l s e
f o r i in range ( len ( o u r l i s t ) − 1 ) :
i f o u r l i s t [ i ] > o u r l i s t [ i +1]:
o u r l i s t [ i ] , o u r l i s t [ i +1] = o u r l i s t [ i +1] , \
our list [ i ]
swapped = True

3 http://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/listings/listings.

pdf

16
14.3.2 Minted
For the minted4 package, the environment is also called minted. The syntax is:

\begin{minted}{YOUR_LANGUAGE}
CODE GOES HERE
\end{minted}

Example output:

def bubble_sort(our_list):
swapped = True

while(swapped):
swapped = False
for i in range(len(our_list) - 1):
if our_list[i] > our_list[i+1]:
our_list[i], our_list[i+1] = our_list[i+1], \
our_list[i]
swapped = True

15 Bibliography
Lastly, we’ll look at how to use bibliography. I won’t go into the best ways of
managing bibliographies, you may use any software you want, or do it manually.
The important thing to know is that you need the bibliographical information
for some article, book, website to be in a specific format. For academic works,
Google Scholar or Semantic Scholar are pretty good, as you can use them to
find the articles and they give the info in the format required. You’d just have
to copy and paste it (Figure 3)! Collect the info on the items you want to cite
in a .bib file and put it in the same folder as your main LATEX source file.
The idea is that each item you want to cite has an entry in your .bib file.
For example:

@inproceedings{radu2016leia,
title={LeiA: A lightweight authentication protocol for CAN},
author={Radu, Andreea-Ina and Garcia, Flavio D},
booktitle={European Symposium on Research in Computer Security},
pages={283--300},
year={2016},
organization={Springer}
}

• @inproceedings is the entry type. In this case, the paper was pub-
lished in some proceedings; most popular types are @book, @article,
@inproceedings, @conference, @manual (a technical manual), @masterthesis,
@phdthesis, @techreport, @unpublished or @misc. @misc is mostly used
to cite web pages, but can be anything that doesn’t fit the other types
(e.g. some personal correspondence, lecture notes)
4 http://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/minted/minted.pdf

17
Figure 3: Getting the BibTeX information from Google Scholar.

• radu2016leia – this is the entry keyword; it needs to be unique to


each entry in your .bib file. You can choose the keyword to be anything
you want (a good style of managing bib entries is to make the keyword
the surname of the first author, the publication year and the first word of
the item title). This keyword will later be used to actually cite the item
in text.
• the rest of the entries are called fields, and which are needed depends
on the entry type usually. Which is why getting them through some
specialised citations software or from a Scholar website is easiest. BibTeX
will complain if an entry of any type does not have a title, an author or a
year (except for @misc, which is fine without a year). Everything else is
optional.

Citing websites is the only type that needs to be manually created if you’re
not using software and browser plugins. A bib item for a website looks like this:

@misc{paperpile_bibtex,
title={A complete guide to the BibTeX format},
howpublished={\url{https://www.bibtex.com/g/bibtex-format/}}
author={Paperpile},
year={na}
}

We need to tell our main document two things in order to make this work
(best practice is to put this at the end of the document, but before any appen-
dices):

18
• the style for the citations; e.g. this document uses
\bibliographystyle{plain}
Another popular style is apalike, which inserts the surnames of the au-
thors and the year in the text as citation ([Radu and Garcia, 2016]) e.g.,
instead of the [2] we currently see. alpha is also quite popular; it creates
a (at most) 3-letter key from the surnames of the first three authors and
appends the last two digits of the publication year (e.g. [RG16]).
• the .bib file where we have all the bibliographical information. We do
this with the \bibliography{FILENAME.bib} command.
Now we can cite our references in the text! We do this with the command
\cite{KEYWORD}.
The output of

For example, the first paper I published in my PhD


was~\cite{radu2016leia} and Paperpile~\cite{paperpile_bibtex}
have a good explanation on BibTeX formats!

is:
For example, the first paper I published in my PhD was [2] and Paperpile [1]
have a good explanation on BibTeX formats!
You’ll be able to see the References section at the end of the document, with
the full info of the paper and website we cite.

If you are not using Overleaf to compile your document (so if you’re using
LATEX on your own system directly, through some editor of your choice),
you must remember the following: you must compile the document
multiple times, to get the references included correctly in the document.
You need to run:
pdflatex <document_name.tex>
bibtex <document_name.tex>
pdflatex <document_name.tex>
pdflatex <document_name.tex>

16 Table of Contents
Inserting a table of contents is very easy! It automatically gets generated from
your \section and \subsection titles. Just insert \tableofcontents wher-
ever you want it to appear. I’ve put mine here, but you’d usually insert it at
the beginning of your document. You’ll notice that this table of contents picked
up the headings I exemplified in Section 5. You will also notice that the starred
subsection I used does not appear in the table of contents.

Contents
1 Introduction 1

19
2 Structure 1

3 Document Classes 3

4 Packages 3

5 Headers 3

6 Hi, I’m a section! 3


6.1 Hi, I’m a subsection! . . . . . . . . . . . . . . . . . . . . . . . . . 3
6.1.1 Hi, I’m a subsubsection! . . . . . . . . . . . . . . . . . . . 3

7 Basic typesetting knowledge 4

8 Lists 4
8.1 Unordered lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
8.2 Ordered (numbered) lists . . . . . . . . . . . . . . . . . . . . . . 5
8.3 Changing the list marker . . . . . . . . . . . . . . . . . . . . . . . 5
8.4 List spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

9 Graphics 5

10 Floats 7

11 Tables 8

12 Labels and referencing 10

13 Maths 11
13.1 In-line mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
13.2 Display mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
13.2.1 Unnumbered . . . . . . . . . . . . . . . . . . . . . . . . . 12
13.2.2 Numbered . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
13.2.3 Alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
13.3 Useful symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
13.4 An example from reasoning . . . . . . . . . . . . . . . . . . . . . 13

14 Listings and code 14


14.1 Verbatim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
14.2 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
14.3 Source code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
14.3.1 Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
14.3.2 Minted . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

15 Bibliography 17

16 Table of Contents 19

17 Done! 21

20
17 Done!
I hope this gives you a better idea of how to approach LATEX! Remember, there
are many, many things you can do with it. Google and StackOverflow are your
friends, and so are the manuals of various packages.
Enjoy your beautiful documents!

References
[1] Paperpile. A complete guide to the bibtex format. https://www.bibtex.
com/g/bibtex-format/.

[2] Andreea-Ina Radu and Flavio D Garcia. Leia: A lightweight authentication


protocol for can. In European Symposium on Research in Computer Security,
pages 283–300. Springer, 2016.

21

You might also like