Learn LaTeX in 30 Minutes - Overleaf, Online LaTeX Editor

Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

 Search help library…

Learn LaTeX in 30 minutes

In this guide, we hope to give you your rst introduction to LATEX. The guide does not require
you to have any prior knowledge of LATEX, but by the time you are nished, you will have
written your rst LaTeX document, and hopefully will have a good knowledge of some of the
basic functions provided by LATEX.

Contents

1 What is LaTeX?
2 Why learn LaTeX?
3 Writing your rst piece of LaTeX
4 The preamble of a document
5 Adding a title, author and date
6 Adding comments
7 Bold, italics and underlining
8 Adding images
8.1 Captions, labels and references
9 Creating lists in LaTeX
9.1 Unordered lists
9.2 Ordered lists
10 Adding math to LaTeX
11 Basic Formatting
11.1 Abstracts
11.2 Paragraphs and newlines
11.3 Chapters and Sections
12 Creating tables
12.1 Creating a simple table in LaTeX
https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 1/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

12.2 Adding borders


12.3 Captions, labels and references
13 Adding a Table of Contents
14 Downloading your nished document

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 LibreOf ce Writer, users can enter plain text and let LATEX take care of the rest.

Why learn LATEX?


LATEX is used all over the world for scienti c documents, books, as well as many other forms of
publishing. Not only can it create beautifully typeset documents, but it allows users to very
quickly tackle the more complicated parts of typesetting, such as inputting mathematics,
creating tables of contents, referencing and creating bibliographies, and having a consistent
layout across all sections. Due to the huge number of open source packages available (more on
this later), the possibilities with LATEX are endless. These packages allow users to do even more
with LATEX, such as add footnotes, draw schematics, create tables etc.

One of the most important reasons people use LATEX is that it separates the content of the
document from the style. This means that once you have written the content of your document,
we can change its appearance with ease. Similarly, you can create one style of document which
can be used to standardise the appearance of many different documents. This allows scienti c
journals to create templates for submissions. These templates have a pre-made layout meaning
that only the content needs to be added. In fact there are hundreds of templates
(https://www.sharelatex.com/templates) available for everything from CVs to slideshows.

Writing your rst piece of LATEX


The rst step is to create a new LATEX project. You can do this on your own computer by
creating a new .tex le, or else you can start a new project in Overleaf
(/learn/Creating_a_document_in_Overleaf). Let's start with the simplest working example:

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 2/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

\documentclass{article}

\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 rst piece of formatting for you, by
indenting the rst line of the paragraph. Let's have a close look at what each part of our code
does.

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/582dbc33f220531c2d4bda27/download/zip&templateName=Learn%20LaTe
X%20in%2020%20minutes:%20Part%201&compiler=pd atex)

The rst 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 scienti c 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 les, 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
(https://en.wikibooks.org/wiki/LaTeX/Basics#Compilation) for more information on how to do
this.

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 3/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

If you are using a dedicated LaTeX editor


(https://en.wikibooks.org/wiki/LaTeX/Installation#Editors) 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 brie y about the preamble.

The preamble of a document


In the previous example the text was entered after the \begin{document} command.
Everything in your .tex le before this point is called the preamble. In the preamble you de ne
the type of document you are writing, the language you are writing in, the packages you would
like to use (more on this later) and several other elements. For instance, a normal document
preamble would look like this:

\documentclass[12pt, letterpaper]{article}
\usepackage[utf8]{inputenc}

Below a detailed description of each line:

\documentclass[12pt, letterpaper]{article}
As said before, this de nes the type of document. Some additional parameters included in the
square brackets can be passed to the command. These parameters must be comma-separated.
In the example, the extra parameters set the font size (12pt) and the paper size (letterpaper).
Of course other font sizes (9pt, 11pt, 12pt) can be used, but if none is speci ed, the default size
is 10pt. As for the paper size other possible values are a4paper and legalpaper; see the
article about Page size and margins (/learn/Page_size_and_margins) for more details about this.

\usepackage[utf8]{inputenc}
This is the encoding for the document. It can be omitted or changed to another encoding but
utf-8 is recommended. Unless you speci cally need another encoding, or if you are unsure
about it, add this line to the preamble.

Adding a title, author and date


To add a title, author and date to our document, you must add three lines to the preamble (NOT
the main body of the document). These lines are

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 4/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

\title{First document}
This is the title.

\author{Hubert Farnsworth}
Here you put the name of the Author(s) and, as an optional addition, you can add the next
command within the curly braces:

\thanks{funded by the Overleaf team}


This can be added after the name of the author, inside the braces of the author command. It
will add a superscript and a footnote with the text inside the braces. Useful if you need to thank
an institution in your article.

\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}

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 5/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/582dbeacf220531c2d4bdaaa/download/zip&templateName=Learn%20LaTeX
%20in%2020%20minutes:%20Part%202&compiler=pd atex)

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!

% This line here is a comment. It will not be printed in the document.

\end{document}

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 6/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/58a308db13712fef4e9deff7/download/zip&templateName=Learn%20LaTeX
%20in%2020%20minutes:%20Part%203&compiler=pd atex)

Bold, italics and underlining


We will now look at some simple text formatting commands.

Bold: Bold text in LaTeX is written with the \textbf{...} command.


Italics: Italicised text in LaTeX is written with the \textit{...} command.
Underline: Underlined text in LaTeX is written with the \underline{...} command.

An example of each of these in action is shown below:

Some of the \textbf{greatest}


discoveries in \underline{science}
were made by \textbf{\textit{accident}}.

Another very useful command is the \emph{...} command. What the \emph command
actually does with its argument depends on the context - inside normal text the emphasized
text is italicized, but this behaviour is reversed if used inside an italicized text- see example
below:

Some of the greatest \emph{discoveries}


in science
were made by accident.

\textit{Some of the greatest \emph{discoveries}


in science
were made by accident.}

\textbf{Some of the greatest \emph{discoveries}


in science
were made by accident.}

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 7/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

Moreover, some packages, e.g. Beamer (/learn/Beamer), change the behaviour of \emph
command.

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/58a30a6813712fef4e9df06b/download/zip&templateName=Learn%20LaTeX
%20in%2020%20minutes:%20Part%204&compiler=pd atex)

Adding images
We will now look at how to add images to a LATEX document. On Overleaf, you will rst have to
upload the images (/learn/Including_images_in_ShareLaTeX).

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}

There's a picture of a galaxy above


\end{document}

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 8/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/58a30b7413712fef4e9df0a8/download/zip&templateName=Learn%20LaTeX
%20in%2020%20minutes:%20Part%205&compiler=pd atex)

LATEX can not manage images by itself, so you will need to use a package. Packages can be used
to change the default look of your LATEX document, or to allow more functionalities. In this case,
you need to include an image in our document, so you should use the graphicx package. This
package gives new commands, \includegraphics{...} and \graphicspath{...}. To use
the graphicx package, include the following line in you preamble: \usepackage{graphicx}

The command \graphicspath{ {images/} } tells LATEX that the images are kept in a folder
named images under the current directory.

The \includegraphics{universe} command is the one that actually included the image in
the document. Here universe is the name of the le containing the image without the extension,
then universe.PNG becomes universe. The le name of the image should not contain white
spaces nor multiple dots.

Note: The le extension is allowed to be included, but it's a good idea to omit it. If the le
extension is omitted it will prompt LaTeX to search for all the supported formats. It is also
usually recommended to use lowercase letters for the le extension when uploading image
les. For more details see the section about generating high resolution and low resolution
images.

Captions, labels and references


Images can be captioned, labelled and referenced by means of the figure environment as
shown below:

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 9/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

\begin{figure}[h]
\centering
\includegraphics[width=0.25\textwidth]{mesh}
\caption{a nice plot}
\label{fig:mesh1}
\end{figure}

As you can see in the figure \ref{fig:mesh1}, the


function grows near 0. Also, in the page \pageref{fig:mesh1}
is the same example.

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/58a30c5613712fef4e9df0e8/download/zip&templateName=Learn%20LaTeX
%20in%2020%20minutes:%20Part%206&compiler=pd atex)

There are three important commands in the example:

\caption{a nice plot}: As you may expect this command sets the caption for the
gure. If you create a list of gures this caption will be used there. You can place it above
or below the gure.

\label{fig:mesh1}: If you need to refer the image within your document, set a label
with this command. The label will number the image, and combined with the next
command will allow you to reference it.

\ref{fig:mesh1}: This code will be substituted by the number corresponding to the


referenced gure.

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 10/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

When placing images in a LATEX document, we should always put them inside a figure
environment or similar so that LATEX will position the image in a way that ts in with the rest of
your text.

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.'

Creating lists in LATEX


Lists are very simple to create in LATEX. You can create lists using different list environments.
Environments are sections of our document that you want to present in a different way to the
rest of the document. They start with a \begin{...} command and end with an \end{...}
command.

There are two main different types of lists, ordered lists and unordered lists. Each will use a
different environment.

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.

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/52fe74766a6237452e000088/download/zip&templateName=Lists%20Exam
ples&compiler=pd atex)

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 11/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

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.

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/52fe74766a6237452e000088/download/zip&templateName=Lists%20Exam
ples&compiler=pd atex)

Adding math to LATEX


One of the main advantages of LATEX is the ease at which mathematical expressions can be
written. LATEX allows two writing modes for mathematical expressions: the inline mode and the
display mode. The rst one is used to write formulas that are part of a text. The second one is
used to write expressions that are not part of a text or paragraph, and are therefore put on
separate lines. Let's see an example of the inline mode:

In physics, the mass-energy equivalence is stated


by the equation $E=mc^2$, discovered in 1905 by Albert Einstein.

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.

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 12/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

The displayed mode has two versions: numbered and unnumbered.

The mass-energy equivalence is described by the famous equation


\[ E=mc^2 \]
discovered in 1905 by Albert Einstein.
In natural units ($c = 1$), the formula expresses the identity
\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 (https://texfaq.org/FAQ-dolldoll) 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 (/learn/Aligning_equations).

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/52ec4e44b43917a25a000e96/download/zip&templateName=Math%20Expr
essions&compiler=pd atex)

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.

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 13/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

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

\[ T^{i_1 i_2 \dots i_p}_{j_1 j_2 \dots j_q} =


T(x^{i_1},\dots,x^{i_p},e_{j_1},\dots,e_{j_q}) \]

We write integrals using $\int$ and fractions using $\frac{a}{b}$.


Limits are placed on integrals using superscripts and subscripts:

\[ \int_0^1 \frac{dx}{e^x} = \frac{e-1}{e} \]

Lower case Greek letters are written as $\omega$ $\delta$ etc. while
upper case Greek letters are written as $\Omega$ $\Delta$.

Mathematical operators are prefixed with a backslash as $\sin(\beta)$,


$\cos(\alpha)$, $\log(x)$ etc.

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/58a30cfd13712fef4e9df123/download/zip&templateName=Learn%20LaTeX
%20in%2020%20minutes:%20Part%207&compiler=pd atex)

The possibilities with math in LATEX are endless and it is impossible to list them all here. Be sure
to check out our other articles on
https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 14/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

Mathematical expressions (/learn/Mathematical_expressions)


Subscripts and superscripts (/learn/Subscripts_and_superscripts)
Brackets and Parentheses (/learn/Brackets_and_Parentheses)
Fractions and Binomials (/learn/Fractions_and_Binomials)
Aligning Equations (/learn/Aligning_equations_with_amsmath)
Operators (/learn/Operators)
Spacing in math mode (/learn/Spacing_in_math_mode)
Integrals, sums and limits (/learn/Integrals,_sums_and_limits)
Display style in math mode (/learn/Display_style_in_math_mode)
List of Greek letters and math symbols (/learn/List_of_Greek_letters_and_math_symbols)
Mathematical fonts (/learn/Mathematical_fonts)

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 scienti c 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}

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/58a30dd713712fef4e9df14e/download/zip&templateName=Learn%20LaTeX
%20in%2020%20minutes:%20Part%208&compiler=pd atex)

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 15/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

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.

This line will start a second Paragraph.


\end{document}

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/58a30dd713712fef4e9df14e/download/zip&templateName=Learn%20LaTeX
%20in%2020%20minutes:%20Part%208&compiler=pd atex)

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.

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 16/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

You can nd more information in the Paragraphs and new lines


(/learn/Paragraphs_and_new_lines) article.

Chapters and Sections


Commands to organize a document vary depending on the document type, the simplest form of
organization is the sectioning, available in all formats.

\chapter{First Chapter}

\section{Introduction}

This is the first section.

Lorem ipsum dolor sit amet, consectetuer adipiscing


elit. Etiam lobortisfacilisis sem. Nullam nec mi et
neque pharetra sollicitudin. Praesent imperdietmi nec ante.
Donec ullamcorper, felis non sodales...

\section{Second Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.


Etiam lobortis facilisissem. Nullam nec mi et neque pharetra
sollicitudin. Praesent imperdiet mi necante...

\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

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 17/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/58a30e7b13712fef4e9df182/download/zip&templateName=Learn%20LaTeX
%20in%2020%20minutes:%20Part%209&compiler=pd atex)

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.

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 18/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

For a more complete discussion about the document structure see the article about sections
and chapters (/learn/Sections_and_chapters).

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.

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/58a3101d13712fef4e9df258/download/zip&templateName=Learn%20LaTeX
%20in%2020%20minutes:%20Part%2010&compiler=pd atex)

Adding borders
The tabular environment is more exible, you can put separator lines in between each column.

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 19/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

\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 speci es 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.

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 20/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

\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 (https://www.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.

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/58a3101d13712fef4e9df258/download/zip&templateName=Learn%20LaTeX
%20in%2020%20minutes:%20Part%2010&compiler=pd atex)

Captions, labels and references


https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 21/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

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}

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/58a3101d13712fef4e9df258/download/zip&templateName=Learn%20LaTeX
%20in%2020%20minutes:%20Part%2010&compiler=pd atex)

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 22/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

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.'

Adding a Table of Contents


To create the table of contents is straightforward, the command \tableofcontents does all
the work for you:

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 23/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

\documentclass{article}
\usepackage[utf8]{inputenc}

\title{Sections and Chapters}


\author{Gubert Farnsworth}
\date{ }

\begin{document}

\maketitle

\tableofcontents

\section{Introduction}

This is the first section.

Lorem ipsum dolor sit amet, consectetuer adipiscing


elit. Etiam lobortisfacilisis sem. Nullam nec mi et
neque pharetra sollicitudin. Praesent imperdietmi nec ante.
Donec ullamcorper, felis non sodales...

\addcontentsline{toc}{section}{Unnumbered Section}
\section*{Unnumbered Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.


Etiam lobortis facilisissem. Nullam nec mi et neque pharetra
sollicitudin. Praesent imperdiet mi necante...

\section{Second Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.


Etiam lobortis facilisissem. Nullam nec mi et neque pharetra
sollicitudin. Praesent imperdiet mi necante...

\end{document}

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 24/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

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.

  Open an example in Overleaf (https://www.sharelatex.com/project/new/template?


zipUrl=/project/58a3103d13712fef4e9df25b/download/zip&templateName=Learn%20LaTeX
%20in%2020%20minutes:%20Part%2011&compiler=pd atex)

Downloading your nished document


You can download your nished PDF from the left hand menu as above by clicking PDF. There is
also the quicker option of clicking the Download PDF button on your PDF viewer as shown
below.

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 25/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

Documentation Home (/learn/Main_Page)


Learn LaTeX in 30 minutes (/learn/Learn_LaTeX_in_30_minutes)

Overleaf guides
Creating a document in Overleaf (/learn/Kb/Creating_a_document_in_Overleaf)
Uploading a project (/learn/Kb/Uploading_a_project)
Copying a project (/learn/Kb/Copying_a_project)
Creating a project from a template (/learn/Kb/Creating_a_project_from_a_template)
Using the Overleaf project menu (/learn/Kb/Using_the_Overleaf_project_menu)
Including images in Overleaf (/learn/Kb/Including_images_in_ShareLaTeX)
Exporting your work from Overleaf (/learn/Kb/Exporting_your_work_from_ShareLaTeX)
Working of ine in Overleaf (/learn/Kb/Working_Of ine_in_Overleaf_v2)
Using Track Changes in Overleaf (/learn/Kb/Track_Changes_in_Overleaf_v2)
Using bibliographies in Overleaf (/learn/Kb/Using_bibliographies_in_ShareLaTeX)
Sharing your work with others (/learn/Kb/Sharing_your_work_with_others)
Using the History feature (/learn/Using_the_History_feature)
Debugging Compilation timeout errors (/learn/Kb/Debugging_Compilation_timeout_errors)
How-to guides (/learn/Kb/Knowledge_Base)

LaTeX Basics
Creating your rst LaTeX document (/learn/Creating_a_document_in_LaTeX)
Choosing a LaTeX Compiler (/learn/Choosing_a_LaTeX_Compiler)
Paragraphs and new lines (/learn/Paragraphs_and_new_lines)
Bold, italics and underlining (/learn/Bold,_italics_and_underlining)
Lists (/learn/Lists)
Errors (/learn/Errors)

Mathematics
Mathematical expressions (/learn/Mathematical_expressions)
Subscripts and superscripts (/learn/Subscripts_and_superscripts)
Brackets and Parentheses (/learn/Brackets_and_Parentheses)
Matrices (/learn/Matrices)
Fractions and Binomials (/learn/Fractions_and_Binomials)
Aligning Equations (/learn/Aligning_equations)
https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 26/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

Operators (/learn/Operators)
Spacing in math mode (/learn/Spacing_in_math_mode)
Integrals, sums and limits (/learn/Integrals,_sums_and_limits)
Display style in math mode (/learn/Display_style_in_math_mode)
List of Greek letters and math symbols (/learn/List_of_Greek_letters_and_math_symbols)
Mathematical fonts (/learn/Mathematical_fonts)

Figures and tables


Inserting Images (/learn/Inserting_Images)
Tables (/learn/Tables)
Positioning Images and Tables (/learn/Positioning_images_and_tables)
Lists of Tables and Figures (/learn/Lists_of_tables_and_ gures)
Drawing Diagrams Directly in LaTeX (/learn/Picture_environment)
TikZ package (/learn/TikZ_package)

References and Citations


Bibliography management in LaTeX (/learn/Bibliography_management_in_LaTeX)
Bibliography management with biblatex (/learn/Bibliography_management_in_LaTeX)
Biblatex bibliography styles (/learn/Biblatex_bibliography_styles)
Biblatex citation styles (/learn/Biblatex_citation_styles)
Bibliography management with natbib (/learn/Bibliography_management_with_natbib)
Natbib bibliography styles (/learn/Natbib_bibliography_styles)
Natbib citation styles (/learn/Natbib_citation_styles)
Bibliography management with bibtex (/learn/Bibliography_management_with_bibtex)
Bibtex bibliography styles (/learn/Bibtex_bibliography_styles)

Languages
Multilingual typesetting on Overleaf using polyglossia and fontspec
(/learn/Multilingual_typesetting_on_Overleaf_using_polyglossia_and_fontspec)
Multilingual typesetting on Overleaf using babel and fontspec
(/learn/Multilingual_typesetting_on_Overleaf_using_babel_and_fontspec)
International language support (/learn/International_language_support)
Quotations and quotation marks (/learn/Typesetting_quotations)
Arabic (/learn/Arabic)
Chinese (/learn/Chinese)
French (/learn/French)

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 27/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

German (/learn/German)
Greek (/learn/Greek)
Italian (/learn/Italian)
Japanese (/learn/Japanese)
Korean (/learn/Korean)
Portuguese (/learn/Portuguese)
Russian (/learn/Russian)
Spanish (/learn/Spanish)

Document structure
Sections and chapters (/learn/Sections_and_chapters)
Table of contents (/learn/Table_of_contents)
Cross referencing sections and equations (/learn/Cross_referencing_sections_and_equations)
Indices (/learn/Indices)
Glossaries (/learn/Glossaries)
Nomenclatures (/learn/Nomenclatures)
Management in a large project (/learn/Management_in_a_large_project)
Multi- le LaTeX projects (/learn/Multi- le_LaTeX_projects)
Hyperlinks (/learn/Hyperlinks)

Formatting
Lengths in LATEX (/learn/Lengths_in_LaTeX)

Headers and footers (/learn/Headers_and_footers)


Page numbering (/learn/Page_numbering)
Paragraph formatting (/learn/Paragraph_formatting)
Line breaks and blank spaces (/learn/Line_breaks_and_blank_spaces)
Text alignment (/learn/Text_alignment)
Page size and margins (/learn/Page_size_and_margins)
Single sided and double sided documents (/learn/Single_sided_and_double_sided_documents)
Multiple columns (/learn/Multiple_columns)
Counters (/learn/Counters)
Code listing (/learn/Code_listing)
Code Highlighting with minted (/learn/Code_Highlighting_with_minted)
Using colours in LaTeX (/learn/Using_colours_in_LaTeX)
Footnotes (/learn/Footnotes)
Margin notes (/learn/Margin_notes)

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 28/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

Fonts
Font sizes, families, and styles (/learn/Font_sizes,_families,_and_styles)
Font typefaces (/learn/Font_typefaces)
Supporting modern fonts with XƎLATEX (/learn/XeLaTeX)

Presentations
Beamer (/learn/Beamer)
Powerdot (/learn/Powerdot)
Posters (/learn/Posters)

Commands
Commands (/learn/Commands)
Environments (/learn/Environments)

Field speci c
Theorems and proofs (/learn/Theorems_and_proofs)
Chemistry formulae (/learn/Chemistry_formulae)
Feynman diagrams (/learn/Feynman_diagrams)
Molecular orbital diagrams (/learn/Molecular_orbital_diagrams)
Chess notation (/learn/Chess_notation)
Knitting patterns (/learn/Knitting_patterns)
CircuiTikz package (/learn/CircuiTikz_package)
Pgfplots package (/learn/Pgfplots_package)
Typing exams in LaTeX (/learn/Typing_exams_in_LaTeX)
Knitr (/learn/Knitr)
Attribute Value Matrices (/learn/Attribute_Value_Matrices)

Class les
Understanding packages and class les (/learn/Understanding_packages_and_class_ les)
List of packages and class les (/learn/List_of_packages_and_class_ les)
Writing your own package (/learn/Writing_your_own_package)
Writing your own class (/learn/Writing_your_own_class)
Tips (/learn/Tips)

Advanced TeX/LaTeX

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 29/30
10/6/2020 Learn LaTeX in 30 minutes - Overleaf, Online LaTeX Editor

In-depth technical articles on TeX/LaTeX (/learn/Articles)

https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes 30/30

You might also like