Você está na página 1de 47

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Introduction to LATEX
Aleksandar Petrov
EUROAVIA Delft

October 8, 2015
EUROAVIA

Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Contents

1
2

What is LATEX
The Basics of the Basics
Document Layout
Sectioning
Line Breaks
Table of contents
Big project management
Special characters
Typesetting Math
Math environments

Typing symbols
Bracketing
Equation numbering
Floats
Figures
Tables
Referencing & Citing
Referencing
Citing
Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Why use LATEX?

Focus on writing, not on typesetting or formatting


Deliver beautifully looking texts with minimum effort
Efficiently incorporate math expressions

Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

How does LATEXwork?

You type your content in a text file

A compiler processes your file

A beautiful PDF is generated for you

Referencing & Citing

Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Where can I type LATEX?

In order to crate your file you need only the LATEXcompiler


However, typing your code can be much more easier if you use
a dedicated editor
Many options exist both online and offline
Local installation depends on OS and editor choice
Suggested online option is ShareLatex.com

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Contents

1
2

What is LATEX
The Basics of the Basics
Document Layout
Sectioning
Line Breaks
Table of contents
Big project management
Special characters
Typesetting Math
Math environments

Typing symbols
Bracketing
Equation numbering
Floats
Figures
Tables
Referencing & Citing
Referencing
Citing
Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Document Layout

Hello World example:


\ documentclass { a r t i c l e }
\ b e g i n { document }
H e l l o World
\ end { document }

Some other types of documents are:


report, book, memoir, letter, beamer

Referencing & Citing

Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Document Layout
A report class example:
\ documentclass { report }
% T i t l e Page
\ t i t l e { Report T i t l e }
\ a u t h o r { A u t h o r name}
\ b e g i n { document }
\ maketitle
\ begin { abstract }
Sum up what i t i s
\ end { a b s t r a c t }

a l l about

\ chapter { Introduction }
Ba ck gr oun d i n f o r m a t i o n
\ end { document }

Floats

Referencing & Citing

Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Sectioning

LATEX understands how humans organize books, articles, reports,


etc. and makes it easier.
\ chapter { Chapter T i t l e }
\ section { Section Title }
\ subsection { Subsection Title }
\ subsubsection { Subsubsection Title }
\ p a r a g r a p h { P a r a g r a p h T o p i c } P a r a g r a p h Text

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Line Breaks

This is the first paragraph, contains some text to show how amazing an author I am. I know it is
magnificent, you dont need to tell me this.
We are continuing with the fancy stuff. As you can see, the line of my thought has not changed. \par
Indeed, I am still wondering if you are impressed enough...\newline
For sure this
what it is. \\

text

has some point.

However, to be completely honest, I am not really sure

That is why, although useful, it might be just a bit meaningless.

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Line Breaks

To sum up:
empty line - new paragraph without adding an empty line
(keeping the topic the same)
\par - new paragraph without adding an empty line (keeping
the topic the same)
\\ - new paragraph with adding an empty line (introducing
new topic)
\newline - new paragraph with adding an empty line
(introducing new topic)

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Table of contents

Automatic table of contents can be generated in a very simple way.


It will update itself every time you build the PDF:
\tableofcontents
Note
If the table of contents has not updated, build the file again.
Appendices can be added in the same manner as chapters. The
\appendix command switches the chapter numbering to letters.

What is LATEX

The Basics of the Basics

Table of contents

\begin{document}
\maketitle
\tableofcontents
\newpage
\chapter{Introduction}
\chapter{Literature study}
\section{Historical remarks}
\section{Modern development}
\chapter{Design propsal}
\appendix
\chapter{Additional information}
\end{document}

Typesetting Math

Floats

Referencing & Citing

Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Big project management

Sometimes LATEX source code can get pretty huge. That is why it
is handy to separate it over several files. Then these files can be
linked to the main file. The way to do this is the
\input{filename} command. When the compiler sees it, it first
processes the external file and then continues with the main file as
if it is one whole thing. Meaning that no breaks in page and
section numbering, referencing and labeling will occur.
When interested in previewing only one part of the document, you
can comment the \input commands for the others. That will
reduce the building time significantly.

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Special characters

Note
There are some reserved characters and using them in your text
will most probably result in an error message from the compiler.
# $ % ^ & _ { } \
If you still want to use any of them, just put a backslash before it.
1

\#, \$, \%, \{}, \&, \ , \{, \}, $\


backslash$

#, $, %, , &, , {, }, \

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Contents

1
2

What is LATEX
The Basics of the Basics
Document Layout
Sectioning
Line Breaks
Table of contents
Big project management
Special characters
Typesetting Math
Math environments

Typing symbols
Bracketing
Equation numbering
Floats
Figures
Tables
Referencing & Citing
Referencing
Citing
Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Typesetting Math
The mathematical typesetting capabilities of LATEX are extremely
advanced. They present one of the main strengths of LATEX.
However, in order to unlock the full capability we need to use
the AMS-LATEX package.
Adding the AMS-LATEX package to your file can be done in the
same way as adding any other extension package. Just use the
\usepackage{amsmath} in the preamble.
\documentclass{report}
\usepackage{amsmath}
% Title Page
\title{Report Title}
\author{Author name}
\begin{document}
\maketitle
...

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Math vs. Text Mode


In order to start typing equations and other mathematical
expressions you need to switch to math mode. There are many
different ways to do this but two are the major ones:
In-line (text style)
1

For example, $a2 + b2 = c2$

For example, a2 + b 2 = c 2

Separately (display style)


And another important result
follows :
2 \begin{equation}
3 c = \sqrt{a2 + b2}
4 \end{equation}
1

And another important result


follows:
p
c = a2 + b 2
(1)

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Subscripts and Superscripts


The average $X {avg}$ of three
numbers $X 1$, $X 2$ and $X
3$ is
2 \begin{equation}
3 X {avg} = (X 1 + X 2 + X 3) / 3
4 \end{equation}
5 However, their squared sum $X {
sum}$ equals
6 \begin{equation}
7 X {sum} = X 12 + X 22 + X 32
8 \end{equation}
9 Finally , their exponent can be
separated in the following
manner:
10 \begin{equation}
11 e{X 1 + X 2 + X 3} = e{X 1} e
{X 2} e{X 3}
12 \end{equation}
1

The average Xavg of three numbers


X1 , X2 and X3 is
Xavg = (X1 + X2 + X3 )/3

(2)

However, their squared sum Xsum


equals
Xsum = X12 + X22 + X32

(3)

Finally, their exponent can be separated in the following manner:


e X1 +X2 +X3 = e X1 e X2 e X3

(4)

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Some mathematical expressions


Let s compute $7 = \frac{21}{3} = \dfrac{21}{3}$.
\begin{gather}
3 X {avg} = \frac{X 1 + X 2 + X 3}{3}\\
4 c = \sqrt{ \frac{a2 + b2}{4} }\\
5 \lim {x \ rightarrow 0}\frac{\sin x}{x} = 1
6 \end{gather}
1

Lets compute 7 =

21
3

21
.
3
X1 + X2 + X3
3
r
2
a + b2
c=
4
sin x
lim
=1
x0 x

Xavg =

(5)
(6)
(7)

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Greek letters

Greek letters can be easily entered in any math environment by


just typing \ and the name of the letter:
1

$\alpha, \beta, \gamma, \omega, \psi, \eta, \theta, \mu, \nu, \delta$

, , , , , , , , ,
Some of the capital Greek letters can also be typed in LATEX:
1

$\Gamma, \Omega, \Psi, \Theta, \Delta$

, , , ,

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Bars, vectors, dots and hats

Math accents can also be easily typed:


$\bar{X} = X {avg} = \frac{X 1 + X 2 + X 3}{3}$ \\
$\vec{r} = \vec{x} + \vec{y} + \vec{z}$ \\
3 $\vec{r} = x \hat{i} + y \hat{j} + z \hat{k}$ \\
4 $v = \dot{x}$ \\
5 $a = \dot{v} = \ddot{x}$

= Xavg = X1 +X2 +X3


X
3
~r = ~x + ~y + ~z
~r = xi + y j + z k
v = x
a = v = x

Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Sums, Products and Integrals


$\sum {k=0}\infty \frac{(1)k z{2k+1}}{(2k+1)!}=\sin z$
\begin{gather}
3 \sum {k=0}\infty \frac{(1)k z{2k+1}}{(2k+1)!}=\sin z \\
4 \int {0}{\infty} \frac{ M}{x} dx \\
5 \prod {n=1}5\frac{n}{n1}
6 \end{gather}
1

k=0

(1)k z 2k+1
(2k+1)!

= sin z

X
(1)k z 2k+1
k=0

= sin z
(2k + 1)!
Z
M
dx
x
0
5
Y
n
n=1

n1

(8)
(9)
(10)

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Dots

You want to multiply something?


Never do this:
1

$$ 216\pi = 32\pi $$

2 16 = 32

Instead, use \cdot:


1

$$ 2 \cdot 16\pi = 32\pi $$

2 16 = 32

Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Dots

You want to list some variables? Never do it like that:


1

$$ X n = \{ x 1, ... , x n \} $$

Xn = {x1 , ..., xn }

Instead, use the dedicated commands:


1
2

$$ X n = \{ x 1, \ ldots , x n \} $$
$$ S n = x 1 + \cdots + x n $$

Xn = {x1 , . . . , xn }
Sn = x1 + + xn

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Typing some common functions


Which one looks better:
cos

or

cos ?

The first one is typed as $cos \theta$ so is interpreted as the product


of three variables - c,o and s. However, the second option uses the
cosine command $\cos \theta$ and the compiler understands it is the
cosine function.
Some other functions that have dedicated commands are:
1

$$\sin , \cos, \tan, \cot, \log , \ln , \arccos , \ arcsin , \arctan , \exp, \min, \
max, \ldots$$

sin, cos, tan, cot, log, ln, arccos, arcsin, arctan, exp, min, max, . . .

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Bracketing
These brackets dont look good:
1

$$ f (x) = (\frac{x2 + 1}{ \sqrt{x}


}) (7x)$$

x2 + 1
f (x) = ( )(7 x)
x

That way is better:


1

$$ f (x) = \ left ( \frac{x2 + 1}{ \


sqrt{x} } \right ) (7x)$$


f (x) =

x2 + 1


(7 x)

This strategy works with any kind of brackets:


1

$$\ left [ \frac{a}{b} \right ], \ left \


lbrace \frac{a}{b} \right\
rbrace , \ left | \frac{a}{b} \
right | $$

hai nao a

,
,
b
b
b

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Equation numbering

Did you notice that some of the equations above had numbers on the
right?
\begin{equation}
f (x) = \sqrt{x}(x2 + 1)
3 \end{equation}

f (x) =

x(x 2 + 1)

(11)

This numbering makes referencing easy as we will see later. Note also
that only display equations can have numbering.
Removing the numbering of a given equation can be made in two ways:
Use equation* (or any other starred) environment instead of
equation
Put the \nonumber tag right after the equation (on the same line)

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Contents

1
2

What is LATEX
The Basics of the Basics
Document Layout
Sectioning
Line Breaks
Table of contents
Big project management
Special characters
Typesetting Math
Math environments

Typing symbols
Bracketing
Equation numbering
Floats
Figures
Tables
Referencing & Citing
Referencing
Citing
Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Floats

Floats are content that is considered separate from the main text.
As such they can float around the pages and position themselves
at a suitable place. Another important aspect of floats is that (in
the general case) they cannot be broken over two or more pages.
Two types of objects are considered floats:
Figures
Tables

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Figures

The basic code structure for including a figure (image) into a LATEX
document is the following:
\begin{figure}[position preference]
\centering
\includegraphics[width=somewidth]{path to image}
\caption{Some caption}
\end{figure}

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Figures
position preference
Although LATEX positions the figure at a place it considers optimal,
you can still specify a preference. However, keep in mind that this
is only a preference and LATEX might not follow it.
Specifier
h
t
b
p
!
H

Permission
Place the float here, i.e., approximately at the same point it occurs
in the source text (however, not exactly at the spot)
Position at the top of the page.
Position at the bottom of the page.
Put on a special page for floats only.
Override internal parameters LATEX uses for determining good float positions.
Places the float at precisely the location in the LATEX code.
Requires the float package, e.g., \usepackage{float}.
This is somewhat equivalent to h!.
Taken from https://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Figures

width
This can be measured in any of the units LATEX understands (e.g.
cm, px, in). However, for many cases it is most convenient to
specify the width of the picture as a percentage of the text width.
For example:
\includegraphics[width=0.5\textwidth]{path to image}

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Figures
Here we present an example of imported picture:

EUROAVIA
\begin{ figure }
2 \ centering
3 \ includegraphics [width=0.7\linewidth
]{./ logo}
4 \caption{EUROAVIA logo}
5 \end{figure}
1

Figure : EUROAVIA logo

The caption of the figure can be above the image if the \caption
tag is placed before the \includegraphics tag.

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Tables

LATEX allows for the design of pretty sophisticated tables. However,


we will discuss only the most simple table functions.
Typing big tables in LATEX by hand can be both time consuming
and error-prone. That is why it is suggested to use a table
generator that simplifies the work considerably.
TablesGenerator.com have a lot of formating options and
facilitate copy-paste from Excel and other spreadsheet programs.

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Tables
An example table generated with TablesGenerator.com.
\begin{table }[b]
\ centering
3 \caption{My caption}
4 \begin{tabular }{| ll |c|}
5 \ hline
6 Column A & Column B & Column C \\ \hline
71
&2
& abc
\\
84
&5
& def
\\
97
&8
& ghi
\\ \ hline
10 \end{tabular}
11 \end{table}
1
2

Table : My caption
Column A
1
4
7

Column B
2
5
8

Column C
abc
def
ghi

Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Tables

Table contents goes between begin{tabular} and


\end{tabular}
Vertical alignment of the columns and column separators are
specified by the |ll|c| tag
Horizontal lines between two rows can be put with the
\hline tag
The caption can be bellow the table if the \caption tag is
placed after the \end{tabular} tag

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Contents

1
2

What is LATEX
The Basics of the Basics
Document Layout
Sectioning
Line Breaks
Table of contents
Big project management
Special characters
Typesetting Math
Math environments

Typing symbols
Bracketing
Equation numbering
Floats
Figures
Tables
Referencing & Citing
Referencing
Citing
Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Referencing & Citing

Making sure that all the referencing and citing within your report
is correct can be quite a tedious task if you type your document in
a typical word processor. LATEX incorporates a powerful, yet simple
and flexible methodology to keep track of all the references and
citations.

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing

Referencing is made of two parts:


Labeling your content
Connecting the text to the labels

Referencing & Citing

Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Labels

Labels can be put with the \label{label_name} to many


different types of objects. It is important to never use the same
label twice. This would produce a warning and a missing reference.
You can label:
Chapters and sections: put the label right after the respective
\chapter or \section tag
Equations: put the label right after the equation and before
any new line tag
Floats (figures and tables): the \label tag must come right
after the \caption tag

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

References

There are two main reference commands:


\ref{marker}: Returns the number of the respective
chapter, section, equation, table or float.
\pageref{marker}: Returns the page at which the
respective chapter, section, equation, table or float is situated
Note
LATEX does not know what type of content you are referencing to.
It returns only a number. That is why if you are referencing to an
equation you should type Equation \ref{label_name}.

What is LATEX

The Basics of the Basics

Typesetting Math

References

As can be seen in Figure


\ref{fig: EUROAVIA_logo},
the EUROAVIA logo is green
and similar to the logo
of Superman.
\begin{figure}
\centering
\includegraphics[width=
0.5\linewidth]{./logo}
\caption{EUROAVIA logo}
\label{fig: EUROAVIA_logo}
\end{figure}

Floats

Referencing & Citing

Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Citing
Citing to external sources can be done in a similar way. The most simple
way to do this is to create a list with sources between
\begin{thebibliography} and \end{thebibliography} tags. Then,
wherever in the main text referencing to this source is needed use the
\cite{cite_label} in the same way as \ref.
\LaTeX{} is widely used for scientific papers. \cite{lamport94}
\begin{thebibliography}{9}
\bibitem{lamport94}
Leslie Lamport,
\emph{\LaTeX: a document preparation system},
Addison Wesley, Massachusetts,
2nd edition,
1994.
\end{thebibliography}

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Citing

The \begin{thebibliography} and


\end{thebibliography} tags are typically placed right
before the the \end{document} tag
If you use more than 9 sources, change
\begin{thebibliography}{9} to
\begin{thebibliography}{99}
The label of a source is the argument of the
\bibitem{cite_label} tag
Never use the same source label twice
For more powerful bibliography management use BibTeX

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Contents

1
2

What is LATEX
The Basics of the Basics
Document Layout
Sectioning
Line Breaks
Table of contents
Big project management
Special characters
Typesetting Math
Math environments

Typing symbols
Bracketing
Equation numbering
Floats
Figures
Tables
Referencing & Citing
Referencing
Citing
Additional resources

What is LATEX

The Basics of the Basics

Typesetting Math

Floats

Referencing & Citing

Additional resources

Additional resources

Wikipedia.org
CTAN.org
The Not So Short Introduction to LATEX2, Tobias Oetiker,
https://tobi.oetiker.ch/lshort/lshort.pdf
Google
tex.stackexchange.com

Você também pode gostar