LaTeX tutorial II

82
Introduction to L A T E X Session #2 Oriol Borrega Pedro Tiago Martins Universitat de Barcelona January 21, 2013 Borrega & Martins (UB) Introduction to L A T E X Session #2 January 21, 2013 1 / 41

description

The presentation of the 2nd session of the LaTeX course of the BiB.

Transcript of LaTeX tutorial II

Page 1: LaTeX tutorial II

Introduction to LATEXSession #2

Oriol Borrega Pedro Tiago Martins

Universitat de Barcelona

January 21, 2013

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 1 / 41

Page 2: LaTeX tutorial II

Outline

1 A preamble: preamblesStyling with style

2 Listing the listsItemizing stuffEnumerating stuffDefining stuff

3 Floating elementsImagine imagesWhy must there always be a table?

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 2 / 41

Page 3: LaTeX tutorial II

Before we begin. . .

Before we begin. . .

. . . remember your commands!

\documentclass[a4paper,12pt]{article}

\section{Your section name here}

\emph{some text here}

\begin{document}

Lots of stuff in here

\end{document}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 3 / 41

Page 4: LaTeX tutorial II

Before we begin. . .

Before we begin. . .

. . . remember your commands!

\documentclass[a4paper,12pt]{article}

\section{Your section name here}

\emph{some text here}

\begin{document}

Lots of stuff in here

\end{document}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 3 / 41

Page 5: LaTeX tutorial II

Before we begin. . .

Before we begin. . .

. . . remember your commands!

\documentclass[a4paper,12pt]{article}

\section{Your section name here}

\emph{some text here}

\begin{document}

Lots of stuff in here

\end{document}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 3 / 41

Page 6: LaTeX tutorial II

Before we begin. . .

(and a brief side comment)

Anything following a percent sign (%) will be ignored by the compiler.That’s very useful to put comments in your documents or to turn on/offcommands and lines of text.

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 4 / 41

Page 7: LaTeX tutorial II

A preamble: preambles

Outline

1 A preamble: preamblesStyling with style

2 Listing the listsItemizing stuffEnumerating stuffDefining stuff

3 Floating elementsImagine imagesWhy must there always be a table?

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 5 / 41

Page 8: LaTeX tutorial II

A preamble: preambles

An example of a preamble

\documentclass{article}

\usepackage[english,catalan]{babel}

\usepackage[ansinew]{inputenc}

\usepackage{geometry} %Allows to change layout settings

\usepackage{enumerate} %Enables lists

\title{The Denisova Hominin}

\author{Wikipedia}

\date{January 21st, 2013}

\parskip=5mm

\geometry{top=2.5cm,left=3cm,right=3cm,bottom=2.5cm}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 6 / 41

Page 9: LaTeX tutorial II

A preamble: preambles

What is going on here?

We are declaring the kind of document we want X\ documentclass[a4paper,12pt]{article}

We are telling LATEX we will do some “special tricks”

\ usepackage[english,catalan]{babel}\ usepackage[ansinew]{inputenc}\ usepackage{geometry}\ usepackage{enumerate}

We are signing our document X\ title {The Denisova hominin}\ author {N.E.Ander et al.}\ date {Just about today}

We are changing the default layout of the document

\ parskip=5mm\ geometry{top=2.5cm,left=3cm,right=3cm,bottom=2.5cm}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 7 / 41

Page 10: LaTeX tutorial II

A preamble: preambles

What is going on here?

We are declaring the kind of document we want X\ documentclass[a4paper,12pt]{article}

We are telling LATEX we will do some “special tricks”

\ usepackage[english,catalan]{babel}\ usepackage[ansinew]{inputenc}\ usepackage{geometry}\ usepackage{enumerate}

We are signing our document X\ title {The Denisova hominin}\ author {N.E.Ander et al.}\ date {Just about today}

We are changing the default layout of the document

\ parskip=5mm\ geometry{top=2.5cm,left=3cm,right=3cm,bottom=2.5cm}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 7 / 41

Page 11: LaTeX tutorial II

A preamble: preambles

What is going on here?

We are declaring the kind of document we want X\ documentclass[a4paper,12pt]{article}

We are telling LATEX we will do some “special tricks”

\ usepackage[english,catalan]{babel}\ usepackage[ansinew]{inputenc}\ usepackage{geometry}\ usepackage{enumerate}

We are signing our document X\ title {The Denisova hominin}\ author {N.E.Ander et al.}\ date {Just about today}

We are changing the default layout of the document

\ parskip=5mm\ geometry{top=2.5cm,left=3cm,right=3cm,bottom=2.5cm}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 7 / 41

Page 12: LaTeX tutorial II

A preamble: preambles

What is going on here?

We are declaring the kind of document we want X\ documentclass[a4paper,12pt]{article}

We are telling LATEX we will do some “special tricks”

\ usepackage[english,catalan]{babel}\ usepackage[ansinew]{inputenc}\ usepackage{geometry}\ usepackage{enumerate}

We are signing our document X\ title {The Denisova hominin}\ author {N.E.Ander et al.}\ date {Just about today}

We are changing the default layout of the document

\ parskip=5mm\ geometry{top=2.5cm,left=3cm,right=3cm,bottom=2.5cm}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 7 / 41

Page 13: LaTeX tutorial II

A preamble: preambles

What is going on here?

We are declaring the kind of document we want X\ documentclass[a4paper,12pt]{article}

We are telling LATEX we will do some “special tricks”

\ usepackage[english,catalan]{babel}\ usepackage[ansinew]{inputenc}\ usepackage{geometry}\ usepackage{enumerate}

We are signing our document X\ title {The Denisova hominin}\ author {N.E.Ander et al.}\ date {Just about today}

We are changing the default layout of the document

\ parskip=5mm\ geometry{top=2.5cm,left=3cm,right=3cm,bottom=2.5cm}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 7 / 41

Page 14: LaTeX tutorial II

A preamble: preambles

What is going on here?

We are declaring the kind of document we want X\ documentclass[a4paper,12pt]{article}

We are telling LATEX we will do some “special tricks”

\ usepackage[english,catalan]{babel}\ usepackage[ansinew]{inputenc}\ usepackage{geometry}\ usepackage{enumerate}

We are signing our document X\ title {The Denisova hominin}\ author {N.E.Ander et al.}\ date {Just about today}

We are changing the default layout of the document

\ parskip=5mm\ geometry{top=2.5cm,left=3cm,right=3cm,bottom=2.5cm}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 7 / 41

Page 15: LaTeX tutorial II

A preamble: preambles

What is going on here?

We are declaring the kind of document we want X\ documentclass[a4paper,12pt]{article}

We are telling LATEX we will do some “special tricks”

\ usepackage[english,catalan]{babel}\ usepackage[ansinew]{inputenc}\ usepackage{geometry}\ usepackage{enumerate}

We are signing our document X\ title {The Denisova hominin}\ author {N.E.Ander et al.}\ date {Just about today}

We are changing the default layout of the document

\ parskip=5mm\ geometry{top=2.5cm,left=3cm,right=3cm,bottom=2.5cm}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 7 / 41

Page 16: LaTeX tutorial II

A preamble: preambles

What is going on here?

We are declaring the kind of document we want X\ documentclass[a4paper,12pt]{article}

We are telling LATEX we will do some “special tricks”

\ usepackage[english,catalan]{babel}\ usepackage[ansinew]{inputenc}\ usepackage{geometry}\ usepackage{enumerate}

We are signing our document X\ title {The Denisova hominin}\ author {N.E.Ander et al.}\ date {Just about today}

We are changing the default layout of the document

\ parskip=5mm\ geometry{top=2.5cm,left=3cm,right=3cm,bottom=2.5cm}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 7 / 41

Page 17: LaTeX tutorial II

A preamble: preambles

What is going on here?

We are declaring the kind of document we want X\ documentclass[a4paper,12pt]{article}

We are telling LATEX we will do some “special tricks”

\ usepackage[english,catalan]{babel}\ usepackage[ansinew]{inputenc}\ usepackage{geometry}\ usepackage{enumerate}

We are signing our document X\ title {The Denisova hominin}\ author {N.E.Ander et al.}\ date {Just about today}

We are changing the default layout of the document

\ parskip=5mm\ geometry{top=2.5cm,left=3cm,right=3cm,bottom=2.5cm}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 7 / 41

Page 18: LaTeX tutorial II

A preamble: preambles

What is going on here?

We are declaring the kind of document we want X\ documentclass[a4paper,12pt]{article}

We are telling LATEX we will do some “special tricks”

\ usepackage[english,catalan]{babel}\ usepackage[ansinew]{inputenc}\ usepackage{geometry}\ usepackage{enumerate}

We are signing our document X\ title {The Denisova hominin}\ author {N.E.Ander et al.}\ date {Just about today}

We are changing the default layout of the document

\ parskip=5mm\ geometry{top=2.5cm,left=3cm,right=3cm,bottom=2.5cm}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 7 / 41

Page 19: LaTeX tutorial II

A preamble: preambles

What is going on here?

We are declaring the kind of document we want X\ documentclass[a4paper,12pt]{article}

We are telling LATEX we will do some “special tricks”

\ usepackage[english,catalan]{babel}\ usepackage[ansinew]{inputenc}\ usepackage{geometry}\ usepackage{enumerate}

We are signing our document X\ title {The Denisova hominin}\ author {N.E.Ander et al.}\ date {Just about today}

We are changing the default layout of the document

\ parskip=5mm\ geometry{top=2.5cm,left=3cm,right=3cm,bottom=2.5cm}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 7 / 41

Page 20: LaTeX tutorial II

A preamble: preambles

Remember!

Title, author and date do not appear by default

\ maketitle

Something similar happens with languages

\ selectlanguage{catalan}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 8 / 41

Page 21: LaTeX tutorial II

A preamble: preambles

Remember!

Title, author and date do not appear by default

\ maketitle

Something similar happens with languages

\ selectlanguage{catalan}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 8 / 41

Page 22: LaTeX tutorial II

A preamble: preambles

Remember!

Title, author and date do not appear by default

\ maketitle

Something similar happens with languages

\ selectlanguage{catalan}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 8 / 41

Page 23: LaTeX tutorial II

A preamble: preambles

Remember!

Title, author and date do not appear by default

\ maketitle

Something similar happens with languages

\ selectlanguage{catalan}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 8 / 41

Page 24: LaTeX tutorial II

A preamble: preambles Styling with style

Just a word on styling: Font Size

this text is tiny

this text is in scriptsize

this text is in footnotesize

this text is still small

this is the normalsize

this text is large

this text is Large

Man, this text is LARGE

this is huge

this is really Huge

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 9 / 41

Page 25: LaTeX tutorial II

A preamble: preambles Styling with style

Just a word on styling: Text Alignment

Text in LATEX can be aligned as you like,

you just have to say how that is. You rather have it

centered, to the left or to the right?

\begin{flushleft}

Text in \LaTeX can be aligned as you like,

\end{flushleft}

\begin{center}

you just have to say how that is. You rather have it

\end{center}

\begin{flushright}

centered, to the left or to the right?

\end{flushright}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 10 / 41

Page 26: LaTeX tutorial II

A preamble: preambles Styling with style

Just a word on styling: Text Alignment

Text in LATEX can be aligned as you like,

you just have to say how that is. You rather have it

centered, to the left or to the right?

\begin{flushleft}

Text in \LaTeX can be aligned as you like,

\end{flushleft}

\begin{center}

you just have to say how that is. You rather have it

\end{center}

\begin{flushright}

centered, to the left or to the right?

\end{flushright}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 10 / 41

Page 27: LaTeX tutorial II

Listing the lists

Outline

1 A preamble: preamblesStyling with style

2 Listing the listsItemizing stuffEnumerating stuffDefining stuff

3 Floating elementsImagine imagesWhy must there always be a table?

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 11 / 41

Page 28: LaTeX tutorial II

Listing the lists

Three examples of lists

Itemizing only puts bullets. . .

. . . it makes an unordered list.

1 Enumeration numbers each item. . .

2 . . . automatically, of course.

Description is seldom used, though it’s nice.

Items are put as in a dictionary.

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 12 / 41

Page 29: LaTeX tutorial II

Listing the lists

Three examples of lists

Itemizing only puts bullets. . .

. . . it makes an unordered list.

1 Enumeration numbers each item. . .

2 . . . automatically, of course.

Description is seldom used, though it’s nice.

Items are put as in a dictionary.

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 12 / 41

Page 30: LaTeX tutorial II

Listing the lists

Three examples of lists

Itemizing only puts bullets. . .

. . . it makes an unordered list.

1 Enumeration numbers each item. . .

2 . . . automatically, of course.

Description is seldom used, though it’s nice.

Items are put as in a dictionary.

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 12 / 41

Page 31: LaTeX tutorial II

Listing the lists

Three examples of lists

Itemizing only puts bullets. . .

. . . it makes an unordered list.

1 Enumeration numbers each item. . .

2 . . . automatically, of course.

Description is seldom used, though it’s nice.

Items are put as in a dictionary.

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 12 / 41

Page 32: LaTeX tutorial II

Listing the lists Itemizing stuff

Itemizing stuff

The basic way:

\begin{itemize}

\item First item

\item Second item

\item Third item

\end{itemize}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 13 / 41

Page 33: LaTeX tutorial II

Listing the lists Itemizing stuff

Itemizing stuff

Itemization provides four levels, by nesting several itemizeenvironments

\begin{itemize}

\item First level

\begin{itemize}

\item Second level

\begin{itemize}

\item Third level

\begin{itemize}

\item Fourth level

\end{itemize}

\end{itemize}

\end{itemize}

\end{itemize}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 14 / 41

Page 34: LaTeX tutorial II

Listing the lists Itemizing stuff

Itemizing stuff

Itemization provides four levels, by nesting several itemizeenvironments

\begin{itemize}

\item First level

\begin{itemize}

\item Second level

\begin{itemize}

\item Third level

\begin{itemize}

\item Fourth level

\end{itemize}

\end{itemize}

\end{itemize}

\end{itemize}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 14 / 41

Page 35: LaTeX tutorial II

Listing the lists Itemizing stuff

A quick challenge

First level

Second level

First levelSecond level

Third level

Second level

Third levelThird level

First level

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 15 / 41

Page 36: LaTeX tutorial II

Listing the lists Itemizing stuff

Was it hard?

\begin{itemize}

\item First level

\begin{itemize}

\item Second level

\end{itemize}

\item First level

\begin{itemize}

\item Second level

\begin{itemize}

\item Third level

\end{itemize}

\item Second level

\begin{itemize}

\item Third level

\item Third level

\end{itemize}

\end{itemize}

\item First level

\end{itemize}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 16 / 41

Page 37: LaTeX tutorial II

Listing the lists Enumerating stuff

Enumerating stuff

The basic way, almost like itemizing:

\begin{enumerate}

\item First item

\item Second item

\item Third item

\end{enumerate}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 17 / 41

Page 38: LaTeX tutorial II

Listing the lists Enumerating stuff

Enumerating stuff

Like with itemization, four levels are provided with differentnumeration symbols: Arabic numbers, bracketted latin letters, romannumbers and capital latin letters.

Good news is: it is very easy to change those symbols:

(i) roman numbers(ii) with brackets

1) arabic numbers2) with a single bracket

A.- capital latin lettersB.- with a dot and a dash

∀(x) →1 meaningless logical formula∀(x) →2 and an arabic number

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 18 / 41

Page 39: LaTeX tutorial II

Listing the lists Enumerating stuff

Enumerating stuff

Like with itemization, four levels are provided with differentnumeration symbols: Arabic numbers, bracketted latin letters, romannumbers and capital latin letters.

Good news is: it is very easy to change those symbols:

(i) roman numbers(ii) with brackets

1) arabic numbers2) with a single bracket

A.- capital latin lettersB.- with a dot and a dash

∀(x) →1 meaningless logical formula∀(x) →2 and an arabic number

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 18 / 41

Page 40: LaTeX tutorial II

Listing the lists Enumerating stuff

Enumerating stuff

Like with itemization, four levels are provided with differentnumeration symbols: Arabic numbers, bracketted latin letters, romannumbers and capital latin letters.

Good news is: it is very easy to change those symbols:

(i) roman numbers(ii) with brackets

1) arabic numbers2) with a single bracket

A.- capital latin lettersB.- with a dot and a dash

∀(x) →1 meaningless logical formula∀(x) →2 and an arabic number

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 18 / 41

Page 41: LaTeX tutorial II

Listing the lists Enumerating stuff

. . . enumeration not enumerating any more!

You can even make enumeration look like an itemized list:

- with dashes- and nothing else

% with percent symbols% if you fancy

with nothing at all(really, this is an enumeration too)

:-) with anything:-) that you want ;-)

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 19 / 41

Page 42: LaTeX tutorial II

Listing the lists Enumerating stuff

. . . enumeration not enumerating any more!

You can even make enumeration look like an itemized list:

- with dashes- and nothing else

% with percent symbols% if you fancy

with nothing at all(really, this is an enumeration too)

:-) with anything:-) that you want ;-)

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 19 / 41

Page 43: LaTeX tutorial II

Listing the lists Enumerating stuff

. . . enumeration not enumerating any more!

You can even make enumeration look like an itemized list:

- with dashes- and nothing else

% with percent symbols% if you fancy

with nothing at all(really, this is an enumeration too)

:-) with anything:-) that you want ;-)

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 19 / 41

Page 44: LaTeX tutorial II

Listing the lists Enumerating stuff

. . . enumeration not enumerating any more!

You can even make enumeration look like an itemized list:

- with dashes- and nothing else

% with percent symbols% if you fancy

with nothing at all(really, this is an enumeration too)

:-) with anything:-) that you want ;-)

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 19 / 41

Page 45: LaTeX tutorial II

Listing the lists Enumerating stuff

. . . enumeration not enumerating any more!

You can even make enumeration look like an itemized list:

- with dashes- and nothing else

% with percent symbols% if you fancy

with nothing at all(really, this is an enumeration too)

:-) with anything:-) that you want ;-)

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 19 / 41

Page 46: LaTeX tutorial II

Listing the lists Enumerating stuff

Some examples

\usepackage{enumerate}

\begin{enumerate}[(i)]

\item roman numbers

\item with brackets

\end{enumerate}

\begin{enumerate}[]

\item with nothing at all

\item (really, this is an enumeration too)

\end{enumerate}\

\begin{enumerate}[:-)]

\item with anything

\item that you want ;-)

\end{enumerate}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 20 / 41

Page 47: LaTeX tutorial II

Listing the lists Defining stuff

Defining stuff

The basic way. Notice the defined term is entered as an optionalargument to \item:

\begin{description}

\item[One] First item

\item[Two] Second item

\item[Three] Third item

\end{description}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 21 / 41

Page 48: LaTeX tutorial II

Listing the lists Defining stuff

Defining stuff

It looks good, as in a dictionary:

One First itemTwo Second item

Three Third item

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 22 / 41

Page 49: LaTeX tutorial II

Floating elements

Outline

1 A preamble: preamblesStyling with style

2 Listing the listsItemizing stuffEnumerating stuffDefining stuff

3 Floating elementsImagine imagesWhy must there always be a table?

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 23 / 41

Page 50: LaTeX tutorial II

Floating elements

Why “floating”?

There are two basic types: figures and tables

They do not have a fixed placing in the page: LATEX decides where isbest to anchor them so they don’t interrupt the flow of the text

They are containers to elements that cannot be split or brokenbetween pages.

Additionally, they have a caption defining them, and they arenumbered (so they can be referred to easily in the text).

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 24 / 41

Page 51: LaTeX tutorial II

Floating elements

Why “floating”?

There are two basic types: figures and tables

They do not have a fixed placing in the page: LATEX decides where isbest to anchor them so they don’t interrupt the flow of the text

They are containers to elements that cannot be split or brokenbetween pages.

Additionally, they have a caption defining them, and they arenumbered (so they can be referred to easily in the text).

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 24 / 41

Page 52: LaTeX tutorial II

Floating elements

Why “floating”?

There are two basic types: figures and tables

They do not have a fixed placing in the page: LATEX decides where isbest to anchor them so they don’t interrupt the flow of the text

They are containers to elements that cannot be split or brokenbetween pages.

Additionally, they have a caption defining them, and they arenumbered (so they can be referred to easily in the text).

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 24 / 41

Page 53: LaTeX tutorial II

Floating elements

Why “floating”?

There are two basic types: figures and tables

They do not have a fixed placing in the page: LATEX decides where isbest to anchor them so they don’t interrupt the flow of the text

They are containers to elements that cannot be split or brokenbetween pages.

Additionally, they have a caption defining them, and they arenumbered (so they can be referred to easily in the text).

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 24 / 41

Page 54: LaTeX tutorial II

Floating elements Imagine images

Figures: an example

Figure: Not this kind of latex

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 25 / 41

Page 55: LaTeX tutorial II

Floating elements Imagine images

Hands on: lets include an image

First of all, we must declare the graphicx package

\usepackage{graphicx}

Then, we prepare the figure environment

\begin{figure}[h]

\ldots

\end{figure}

Notice the [h] there?

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 26 / 41

Page 56: LaTeX tutorial II

Floating elements Imagine images

Hands on: lets include an image

First of all, we must declare the graphicx package

\usepackage{graphicx}

Then, we prepare the figure environment

\begin{figure}[h]

\ldots

\end{figure}

Notice the [h] there?

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 26 / 41

Page 57: LaTeX tutorial II

Floating elements Imagine images

Hands on: lets include an image

First of all, we must declare the graphicx package

\usepackage{graphicx}

Then, we prepare the figure environment

\begin{figure}[h]

\ldots

\end{figure}

Notice the [h] there?

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 26 / 41

Page 58: LaTeX tutorial II

Floating elements Imagine images

Hands off! Placing floats

All floats take an optional argument: the place specifier.There are four possible values:

h → here

t → top

b → bottom

p → sepparate page just for floats

They can be forced by adding an exclamation mark ([h!])However, in the end, they are just a suggestion: LATEX has the final word

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 27 / 41

Page 59: LaTeX tutorial II

Floating elements Imagine images

Hands off! Placing floats

All floats take an optional argument: the place specifier.There are four possible values:

h → here

t → top

b → bottom

p → sepparate page just for floats

They can be forced by adding an exclamation mark ([h!])However, in the end, they are just a suggestion: LATEX has the final word

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 27 / 41

Page 60: LaTeX tutorial II

Floating elements Imagine images

Hands off! Placing floats

All floats take an optional argument: the place specifier.There are four possible values:

h → here

t → top

b → bottom

p → sepparate page just for floats

They can be forced by adding an exclamation mark ([h!])However, in the end, they are just a suggestion: LATEX has the final word

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 27 / 41

Page 61: LaTeX tutorial II

Floating elements Imagine images

Hands on (again): lets include an image

Next step: tell LATEX what image we want to include, and how big itmust be

\begin{figure}[h]

\includegraphics[width=5cm]{images/image.png}

\end{figure}

Regarding size, we can tinker with

Image width → [width=Xcm]Image height → [height=Xcm]Scaling factor → [scale=1.5]Rotation angle (in degrees) → [angle=X]

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 28 / 41

Page 62: LaTeX tutorial II

Floating elements Imagine images

Hands on (again): lets include an image

Next step: tell LATEX what image we want to include, and how big itmust be

\begin{figure}[h]

\includegraphics[width=5cm]{images/image.png}

\end{figure}

Regarding size, we can tinker with

Image width → [width=Xcm]Image height → [height=Xcm]Scaling factor → [scale=1.5]Rotation angle (in degrees) → [angle=X]

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 28 / 41

Page 63: LaTeX tutorial II

Floating elements Imagine images

Hands on (again): lets include an image

Next step: tell LATEX what image we want to include, and how big itmust be

\begin{figure}[h]

\includegraphics[width=5cm]{images/image.png}

\end{figure}

Regarding size, we can tinker with

Image width → [width=Xcm]Image height → [height=Xcm]Scaling factor → [scale=1.5]Rotation angle (in degrees) → [angle=X]

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 28 / 41

Page 64: LaTeX tutorial II

Floating elements Imagine images

Hands on (again): lets include an image

Next step: tell LATEX what image we want to include, and how big itmust be

\begin{figure}[h]

\includegraphics[width=5cm]{images/image.png}

\end{figure}

Regarding size, we can tinker with

Image width → [width=Xcm]Image height → [height=Xcm]Scaling factor → [scale=1.5]Rotation angle (in degrees) → [angle=X]

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 28 / 41

Page 65: LaTeX tutorial II

Floating elements Imagine images

Hands on (again): lets include an image

Next step: tell LATEX what image we want to include, and how big itmust be

\begin{figure}[h]

\includegraphics[width=5cm]{images/image.png}

\end{figure}

Regarding size, we can tinker with

Image width → [width=Xcm]Image height → [height=Xcm]Scaling factor → [scale=1.5]Rotation angle (in degrees) → [angle=X]

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 28 / 41

Page 66: LaTeX tutorial II

Floating elements Imagine images

Hands on (again): lets include an image

Finally, we can add a caption to the image (either before or after theimage itself, within the environment)

\begin{figure}[h]

\includegraphics[width=5cm]{images/image.png}

\caption{This image has served us as a tutorial.}

\end{figure}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 29 / 41

Page 67: LaTeX tutorial II

Floating elements Imagine images

Imagine not only images

Although this is not as common, the contents of the figure environmentcan be text. For instance:

Com evident experiencia mostra, la debilitat de la nostra memoria, sotsmetent facilmenta oblivio no solament los actes per longitud de temps envellits, mas encara los actes

frescs de nostres dies, es estat doncs molt condecent, util e expedient deduir en escrit lesgestes e histories antigues dels homens forts e virtuosos, com sien espills molt clars,exemples e virtuosa doctrina de nostra vida, segons recita aquell gran orador Tul·li.

Figura: A fragment of Tirant lo Blanc

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 30 / 41

Page 68: LaTeX tutorial II

Floating elements Imagine images

Imagine not only images

Although this is not as common, the contents of the figure environmentcan be text. For instance:

Com evident experiencia mostra, la debilitat de la nostra memoria, sotsmetent facilmenta oblivio no solament los actes per longitud de temps envellits, mas encara los actes

frescs de nostres dies, es estat doncs molt condecent, util e expedient deduir en escrit lesgestes e histories antigues dels homens forts e virtuosos, com sien espills molt clars,exemples e virtuosa doctrina de nostra vida, segons recita aquell gran orador Tul·li.

Figura: A fragment of Tirant lo Blanc

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 30 / 41

Page 69: LaTeX tutorial II

Floating elements Why must there always be a table?

Ready? The tough part begins now...

...so take a deep breath.

The fun part begins now!

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 31 / 41

Page 70: LaTeX tutorial II

Floating elements Why must there always be a table?

How a table looks like in the final .pdf...

JOHN MARY JAMES

Monday ironing cooking vacuum cleaning

Tuesday cooking dusting sweepingWednesday shopping

Thursday bathroom cleaning cooking

Friday rest

Table: This table is neat!

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 32 / 41

Page 71: LaTeX tutorial II

Floating elements Why must there always be a table?

...and how it looks like in the .tex

\begin{table}[h!]

\begin{tabular}{|c|c|c|c|}

\cline{2-4}

\multicolumn{1}{c|}{} & JOHN & MARY & JAMES \\\hline

Monday & ironing & cooking & vacuum cleaning \\\hline

Tuesday & cooking & dusting & sweeping \\\cline{1-1}\cline{3-4}

Wednesday & & \multicolumn{2}{c|}{shopping}\\\hline

Thursday & \multicolumn{2}{c|}{bathroom cleaning} & cooking \\\hline

Friday & \multicolumn{3}{c|}{rest}\\\hline

\end{tabular}

\caption{This table is neat!}

\end{table}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 33 / 41

Page 72: LaTeX tutorial II

Floating elements Why must there always be a table?

Lets walk through it step by step

First, we prepare the table environment

\begin{table}[ht!]

...

\caption{This table is neat!}

\end{table}

\caption is optional

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 34 / 41

Page 73: LaTeX tutorial II

Floating elements Why must there always be a table?

Lets walk through it step by step

First, we prepare the table environment

\begin{table}[ht!]

...

\caption{This table is neat!}

\end{table}

\caption is optional

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 34 / 41

Page 74: LaTeX tutorial II

Floating elements Why must there always be a table?

Lets walk through it step by step

Next, we create the table with the tabular environment

\begin{table}[ht!]

\begin{tabular}{alignment}

...

\end{tabular}

\caption{This table is neat!}

\end{table}

Possible alignments are l (left), c (center) and r (right)

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 35 / 41

Page 75: LaTeX tutorial II

Floating elements Why must there always be a table?

Lets walk through it step by step

Next, we create the table with the tabular environment

\begin{table}[ht!]

\begin{tabular}{alignment}

...

\end{tabular}

\caption{This table is neat!}

\end{table}

Possible alignments are l (left), c (center) and r (right)

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 35 / 41

Page 76: LaTeX tutorial II

Floating elements Why must there always be a table?

Lets walk through it step by step

Next, we create the table with the tabular environment

\begin{table}[ht!]

\begin{tabular}{rcl}

...

\end{tabular}

\caption{This table is neat!}

\end{table}

Possible alignments are l (left), c (center) and r (right)

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 36 / 41

Page 77: LaTeX tutorial II

Floating elements Why must there always be a table?

Lets walk through it step by step

Finally, we add row after row of table

\begin{table}[ht!]

\begin{tabular}{rcl}

A & B & C \\

AA & BB & CC \\

AAA & BBB & CCC \\

AAAA & BBBB & CCCC \\

\end{tabular}

\caption{This table is neat!}

\end{table}

The ampersand (&) is the column divider, a linebreak (\\) finisheseach row.

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 37 / 41

Page 78: LaTeX tutorial II

Floating elements Why must there always be a table?

Ok, run it!

if we run the previous code, we get...

A B CAA BB CC

AAA BBB CCCAAAA BBBB CCCC

Table: This table is neat!

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 38 / 41

Page 79: LaTeX tutorial II

Floating elements Why must there always be a table?

Ok, run it!

if we run the previous code, we get...

A B CAA BB CC

AAA BBB CCCAAAA BBBB CCCC

Table: This table is neat!

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 38 / 41

Page 80: LaTeX tutorial II

Floating elements Why must there always be a table?

Lets add lines

\begin{table}[ht!]

\begin{tabular}{|r|c|l|}

\hline

A & B & C \\ \hline

AA & BB & CC \\ \cline{1-2}

AAA & BBB & CCC \\ \cline{2-3}

AAAA & BBBB & CCCC \\ \hline

\end{tabular}

\caption{This table is neat!}

\end{table}

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 39 / 41

Page 81: LaTeX tutorial II

Floating elements Why must there always be a table?

Lets add lines

A B C

AA BB CCAAA BBB CCC

AAAA BBBB CCCC

Table: This table is neat!

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 40 / 41

Page 82: LaTeX tutorial II

Floating elements Why must there always be a table?

Another quick challenge

COLUMN A COLUMN B COLUMN C

ROW 1 A1 B1 C1ROW 2 A2 B2 C2ROW 3 A3 B3 C3

Table: This table is a quick exercise

Borrega & Martins (UB) Introduction to LATEX Session #2 January 21, 2013 41 / 41