Professional Documents
Culture Documents
Learn Latex in 30 Minutes: Templates
Learn Latex in 30 Minutes: Templates
In this guide, we hope to give you your first introduction to LATEX. The guide does not require you
to have any prior knowledge of LATEX, but by the time you are finished, you will have written
your first LaTeX document, and hopefully will have a good knowledge of some of the basic
functions provided by LATEX.
What is LATEX?
LATEX (pronounced LAY-tek or LAH-tek) is a tool used to create professional-looking documents.
It is based on the WYSIWYM (what you see is what you mean) idea, meaning you only have focus
on the contents of your document and the computer will take care of the formatting. Instead of
spacing out text on a page to control formatting, as with Microsoft Word or LibreOffice Writer,
users can enter plain text and let LATEX take care of the rest.
\begin{document}
First document. This is a simple example, with no
extra parameters or packages included.
\end{document}
You can see that LATEX has already taken care of the first piece of formatting for you, by indenting
the first line of the paragraph. Let's have a close look at what each part of our code does.
The first line of code declares the type of document, known as the class. The class controls the
overall appearance of the document. Different types of documents will require different classes i.e.
a CV/resume will require a different class than a scientific paper. In this case, the class is
article, the simplest and most common LATEX class. Other types of documents you may be
working on may require different classes such as book or report.
After this, you write the content of our document, enclosed inside the \begin{document} and \
end{document} tags. This is known as the body of the document. You can start writing here and
make changes to the text if you wish. To see the result of these changes in the PDF you have to
compile the document. To do this in Overleaf, simply hit Recompile. (You can also set your project
to automatically recompile when you edit your files, by clicking on the small arrow next to the
'Recompile button and set 'Auto Compile to 'On.)
If you are using a basic text editor such as gedit, emacs, vim, sublime, notepad etc., you will have to
compile the document manually. To do this, simply run pdflatex <your document> in your
computers terminal/command line. See here for more information on how to do this.
If you are using a dedicated LaTeX editor such as TeXmaker or TeXworks, simply hit the
Recompile button. Consult the programs documentation if you are unsure of where this is.
Now that you have learnt how to add content to our document, the next step is to give it a title. To
do this, we must talk briefly about the preamble.
\author{Hubert Farnsworth}
Here you put the name of the Author(s) and, as a optional parameter, you can add the next
command:
\date{February 2014}
You can enter the date manually or use the command \today so the date will be updated
automatically at the time you compile your document
With these lines added, your preamble should look something like this
\documentclass[12pt, letterpaper, twoside]{article}
\usepackage[utf8]{inputenc}
\title{First document}
\author{Hubert Farnsworth \thanks{funded by the Overleaf team}}
\date{February 2017}
Now that you have given your document a title, author and date, you can print this information on
the document with the \maketitle command. This should be included in the body of the
document at the place you want the title to be printed.
\begin{document}
\maketitle
We have now added a title, author and date to our first \LaTeX{} document!
\end{document}
Adding comments
As with any code you are writing, it can often be useful to include comments. Comments are pieces
of text you can include in the document which will not be printed, and will not affect the document
in any way. They are useful for organizing your work, taking notes, or commenting out
lines/sections when debugging. To make a comment in LATEX, simply write a % symbol at the
beginning of the line as shown below:
\begin{document}
\maketitle
We have now added a title, author and date to our first \LaTeX{} document!
\end{document}
Moreover, some packages, e.g. Beamer, change the behaviour of \emph command.
Adding images
We will now look at how to add images to a LATEX document.
Below is a example on how to include a picture.
\documentclass{article}
\usepackage{graphicx}
\graphicspath{ {images/} }
\begin{document}
The universe is immense and it seems to be homogeneous,
in a large scale, everywhere we look at.
\includegraphics{universe}
Unordered lists
Unordered lists are produced by the itemize environment. Each entry must be preceded by the
control sequence \item as shown below.
\begin{itemize}
\item The individual entries are indicated with a black dot, a so-called
bullet.
\item The text in the entries may be of any length.
\end{itemize}
By default the individual entries are indicated with a black dot, so-called bullet. The text in the
entries may be of any length.
Ordered lists
Ordered list have the same syntax inside a different environment. We make ordered lists using the
enumerate environment:
\begin{enumerate}
\item This is the first entry in our list
\item The list numbers increase with each entry we add
\end{enumerate}
As with unordered lists, each entry must be preceded by the control sequence \item, which will
automatically generate the number labelling the item. The enumerate labels consists of sequential
numbers starting at one.
To put your equations in inline mode use one of these delimiters: \( ... \), $ ... $ or \
begin{math} ... \end{math}. They all work and the choice is a matter of taste.
\[E=mc^2\]
\begin{equation}
E=m
\end{equation}
To print your equations in display mode use one of these delimiters: \[ ... \], \
begin{displaymath} ... \end{displaymath} or \begin{equation} ... \
end{equation}. $$ ... $$ is discouraged as it can give inconsistent spacing, and may not
work well with some math packages.
Important Note: equation* environment is provided by an external package, consult the
amsmath article.
Many math mode commands require the amsmath package, so be sure to include it when writing
math. An example is shown below of some basic math mode commands.
Subscripts in math mode are written as $a_b$ and superscripts are written as
$a^b$. These can be combined an nested to write expressions such as
We write integrals using $\int$ and fractions using $\frac{a}{b}$. Limits are
placed on integrals using superscripts and subscripts:
Lower case Greek letters are written as $\omega$ $\delta$ etc. while upper case
Greek letters are written as $\Omega$ $\Delta$.
The possibilities with math in LATEX are endless and it is impossible to list them all here.
Basic Formatting
We will now look at how to write abstracts, as well as how to format a LATEX document into
different chapters, sections and paragraphs.
Abstracts
In scientific documents it's a common practice to include a brief overview of the main subject of the
paper. In LATEX there's the abstract environment for this. The abstract environment will
put the text in a special format at the top of your document.
\begin{document}
\begin{abstract}
This is a simple paragraph at the beginning of the
document. A brief introduction about the main subject.
\end{abstract}
\end{document}
Paragraphs and newlines
\begin{document}
\begin{abstract}
This is a simple paragraph at the beginning of the
document. A brief introduction about the main subject.
\end{abstract}
Now that we have written our abstract, we can begin writing our first paragraph.
When writing the contents of your document, if you need to start a new paragraph you must hit the
"Enter" key twice (to insert a double blank line). Notice that LATEX automatically indents
paragraphs.
To start a new line without actually starting a new paragraph insert a break line point, this can be
done by \\ (a double backslash as in the example) or the \newline command.
Care should be taken that multiple \\ or \newlines are not used to "simulate" paragraphs with
larger spacing between them, as this can interfere with LATEX's typesetting algorithms. The
recommended method to do so is to keep using double blank lines to create new paragraphs without
any \\, and then add \usepackage{parskip} to the preamble.
\section{Introduction}
\section{Second Section}
\subsection{First Subsection}
Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...
\section*{Unnumbered Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem
The command \section{} marks the beginning of a new section, inside the braces is set the title.
Section numbering is automatic and can be disabled by including a * in the section command as \
section*{}. We can also have \subsection{}s, and indeed \subsubsection{}s. The
basic levels of depth are listed below:
-1 \part{part}
0 \chapter{chapter}
1 \section{section}
2 \subsection{subsection}
3 \subsubsection{subsubsection}
4 \paragraph{paragraph}
5 \subparagraph{subparagraph}
Note that \part and \chapter are only available in report and book document classes.
Creating tables
Creating a simple table in LATEX
Below you can see the simplest working example of a table
\begin{center}
\begin{tabular}{ c c c }
cell1 & cell2 & cell3 \\
cell4 & cell5 & cell6 \\
cell7 & cell8 & cell9
\end{tabular}
\end{center}
The tabular environment is the default LATEX method to create tables. You must specify a
parameter to this environment, in this case {c c c}. This tells LATEX that there will be three
columns and that the text inside each one of them must be centred. You can also use r to align the
text to the right and l for left alignment. The alignment symbol & is used to specify the breaks in
the table entries. There must always be one less alignment symbol in each line than the number of
columns. To go to the next line of your table, we use the new line command \\. We wrap the entire
table inside the center environment so that it will appear in the center of the page.
Adding borders
The tabular environment is more flexible, you can put separator lines in between each column.
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
cell1 & cell2 & cell3 \\
cell4 & cell5 & cell6 \\
cell7 & cell8 & cell9 \\
\hline
\end{tabular}
\end{center}
You can add borders using the horizontal line command \hline and the vertical line parameter |.
• { |c|c|c| }: This declares that three columns, separated by a vertical line, are going to
be used in the table. The | symbol specifies that these columns should be separated by a
vertical line.
• \hline: This will insert a horizontal line. We have included horizontal lines at the top and
bottom of the table here. There is no restriction on the number of times you can use \
hline.
Below you can see a second example.
\begin{center}
\begin{tabular}{||c c c c||}
\hline
Col1 & Col2 & Col2 & Col3 \\ [0.5ex]
\hline\hline
1 & 6 & 87837 & 787 \\
\hline
2 & 7 & 78 & 5415 \\
\hline
3 & 545 & 778 & 7507 \\
\hline
4 & 545 & 18744 & 7560 \\
\hline
5 & 88 & 788 & 6344 \\ [1ex]
\hline
\end{tabular}
\end{center}
Creating tables in LATEX can be a bit tricky sometimes, so you may want to use the
TablesGenerator.com online tool to export LATEX code for tabulars. The File > Paste table data
option lets you copy and paste data from spreadsheet applications.
Captions, labels and references
You can caption and reference tables in much the same way as images. The only difference is that
instead of the figure environment, you use the table environment.
Table \ref{table:data} is an example of referenced \LaTeX{} elements.
\begin{table}[h!]
\centering
\begin{tabular}{||c c c c||}
\hline
Col1 & Col2 & Col2 & Col3 \\ [0.5ex]
\hline\hline
1 & 6 & 87837 & 787 \\
2 & 7 & 78 & 5415 \\
3 & 545 & 778 & 7507 \\
4 & 545 & 18744 & 7560 \\
5 & 88 & 788 & 6344 \\ [1ex]
\hline
\end{tabular}
\caption{Table to test captions and labels}
\label{table:data}
\end{table}
Note: If you are using captions and references on your own computer, you will have to compile the
document twice for the references to work. Overleaf will do this for you automatically.'
\begin{document}
\maketitle
\tableofcontents
\section{Introduction}
\addcontentsline{toc}{section}{Unnumbered Section}
\section*{Unnumbered Section}
\section{Second Section}
\end{document}
Sections, subsections and chapters are automatically included in the table of contents. To manually
add entries, for example when you want an unnumbered section, use the command \
addcontentsline as shown in the example.