A short and simple guide to LaTeX. I wrote this up as a resource for my colleagues, and perhaps it can be of use to others as well. This guide assumes no previous knowledge of LaTeX, programming, or anything that uses code. This is based on my experiences teaching LaTeX to complete beginners.

Why use it?

If you’ve come this far, I will assume you are already convinced of the usefulness of LaTeX (or you need to use it because of your collaborators or publisher requirements), so I won’t bore with you that. I’ll just briefly describe it.

LaTeX is a document preparation system. You write your document in plain text, and along the way include some information about its structure. The result is a nicely formatted .pdf file. There are a couple of main advantages to this when compared to word processors:

• it’s much easier to write structured documents, since it allows you to clearly separate content and formatting (you worry mostly about the former)
• the consistency and typographical quality of your documents will be excellent.
• You can typeset things that are very hard or impossible to do with regular word processors.

The idea is that you realize how useful this is by simply using it.

Getting started

There are two ways of using LaTeX these days:

• offline (you install the LaTeX system on your computer and use it like any other program)
• online (you use a web platform, something like a Google Docs for LaTeX)

Since this is all about simplicity, for this tutorial we will work online. This means you will not have to install anything, and can start right away with no hassle.1

We will use a platform called Overleaf. There are other ways, but this is probably the simpler. Click the Overleaf link and create an account.2

Start a new project, choose the “blank” template, and you will be ready to go.

You will see two panes: the left pane is where you write your document, and in the right pane you will see a preview of the output. By default, this preview is updated in real time. This means that the system keeps going over your document non-stop, looking for changes, and showing you how it will look like. You can also set this to manual (at the top of the right pane), and click “refresh preview” whenever you want to see the current preview of your document. You can download the actual .pdf file at any time by clicking “PDF” in the top menu.

I will now ask you to actually switch to Manual preview. Throughout this guide, whenever you see this:

refresh preview

that’s me telling you to go ahead and click “refresh preview” on Overleaf (you can of course refresh the preview whenever you like, but this way you will see the progress in what I believe is an intuitive way.)

Files

When you work on a LaTeX document, you work on a .tex file (for example, main.tex). This is also called the source or source file. To get a .pdf, you compile that file. In Overleaf, you compile your file by clicking “refresh preview”.

In Overleaf, you will see to the left all of the files you are working with (you show or hide this by clicking “PROJECT”). For now, you just have main.tex. You can rename this to whatever you like, as long as file extension is still .tex.

Using commands

LaTeX works with commands. These tell the system what to do with the text you write. Don’t feel intimidated. Remembering where things are in menus (which change from one computer to another, and from one version of a program to another) is much harder.

So, for example, if you want to type a section header, like an “Introduction” section, you don’t need to make the text a little bigger and bold, or whatever you usually do to make it clear that’s the name of the section. Instead you use a command \section{Introduction}, and LaTeX will interpret that and output a properly formatted section header that reads “Introduction” (with automatic numbering and all!). This is indeed the main idea: you tell LaTeX what something is, and LaTeX knows what to do with it and what to make it look like.

Let’s go over the different types of commands in LaTeX.

Command types

Commands start with \, followed by the name of the command. Some commands do things by themselves, and others act on something else that you specify (called an argument), which you put inside curly brackets ({}).

Commands without arguments do something:

\command


Commands with arguments apply to or are used to select something:

\command{argument}


Some commands also have optional arguments (also called options), which you put inside square brackets ([]). These options change in some way what the command does exactly:

\command[option]{argument}


When not mutually exclusive, you can use several options at the same time by separating them with commas:

\command[option1,option2]{article}


There are also environments, which always begin and end, and will apply to whatever is inside them.

\begin{environment}
stuff inside the environment
\end{environment}


All of the commands you’ll be using will look something like the examples above. It will become clearer; don’t worry.

Let’s start!

Preamble

We will start with our preamble. The preamble is where information pertaining to our document goes. This is the kind of stuff you would find in the document and layout properties in other programs you might be used to; not yet what you actually write in your document.

Document class

The first thing to determine is the kind of document you will be writing, by choosing a document class. Common ones are article, book or report. For this tutorial we will use article. You declare it the following way, at the very top of your source file:

\documentclass{article}


This will select a layout that’s appropriate for an article.

Title & Author

Then you give your document a title, with the \title command:

\documentclass{article}
\title{My article}


And an author, with the \author command:

\documentclass{article}
\title{My article}
\author{John Smith}


So now you have a basic preamble. So far you’ve decided it’s an article, and you have included author and title information.

Document

Now you will start writing your actual content, by using the document environment.

\documentclass{article}
\title{My article}
\author{John Smith}

\begin{document}
The content of our article will be here.
\end{document}


refresh preview

Everything above \begin{document} will be considered the preamble, and everything from that point on until \end{document} will be the content of the document. Anything below \end{document} will be ignored.

You will notice that even though you told LaTeX the title and author of your paper, you still can’t see them anywhere. That’s because you haven’t included anything in your document yet. Let’s display the title and author with the \maketitle command in your document:

\documentclass{article}
\title{My article}
\author{John Smith}

\begin{document}
\maketitle

\end{document}


refresh preview

Now you should see your title and author name.

Date

You will also see that today’s date has appeared. This is what happens by default. You can, however, change it to whatever you like by using the \date command in the preamble. If you want it to read “2017” (but it can actually be whatever you want, date or not), you do the following:

\documentclass{article}
\title{My article}
\author{John Smith}
\date{2017}

\begin{document}
\maketitle

\end{document}


refresh preview

If you do not want the date to show up, use the command but leave it empty: \date{}.

Sections

A paper usually has sections. Let’s give our document an “Introduction” section, by using the \section command:

\documentclass{article}
\title{My article}
\author{John Smith}

\begin{document}
\maketitle

\section{Introduction}

\end{document}


refresh preview

Notice how that section header is in bold, has a larger font, and is numbered. LaTeX automatically numbers sections, and if you move them around the numbers will be automatically adjusted. Let’s add some text below it too.

\documentclass{article}
\title{My article}
\author{John Smith}

\begin{document}
\maketitle

\section{Introduction}
This is the first sentence of my introduction.

\end{document}


refresh preview

Now you have some normal looking text. No special command is needed for that.

Let’s add a subsection, and while we’re at it, a subsubsection as well (with the \subsection and \subsubsection commands), with some text under each of them.3

\documentclass{article}
\title{My article}
\author{John Smith}

\begin{document}
\maketitle

\section{Introduction}
This is the first sentence of my introduction.
\subsection{Some more stuff}
This is some stuff that's a little more specific.
\subsubsection{Even more stuff}
This is even more specific.

\end{document}


refresh preview

You will see that each level has been formatted and numbered accordingly. Add some more on your own, and move them around. See how the numbers change.

This alone would allow you to write a simple, beautifully formated article.

You can also have unnumbered sections, by adding a star (*) to the section commands:

\documentclass{article}
\title{My article}
\author{John Smith}

\begin{document}
\maketitle

\section*{Introduction}
This is the first sentence of my introduction.
\subsection*{Some more stuff}
This is some stuff that's a little more specific.
\subsubsection*{Even more stuff}
This is even more specific.

\end{document}


refresh preview

These sections will now be unnumbered. You can also combine numbered and unnumbered sections. This is useful for including, for example, an “Acknowledgments” section at the end of your paper, which is usually unnumbered.

Let’s change them back to numbered (without the *).

refresh preview

Adding a table of contents amounts to using the \tableofcontents command where you want it to appear (usually, just below the title and author in your document). So we’ll add it just below the \maketitle command:

\documentclass{article}
\title{My article}
\author{John Smith}

\begin{document}
\maketitle
\tableofcontents
\section{Introduction}
This is the first sentence of my introduction.
\subsection{Some more stuff}
This is some stuff that's a little more specific.
\subsubsection{Even more stuff}
This is even more specific.

\end{document}


refresh preview

That’s all there is to it. A table of contents will be generated. Whenenever there’s a change, the table of contents will be automatically updated: section numbering, section names and page numbers will always correspond to the current state of your document.

Some simple text formatting

You will want to format text in different ways every now and then (e.g. bold or italic). Common ways of formatting text are available through the following commands:

• italic: \textit{word} (keyboard shortcut in Overleaf: cmd ⌘ + i / ctrl + i)
• bold: \textbf{word} (keyboard shortcut in Overleaf: cmd ⌘ + b / ctrl + b)
• small caps: \textsc{word}
• typewriter style: \texttt{word}
• emphasis: \emph{word}

Let’s try them all out:

\textit{This sentence is italicized.} \textbf{This sentence is bold.} \textsc{This sentence is in small caps.} \texttt{This sentence is in typewriter style.} \emph{This sentence is emphasized.}


refresh preview

You will notice that \emph results in italicized text. If you use \emph on text that’s already italicized, however, it will emphasize text by putting it back to regular. Try it out:

\textit{This sentence is in italics but the last word is \emph{emphasized}.}


refresh preview

Because of this, it is good practice to use \emph when you want to emphasize (which is very often the case) and \textit when you want something to be explicitly italicized (like, say, a name of a gene or a species).

This is a good opportunity to say that, as you saw in the example just above, you can include commands inside other commands. If your section has the name of a species, for example, which by convention should be italicized, you can use \textit inside of \section:

\section{Cognitive abilities of \textit{Homo Sapiens}}


Special characters

Some characters have a special meaning in LaTeX, in that they are interpreted as part of a command: &, %, $, #, _, {, }, ~, ^, and \. This means that if you want to type them in as actual characters, you have to tell LaTeX that they are not part of a command. To type in these symbols as actual characters, you can use, respectively: \&, \%, \$, \#, _, \{, \}, \textasciitilde, \textasciicircum, and \textbackslash.

You will notice that most of them just require a backslash (\). This means that the backslash acts as what’s called an escape character, that is, it changes the original meaning of those special characters (in these cases, it changes them from special into regular characters).

A note on quotation marks

For correctly displaying correction marks, you have to use  for opening them and '' for closing them:

text in quotes''


which will give you the correct format:

“text in quotes”

If you use: ''text in quotes''

You’ll get the incorrect:

”text in quotes”

Paragraphs and linebreaks

If you want to start a new paragraph, simply leave an empty line between blocks of text (e.g. press twice):

\section{Introduction}
We have described our methodology in the previous paragraph.
In the next paragraph, we will discuss our results.

Our results show that subjects were able to distinguish A from B.


refresh preview

You will see that the first line on the new paragraph will automatically indent. If you leave more than one empty line, the output will be the same.

You can space things out as much as you want if it helps you keep things clean in the source file.

If you want to go to the next line, without starting a new paragraph, you can use a line-break (\\)

\section{Introduction}
In the next line, we will discuss our results.\\
Our results show that subjects were able to distinguish A from B.


refresh preview

This is a good way of adding more info in the author field, such as an affiliation. Go back to the author line and try that out:

\author{John Smith\\University of Research}


refresh preview

If you want to be more drastic and go directly to the next page, you can use the command \newpage or \clearpage:4

\section{Introduction}
We will go directly to the next page.
\newpage
Here we are, in the next page.


refresh preview

Lists

There are two kinds of lists that most people use. These are numbered (or ordered) and unnumbered (or unordered). For numbered lists we have the enumerate environment, which will automatically number each item. For unnumbered lists we have the itemize environment, which will list items with bullet-points. Each item in a list is entered with an \item command. Here’s an example of a numbered list:

\begin{enumerate}
\item something
\item something else
\item something more
\end{enumerate}


refresh preview

And an unnumbered list:

\begin{itemize}
\item something
\item something else
\item something more
\end{itemize}


refresh preview

You can also embed different kinds of lists:

\begin{itemize}
\item something
\begin{enumerate}
\item of one type
\item of another type
\end{enumerate}
\item something else
\item something more
\end{itemize}


refresh preview

There is a third kind of list that is not used as frequently, but which is handy, for example, for definitions. It uses the description environment, and to each item you append the term to be described or defined with square brackets ([]). Here’s an example:

\begin{description}
\item[car] a four wheeled vehicle.
\item[bicycle] a two-wheeled vehicle.
\end{description}


refresh preview

You can also put description lists inside other kinds of lists.

Naturally, you can embed lists of the same kind as well.

\begin{enumerate}
\item Vehicles
\begin{enumerate}
\item car
\item bicycle
\end{enumerate}
\end{enumerate}


refresh preview

Abstract

You can add an abstract at the beginning of your paper by using the abstract environment:

\begin{document}
\maketitle
\begin{abstract}
This is the abstract of our paper. It summarizes the methods and results.
\end{abstract}
\end{document}


refresh preview

This adds a centered “Abstract” heading and the abstract text in a slightly narrower width than the rest of the text, and a smaller font as well.

Footnotes

Footnotes are easy to do. Just include the footnote text inside a \footnote command, which will do all of the work for you:

This issue is not central to our paper.\footnote{We leave it for future work.}


refresh preview

This will both add the footnote marker to your text, and the corresponding footnote at the bottom of the page. As you might expect by now, numbering is automatic, and if you add, delete or move footnotes around the numbering will update accordingly.

Tables

Tables in LaTeX are easy in principle, but there is no way around it: when tables get complicated, it also gets complicated to do them in LaTeX. But let’s go over a simple example. For a table, you use the tabular environment, and you specify the number of columns and their alignment with letters that stand for the different kinds of alignment. In the example below, we want our table to have three columns, all left aligned, so we use three ls:

\begin{tabular}{lll}

\end{tabular}


As you might have guessed, r will produce a right-aligned column, and c a center-aligned one.

Now you add your cells by adding a row of three values separated by &:

\begin{tabular}{lll}
item & type & amount
\end{tabular}


refresh preview

For more than one row (vely likely), you use a line-break (\\), and add more lines:

\begin{tabular}{lll}
item & type & amount\\
car & vehicle & one\\
\end{tabular}


refresh preview

Vertical borders in tables are a typographical no-no (pick up a professionally typeset book and find a table; you will most likely not see a lot of vertical lines, if any), but you can add them as needed by adding a pipe (|) where you want the border to be when you define the number and alignment of the columns (so instead of lll, we can have |l|l|l|):

\begin{tabular}{|l|l|l|}
item & type & amount\\
car & vehicle & one\\
\end{tabular}


refresh preview

Horizontal borders are added where you want them to appear in between the rows by using \hline:

\begin{tabular}{|l|l|l|}
\hline
item & type & amount\\
\hline
car & vehicle & one\\
\hline
\hline
\end{tabular}


refresh preview

Again, it is good typographical practice is to minimize borders, as long as your table stays readable. This will look much better (just one line separating the titles of the columns from the rest):

\begin{tabular}{lll}
item & type & amount\\
\hline
car & vehicle & one\\
\end{tabular}


refresh preview

It’s also nice to format the column headers a bit differently to make it clear they are headers, e.g.:

\begin{tabular}{lll}
\textit{item} & \textit{type} & \textit{amount}\\
\hline
car & vehicle & one\\
\end{tabular}


refresh preview

So far what you have is just some rows and columns with values. There nothing telling us what it is. If you are writing a paper, you will want it to be numbered and a have caption. For that you use the table environment, which you put around your tabular:

\begin{table}
\begin{tabular}{lll}
\textit{item} & \textit{type} & \textit{amount}\\
\hline
car & vehicle & one\\
\end{tabular}
\end{table}


refresh preview

And you can also add a caption with the \caption command,

\begin{table}
\begin{tabular}{lll}
\textit{item} & \textit{type} & \textit{amount}\\
\hline
car & vehicle & one\\
\end{tabular}
\caption{Summary of products bought.}
\end{table}


refresh preview

If you want your table to be centered (which you probably do), add \centering just below \begin{table}:

\begin{table}
\centering
\begin{tabular}{lll}
\textit{item} & \textit{type} & \textit{amount}\\
\hline
car & vehicle & one\\
\end{tabular}
\caption{Summary of products bought.}
\end{table}


refresh preview

Now, when things get more complicated, I recommend using a tool that lets you edit a table in a spreadsheet-like fashion and then get the corresponding LaTeX code, which you can paste onto your document. I recommend the LaTeX Table Generator. That’s what I use most of the time, but it’s good to know the basics of how tables work in case you need to fine-tune your table, or in case something goes wrong and you need to fix it.5

(Bear in mind that you can actually put anything inside a table environment; it doesn’t have to be a tabular).

By the way, you can also generate a List of Tables, by using the \listoftables command where you want it to appear.

Cross-references (or labeling and referring)

You know when you write in your paper “see Section 3”, but then you move it around and it’s not Section 3 anymore? Or “see Table 5”, but you actually now have 3 new Tables that come before it? Maybe you even do things like “see Section XX” because you know you’ll have to go over the whole text in the end to fix it anyway. This is not a problem in LaTeX, because you can label and refer to things, regardless of where they are. You don’t need to keep track of and manually type in the numbers. Anything that’s numbered can be labeled with the \label command. For example:

\section{Results}
\label{results}
Our results are as follows...


You can now refer to that numbered section by using the \ref command:

\section{Introduction}
In Section \ref{results}, we will present our results.


refresh preview

This will display the current number of the section you are referring to, whatever it is. This applies to all numbered elements.

If you move a section around, or even if you make it into something else, like a subsection, the reference to it will update accordingly. So you never have to worry about that. From now on, instead of wasting time fixing cross-references because a reviewer asked for a new footnote, or for a section to be removed, you can just worry about the content and be done with it.

It is good practice to label things if you think you might need to refer to them (or even if you think you won’t; you never know). It is also good practice to label each element with some clue as to what kind of element it is. For example, I would label my introduction section with \label{sec:intro}. That sec: part tells me it’s a section.

Similarly, when labeling a footnote I would use fn: as part of the label name:

We used method so and so.\footnote{\label{fn:method} We made sure to follow ethical procedures.}


This is useful because it makes labels easier to remember. When you start start typing \ref in Overleaf you will also get a list of all labels that you have, sorted alphabetically, and this makes it much easier to find what you need. But, of course, you can use whatever you like as a label name.

You can also refer to the page (instead of the number) of any element, by using the \pageref command:

\section{Introduction}
\label{sec:intro}

...
\section{Conclusions}
As we've seen in the Introduction, on page \pageref{sec:intro},...


refresh preview

Instead of the section number, you will get the page where the section starts. The label it’s still the same; you just used a different the way to refer to it.

With what you’ve learned so far, you could write a decent article. But from now on is when things start getting more interesting.

Using packages

Packages add functionality to LaTeX. They give you the ability to use extra features that are not available by default. To make yet another word processor analogy, this would be like going to the settings in Word and enable a functionality that by default is not enabled. Packages are declared in the preamble with the \usepackage command, which we use to select specific packages:

\usepackage{packagename}


Some packages might also allow you to use certain options, which you do the following way:

\usepackage[option]{packagename}


After loading6 a package, you will either have new commands at your disposal, or you will have changed something about your document (or both). You will see that using packages is quite a common thing.

From this point on we will cover things that make use of packages.

Citations and Bibliography

If you are used to typing in your references manually and checking everything for mistakes very carefully after your paper is finished, always on the lookout for citations in the text that do not appear in the list of references and vice-versa, your life is about to change (and be honest, you know that’s what you do).

LaTeX uses a reference management system called BibTeX, which works in the following way:

• you have a separate file with a list of references
• you use a command to cite the references you need in your document
• everything you cite (no more, no less) appears automatically in a References section at the bottom of the paper, always in a consistent format.

Let’s break it down.

References file (.bib file)

So far, we’ve been working on a .tex file, our document. That’s where you have been typing in (or pasting) the commands you’re learning about. But now we will add another file, which will have a .bib extension. Let’s call it refs.bib. This is the file where you will have all of your bibliographical entries, which you can cite in your document.

To add this file in Overleaf, click on Files… (left menu) and choose Add… Blank File. Name it refs.bib. Now we have to add bibliographic entries to it.

A typical bibtex entry looks like this:

@article{smith2017,
author = {Smith, John},
title = {Some paper},
year = {2017},
journal = {Journal of Research},
volume = {2},
number = {1},
pages = {1--69}
}


You can see that each entry starts with a @, followed by the kind of source it is (in this case, an article, but it could be a book, a book chapter, a proceedings volume, a thesis, etc.), a unique id that you can later use to cite this particular entry, which can be whatever you want (in this case it’s smith2017), and several fields with information about the entry.

Your .bib file will have several such entries. Until you actually cite them, they do nothing. This means you can store thousands of entries in a .bib file, ready for you to use, and cite only those you need for the particular paper you are writing.

Getting bibliographical information into your .bib file

There are different ways of getting the information onto your references file. One of them is to type them in. This is not the nicest thing in the world, but remember you only have to do it once, and you will be able to cite it whenever you need to in the future. Still, it’s far from ideal.

There are actually programs that can work with .bib files and let you edit their contents in a nice interface. A popular one is BibDesk (MacOS only, I believe). There are other popular, cross-platform bibliography managers that you might even already use that can also generate a nice .bib file for you to use in your LaTeX papers, such as Mendeley, Zotero and JabRef. All of these allow you to export your database as a .bib file.7 Check this Wikipedia entry for a list of .bib-compatible reference managers.

One other way is to copy the citation from somewhere. If you use Google Scholar, you surely have noticed the (previously, “cite”) option that appears under each article. When you click that, you get different formats. One of them is “BibTex”. Click that option, and it will show you an entry like the one you saw above:

@article{smith2017,
author = {Smith, John},
title = {Some paper},
year = {2017},
journal = {Journal of Research},
volume = {2},
number = {1},
pages = {1--69}
}


If you ever clicked it by accident and wondered what the hell it was, now you know. You can just copy and paste it onto to your refs.bib file.8

Many publisher and institutional websites also provide similar functionality. Some people also provide citations in BibTeX format in their publication pages (I do it as well), or provide .bib files with entries for all of their papers.

If you haven’t done so yet, let’s go ahead and actually paste that whole entry into our refs.bib file.

Setting up

Setting up your citation workflow requires three quick steps.

First, we will load the natbib package, which will give us some useful functionality.9

\usepackage{natbib}


Then, you must select the format you want to use. There are many to choose from. If you want to use, say, APA style, you have to declare it as follows:

\usepackage{natbib}
\bibliographystyle{apalike}


The name of the APA style in BibTeX happens to be apalike. Other popular ones include harvard or chicago. Usually, a quick google search (“X style in latex”) will tell you the name of the formatting style you are looking for. Publishers might also provide you with their own bibtex style file (it will always be a .bst file), which you can place in the same location as your .tex and .bib files.

Finally, you have to say in your document where you are getting your references from: your refs.bib file. You do this where you want the “References” section to appear, at the bottom of the paper (but, remember, before \end{document}!):

...
\bibliography{refs}
\end{document}


Let’s recap. If you have a bib file with at least one bibliography entry (we have one, which we called refs.bib) and your main.tex file has at least the following, you are good to go:

\documentclass{article}
\usepackage{natbib}
\bibliographystyle{apalike}
\begin{document}
Our content here.
\bibliography{refs}
\end{document}


refresh preview

Citing some papers

Now you can actually start citing. The default command for citing is, you guessed it, \cite. Let’s cite our entry somewhere in our document:

As shown in \cite{smith2017}, results indicate...


refresh preview

This will do two things. The first is that your text will look like this:

As shown in Smith (2017), results indicate…

The other is that you will find that you now have a “References” section at the bottom of your document, with the entry you cited:

Smith, J. (2017). Some paper. Journal of Research. 2(1): 1—69.

You probably also noticed that as you were typing the “\cite” command in Overleaf, as soon as you typed in the { you were shown your smith2017 entry before you finished typing. Much like with labels, Overleaf has auto-complete for bibliographic entries!

The usefulness of bibtex becomes apparent when you realize you can have all of your references ready to be cited whenever you need them.

natbib provides other useful commands, besides the default \cite.

The most useful is \citep, for parenthetical citations. This:

Our results support previous work on this topic \citep{smith2017}.


refresh preview

will give you:

Our results support previous work on this topic (Smith, 2017).

You can also add other information (usually page or chapter numbers) to your in text citation as follows:

Our results support previous work on this topic \citep[p. 57]{smith2017}


refresh preview

In the case of the formatting style you are using (APA) this will give you:

Our results support previous work on this topic (Smith, 2017, p. 17).

By default, natbib assumes you will be using “author-year” citation styles, but numerical citation styles (very common in the hard sciences) are also easy to get, by using the numbers option in the natbib package:

\usepackage[numbers]{natbib}


Now, if you cite your source:

Our results support previous work on this topic \cite{smith2017}.


refresh preview

you will get in your text:

Our results support previous work on this topic [1].

And in the reference list:

[1] Smith, J. (2017). Some paper. Journal of Research. 2(1): 1—69.

You can find a list of useful citation commands in the Reference sheet for natbib usage.

Citing multiple references at the same time

If you want to cite multiple references at the same time (which is very likely), you can do so by using whatever citation command you wish (say, \citep), and include multiple references separated by commas, without any spaces between them:

\citep{kepler1619,lenneberg1967,smith2017}


which, depending on the style you are using, will give you:

(Kepler, 1619; Lenneberg, 1967; Smith 2017)

Images/Figures

When you write a paper, you will often need to include images of some sort.

The first thing you will need is to have your figure in the same location as your .tex file. So please go ahead and upload an image to your project in Overleaf (Files… > Upload from…). In the examples I’ll assume it’s called my_picture.png.

To be able to include images, you must load the graphicx package:

\usepackage{graphicx}


Now in your document you can use the \includegraphics command where you want your image to appear:

\includegraphics{my_picture.png}


refresh preview

It’s possible that your image is too big and just goes all over the place. You can solve that by specifying a width:

\includegraphics[width=10cm]{my_picture.png}


refresh preview

This doesn’t change your image file in any way; your file will be untouched. It just places it in the document with a width of 10 cm. LaTeX understands, among others, the following units: pt (points), mm (millimeter), cm (centimeter), in (inch), ex (the height of ‘x’) and em (the width of an ‘M’).

You can also define a relative width like, say, the width of the text, which is represented by \textwidth:

\includegraphics[width=\textwidth]{my_picture.png}


refresh preview

Or even a percentage of the textwidth:

\includegraphics[width=0.75\textwidth]{my_picture.png}


refresh preview

Other options similar to width are:

height (exact height):

\includegraphics[height=5cm]{my_picture.png}


refresh preview

scale (size of the image, with 1 being actual size)

\includegraphics[scale=0.5]{my_picture.png}


refresh preview

angle (rotation angle, in degrees):

\includegraphics[angle=90]{my_picture.png}


refresh preview

Now, this is still not a figure; it’s just an image the middle of the paper. To make it an actual figure, you need to put it inside the figure command:

\begin{figure}
\includegraphics[width=0.75\textwidth]{my_picture.png}
\end{figure}


This allows you to add a caption, and it will number the figure.

\begin{figure}
\includegraphics[width=0.75\textwidth]{my_picture.png}
\caption{A picture of my dog.}
\end{figure}


refresh preview

Now your figure is numbered, and has a caption. Remember: if the figure is numbered, that means you can refer to it if you want to. All you need to do is label it.

\begin{figure}
\includegraphics[width=0.75\textwidth]{my_picture.png}
\caption{A picture of my dog.}
\label{fig:dog}
\end{figure}


Now you use:

As we can see in Figure \ref{fig:dog}, my dog is a Rottweiler.


refresh preview

You can also generate a List of Figures, by using the \listoffigures command.

Bear in mind that you can actually put whatever you want inside a figure environment. If I do:

\begin{figure}
HELLO.
\end{figure}


my figure will be the word “HELLO”.

On image formats

You can insert images in .jpeg, .png, .eps and .pdf formats. Images in vector format (.eps and .pdf) are preferred over bitmap images. If no vector format is available, .png is the next best choice, unless the image is a photograph, in which case .jpeg is the most adequate format.

When trying to decide which format to use, pay attention as well to publisher requirements, if applicable. They will usually have requirements not only on format, but also on resolution (usually, at least 300 dpi).

On file location

You don’t necessarily need to put your images or any other files (like the .bib file) exactly in the same location as your .tex file. You can have it anywhere else, provided you tell LaTeX where to find it. I just keep telling you to put files in the same location as the .tex to keep things simple for now.

But as a project grows, and in order to keep things clean, it is good practice to have, for example, a “figures” folder in the project, and inside it all your figures. In that case, you would have to provide the correct relative path to the image:

\begin{figure}
\includegraphics[width=0.75\textwidth]{figures/my_picture.png}
\end{figure}


Instead of telling LaTeX to look around for my_picture.png, this tells it to look into the figures folder for my_picture.png).

Figure and table (float) positioning

Figures and tables (not the actual images and tabulars, but the containers corresponding to the figure and table environments) are what’s called floats. Floats are not part of the text itself, and cannot be broken up. For this reason, they might not occur where you have them in your source file. Instead, if there is no room for a Table or Figure, they might be placed somewhere else on the same page, or even on a different page altogether. LaTeX follows typographical principles that push floats towards the top or bottom of the page when there is no room for them elsewhere. These principles are the reason why it’s always a good idea to refer to your figures and tables by number (remember, use \label and \ref!), and not use expressions like “below.” You can never be 100% sure that floats will not be rearranged for better typographical quality.

However, you might want to force a tendency or an absolute position in some cases. LaTeX provides a way of doing that, through placement specifiers. These are:

• h: put it here (approx. same location as in source)
• t: put it at the top of the page
• b: put it at the bottom of the page
• p: put it on a page where all floats will go

You can do it by including the corresponding specifier in square brackets, just after you begin your figure or table environment. For example, if you want a figure to be at the top of the page, you do:

\begin{figure}[t]
\includegraphics{figures/my_picture.png}
\caption{This is my picture.}
\end{figure}


There is also a ! option that you can include in the specifier (.e.g. [!h]), which basically means “ignore good typographical practices and really put it where I’m telling you to.”

You can also use more than one specifier and LaTeX will go through them and choose whichever is more typographically sound. (e.g. [htp]).

Using diacritics & documents in different languages

If you try using diacritics, in many cases you will see you will get a missing letter instead.

You try something like this:

\section{Modèle génératif}


refresh preview

and you will get “1. Modle gnratif”.

The common way to guarantee LaTeX will understand and output most diacritics properly is by using the inputenc and fontenc packages—remember: packages always go in the preamble!—, with the following options:10

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}


refresh preview

Now everything should display correctly.

But there are still elements whose names you can’t control,11 like “Contents” in the table of contents, the name of the “References” section, or the date. If you write in a different language, it makes sense those are in a different language as well. You don’t want to write in French and have a table of contents called “Contents”. This is solved with the babel package. The babel package helps you with “language-determined” typographical and orthographical aspects, such as hyphenation or the names of those “hard-wired” sections or the date. For example, if you write in Finnish, you can use:

\usepackage[finnish]{babel}


Use the name of your language and see the differences!

refresh preview

Most likely, the language you want to use is supported by babel.

Math

Math is actually for many the reason to use LaTeX. LaTeX is the de-facto standard in mathematics and other math-heavy fields like cosmology or computer science. This is so because it allows you to type in math intuitively, and it displays math beautifully. There are two ways of including math in LaTeX: inline (in the middle of your text), or display (a separate, numbered equation).

For inline math, you use the $ sign as a delimiter. So anything between two of those signs will be processed as math. For example: Albert Einstein's most famous formula is$E=mc^2$.  refresh preview The same equation in display mode, as a separate entity is done with the equation environment:  E=mc^2  refresh preview You can typeset any kind of equation:  \frac{1}{2\pi}\sum_{k=-\infty}^{\infty}e^{-ika}\left(\int_{-\pi}^{\pi}\phi(x)e% ^{ikx}\mathrm{d}x\right)=\phi(a)  refresh preview Maybe you’ll even figure out how this works by following the code and the resulting equation (e.g. how to do fractions, what _ and ^ do, etc.) Even though math is one of the big reasons to use LaTeX, I will not go further into it because: • if you were a mathematician, you would most likely know how to use LaTeX (why are you reading this guide? ;-) ) • it merits much more attention than I could give it in a tutorial of this scope • I am not a mathematician and would probably give you really boring examples Still, math in LaTeX is useful even if you don’t use mathematics per se in your work. You might still want to use mathematical symbols and other elements commonly used in math and logic. You can check out a list of symbols, or even draw it and see how to type it in LaTeX! It’s possible (and quite useful) to create hyperlinks within your document. You do so by using the hyperref package: \usepackage{hyperref}  Now, any and all cross-refs become cross-links. For example, everything in the Table of Contents becomes clickable, and you’ll be taken to the page where the corresponding section starts. All references in the text (the ones created with \label and \ref) as well as citations will be clickable. refresh preview Using this package also allows us to enter clickable URLs with the \url command: For our search we used \url{http://google.com}.  refresh preview Which will give us: For our search we used http://google.com. where “http://google.com” is clickable. You can also have any text linking to a URL, with the \href command: For our search we used \href{http://google.com}{Google}.  refresh preview which will give us: For our search we used Google. Where “Google” is clickable. Comments LaTeX generates your document by going over your text and checking for commands that tell it what to do with that text. But you might want to have something just for you to see, which is not to appear in the final document. For this you use comments, which you add by using %. Everything that follows a % in a line will not be processed by LaTeX. Here’s an example: \section{Introduction} In this paper we study the effects of X on Y. %must write this ASAP The effects of X on Y have been given little attention in the literature.  refresh preview In the example above, “must write this ASAP” will not appear in the output document because it follows a %. The second paragraph will appear, because it’s already on a different line. Comments are also very useful also for removing things from your document without having to delete them from your source, because you might want to use them later, or just want to have them. Let’s say you must remove a paragraph because you have a word-limit, or because you’re not sure if you’ll need it. You don’t have to delete it; just comment it out: \section{Introduction} %In this paper, we study the effects of X on Y. This paragraph is actually not really necessary, and I just wrote it because I needed to reach the word count I was asked to do. Turns out the paper got too long, so now I actually have to get rid of it. I still think this information is interesting, and maybe I'll use it later for something else. The effects of X on Y have been given little attention in the literature.  refresh preview The first paragraph will not appear in your document, because it’s all in the same line, and that line is now a comment (remember? paragraphs are separated by empty lines, which means each paragraph is actually one single line in your source file). Comments are also good for describing what something does. This can be useful as you learn or your document gets more complex: \documentclass{article} %this command selects the article class \begin{document} %this command starts my document \maketitle %this command outputs the title, author and date some text \end{document} %this command ends my document  Finally, commenting out might be a good way of omitting things in your preamble that you might want to keep in your file for further use. It’s exactly the same as hiding paragraphs because you don’t want to see them, but still want to keep in your file. For example, if you want to alternate between having your document display your name and “Anonymous”, you can have: \documentclass{article} %\author{John Smith} \author{Anonymous} \title{My paper} \begin{document} \maketitle \end{document}  refresh preview Conclusion: any line that follows % is ignored by LaTeX. Use it to your advantage! Field specific functionality You may want to use in your documents elements that are particular to your field. This is indeed another reason for using LaTeX. There will most likely be a package that does exactly what you need. If you have played around a bit with what you’ve learned so far, you should be able to find new information for doing the things you need to do. A Google search for “how to do X in LaTeX” will give you examples or guides. These will usually include what packages to use, all of which accompanied by documentation. Below are a couple of examples that might be of interest to you. Phonetic symbols The tipa package provides all of the phonetic symbols from the IPA. To use it, load the package in your preamble (\usepackage{tipa}), and in your text do: \textipa{[f@"nEt\i ks]}  refresh preview This will give you “[fəˈnɛtɪks]”, which is of course the phonetic transcription of “phonetics”. Here’s a tipa cheat sheet. You will see most symbols are quite intuitive. You can forget the days of IPA shenanigans when using Word: missing, incompatible and inconsistent fonts. (Syntactic) trees There are different packages that allow you to draw syntactic trees. I’ll give you an example which uses the qtree package. After loading the package, you can use the \Tree command to draw a tree. You draw trees (and subtrees) by enclosing them in square brackets. ([]). Bear in mind that roots must always be preceded by ., and that terminal (aka leaf nodes) nodes are written without a .. Also, pay attention to the spaces before closing brackets ( ]). Let’s just look at a practical example, which you will be able to figure out. This: \Tree [.S [.NP [.Det the ] [.N platypus ] ] [.VP [.V plays ] [.NP [.N guitar ]]]]  will give you: Other kinds of documents So far, you’ve been using the article document class. You can, however, write many different kinds of documents. If you want to write a book, you can use the book document class. This changes the layout of your document, and also provides you with other commands for things like chapters, which an article doesn’t have. You can also use LaTeX to prepare slide presentations, by using the beamer class. Here’s an example. By the way, there are several beamer themes. Writing a thesis? Your university might even have an official LaTeX class you can use. Ask around! You can also take a look at the hundreds of templates at Overleaf, from theses, to posters, to CVs, and everything in between. Errors If you do everything 100% right all of the time, you will not get any errors. If you are human, however, you will get errors. Whenever something is not quite right, LaTeX might refuse to compile your document, and the reason might either be obvious or at first seem a little cryptic. Modern editors and online platforms (such as Overleaf) minimize this because they help you write your commands correctly. Still, errors will happen. Some common causes are: • You forgot to close something you’ve opened: parentheses (()), curly ({}) or square brackets ([]), environments (\begin{...} ... \end{...}, math delimiters ($\$)…
• You are using characters that are special because they are themselves part of a command. For example (but see the Special Characters section for more characters):
• % is used for comments. Use \% for the percentage sign.
• & is used for separating table cells. Use \& for the ampersand.
• _ is used for subscript when writing math. Use \_ for the underscore.
• There’s a typo in a command (or missing \)
• You are using a command that is provided by a package, but you forgot to load that package (or there’s a typo). For example, if you are trying to include an image with \includegraphics, make sure you have \usepackage{graphicx} in your preamble.

Make an effort to try to decipher the error message. It often points to a specific line number, and sometimes it tells you exactly what went wrong, so you can fix it.

But I want to change how things look like

You might be tempted to change how things look. You may wonder: “why do I have to get this font, and these margins, and these bold headers?”12 There’s two or three things you have to bear in mind:

• The default look of latex is typographically sound. You worry about the content and LaTeX worries about how it looks because it is most likely a better typographer than you. Everything down to the number of characters per line is based on well-established typographical principles (that’s why it’s so easy on the eyes, not just aesthetically but also in terms of readability). Even the spacing between the letters relies on a set of algorithms that optimize the way it looks/reads. This is different from Word in the sense that Word just lets you put letters and font types and sizes together at will, which often results in messy structure or supposedly structural decisions that are based solely on what you think “looks nice”.

• Having said this, you can change the way a LaTeX document looks like, and very drastically so. But first it’s important to understand how to use it, which is the goal of this tutorial. If someone wishes to change the section headers to small caps instead of bold, it is expected that they know the basics of writing a LaTeX document first. This might be your case already if you are able to do all of the above. So go ahead and find a way of doing whatever changes you deem appropriate. :)

• Journals will not care about how you want your paper to look like (or at least, they shouldn’t). So if you are writing a paper that you will submit, you shouldn’t either. You usually submit your .tex file and they process it with their own parameters, or they provide you with their own document class or package (so instead of \documentclass{article}, you would use something like \documentclass{journal_x_template}, or use article as usual but load the journal’s package, \usepackage{journal_x_package}.) These are usually available at the publisher’s website. Many of these document classes are even available directly from Overleaf! This is also one of the great advantages of LaTeX. Sending a paper to a journal usually amounts to just sending your .tex file as is, or using their template. If it’s rejected and you must send it somewhere else, it’s as easy as changing the document class your are using. There might be other minor adjustments due to style, but that’s all there is to it really. It’s trivial. Switching formats to resend a paper if you use Word or a similar, however, is usually very non-trivial.

Having said that, below you will find some easy-to-make changes, etc. that you might find useful.

Quick reference for other useful things

This is a list of layout changes and other tips you might find useful.

Font size

The default (text) font size is 10 pt. You can also choose 11 pt or 12 pt, by specifying it as an option in your document class:

\documentclass[12pt]{article}


All other sizes are relative to this value (e.g. the font size of footnote text will be smaller when the normal text is 10 pt text than when it is 12 pt.)

You can also use the following (relative) sizes in your document:

• \Huge
• \huge
• \LARGE
• \Large
• large
• \normalsize (this is the size of the text)
• \small
• \footnotesize
• \scriptsize
• \tiny

There are two ways of using these sizes. You can either use environments named after them:

\begin{LARGE}
This text is big!
\end{LARGE}


or use the corresponding command inside something that’s delimited in curly brackets:

{\large This whole sentence is quite large}.


Page size

The default is US Letter. You can change this with the geometry package:

\usepackage[a4paper]{geometry}


You can use any A size (a0paper to a6paper), B size (b0paperto b6paper), letterpaper, legalpaper and executivepaper.

You can also define the page size manually, again with the geometry package:

\usepackage[paperwidth=15cm,paperheight=30cm]{geometry}


Margins

To change the margins, the geometry package comes in handy again. If you want all margins to be the same, do:

\usepackage[margin=1.5cm]{geometry}


If you want to specify each margin differently, do:

\usepackage[top=1cm, bottom=1.5cm, left=2cm, right=2cm]{geometry}


Columns

If you want two-column text, use the twocolumn option when declaring the document class:

\documentclass[twocolumn]{article}


Alignment

You can align elements by using the center, flushleft and flushright environments. For example:

\begin{center}
This text is centered\\and this one too.
\end{center}


or:

\begin{flushright}
Yours truly,
\end{flushright}


Font

If you want to renounce the great default LaTeX font (by the way, it’s called Computer Modern), you can do it. There are different ways of doing this. One is by using packages. One font I use occasionally for less formal writing is the following:

\usepackage{libertine}


Others like times or courier are available in a similar fashion. Go to the LaTeX Font Catalogue and knock yourself out.13

Handling multiple authors

If your paper has multiple authors, you can just write all of their names in the \author field:

\author{Jane Doe, John Smith and That Other Guy}


But there is an \and command that comes in handy for separating authors into different blocks, which is especially useful if you include other information like affiliation or email:

\author{John Smith\\University of Research\\\texttt{smith@research.edu} \and Jane Doe\\Institute of Investigation\\\texttt{doe@investigation.edu}}


There is also a package called authblk that can be useful when you have many authors, especially if most of them share affiliations, in that you will avoid repeating them:

\usepackage{authblk}

\author[1]John Smith
\author[2]John Doe
\author[1,2]Jane Doe
\author[2]That other guy

\affil[1]University of Research
\affil[2]Institute of Investigation


This will use superscript numbers to connect authors and their affiliations. The authblk package also gives you some flexibility when formatting author blocks.

Space

You can insert horizontal or vertical space.

There are commands that insert predefined lengths of vertical space, e.g.: \smallskip, \medskip and \bigskip. There are also commands for inserting predefined lengths of horizontal space, e.g.: \enspace, \quad and \qquad.

You can also use the \vspace and \hspace commands for inserting specific lengths of space, e.g.:

Some text.
\vspace{2cm}
Some more text.


Lenghts can also be negative (e.g. \vspace{-2cm}).

There are also the useful \hfill and \vfill commands, which push elements to the right or bottom, respectively, until they meet a margin:

Sentence to the left\hfill Sentence to the right.


Bonus: LaTeX in LaTeX

There’s a special command for writing “LaTeX” in LaTeX: \LaTeX.

Is this a lot to memorize?

While most regular LaTeX users can probably do all of what we covered from memory, you don’t have to (but you probably will end up being able to do it as well, without realizing it). Just keep in mind that:

• All of the stuff you have in the preamble (especially packages) will not change much, so you can start a new article by copying that part from one file to another.
• Most platforms (like Overleaf) have auto-complete, so most commands will be written for you.
• If you have doubts or want to do something that you never had to do before, Google will be very kind. You almost always find explanations with code included, which can often simply copy and paste onto your document.

There’s no shortage of LaTeX guides, some shorter than this one, and some gargantuan. If you end up getting into LaTeX and want to know more, I recommend the following free resources:

Acknowledgments

Thanks to Bridget D. Samuels for useful comments and suggestions, and to Sven Grawunder for letting me host his tipa cheat sheet.

Notes

1. If you do want to install LaTeX on your computer, I recommend MacTex (for MacOS) and MiKTeX (for Windows). If you use Linux, TeX Live is the way to go. Any of those options will install the LaTeX system on your computer. For actually writing up your documents, any text editor will work (e.g. TextEdit on Mac, Notepad on Windows, etc.), but you should use an editor made for LaTeX, which will make your job much easier (e.g. Texmaker, TeXstudio), or a code editor that has LaTeX support. I personally use the Sublime Text editor with the LaTeXTools plug-in. But before delving into any of this, please go through the tutorial using Overleaf until you are comfortable with everything it covers.

2. If you belong to a university, it’s possible that using your institutional email will give you some advantages. You can check if your institution is included in the list. Either way, having a “pro” account is definitely not necessary.

3. Sections, subsections and subsubsections are allowed by default. If you need to go deeper, you might want to rethink the structure of your paper (This is not an excuse; take a look at any published paper and try to find “subsubsubsections”. Not very likely!). Still, if you do need a “4th level”, you can try the \paragraph command (the usage is the same as the different section commands). This you give you an unnumbered, bold section title, in the same line and font-size as the rest of the text. Try it out.

4. The commands \newpage and clearpage differ in ways not worth getting into in this guide. In most cases the result will be the same.

5. In case you work offline, some of the editors I mentioned (e.g. Texmaker help draw tables (among other things) by offering you a visual wizard that will make things easier.

6. Loading a package simply means having in the preamble the command that allows you to use it, which will in effect “load” the package for you. Other terms you might find are invoking, calling (up), importing, or declaring a package.

7. Actually, even better: if you use Mendeley, Zotero or CiteULike, you can directly connect your references database to your Overleaf project. This means that whatever you have on any of those at any given point will be available for you to cite. To do that, click Files… (left menu) and choose Add… Bibliography. You will be given the option to connect to one of those services. If you add more references to your database (through the services themselves), just click on your .bib file (which now will not be editable, because it’s getting it’s information from elsewhere) and hit “Refresh”.

8. This doesn’t apply to working with .bib, but deserves mention: Google provides a “Google Scholar button” for your browser that allows you to quickly look up papers and also get the citation. When on Google Scholar, go to Settings, and then Button to install it (I believe it’s compatible with Safari, Firefox and Chrome).

9. There are other citation packages one can use (and actually you don’t necessarily need to use any package, but using a good one gives you some good extra features). natbib is quite popular, and the one I (and a lot of people I know) use, so I chose it for this guide. Very often, a publisher might give you specific instructions on what to use. The whole process will however be similar.

10. Explaining what these packages do exactly is beyond the scope of this guide. To put it briefly, the inputenc package makes sure the characters you type in are well interpreted, and the fontenc package makes sure the output is correct. Also, there actually are ways of typing in diacritics correctly without any packages. For example, \'{e} will give you ‘é’. Many people actually prefer doing that. Here’s a reference table for most diacritics.

11. Actually you can manually control what the elements I mention are called, but this outside of the scope of this guide.

12. I wish more people asked the same questions about 12 pt Times New Roman (or Calibri), 1 inch margins, double-space ;-)

13. From my experience, everyone who dabbles with different fonts in LaTeX ends up going back to the default one (even though you can use literally any font with it). The other way(s) of selecting fonts fall outside the scope of this guide. One such way involves the XelaTeX typesetting engine and the fontspec` package, which will allow you to use any font installed on your computer.