1. A
Introduction to LTEX
Session #3
Oriol Borrega Pedro Tiago Martins
Universitat de Barcelona
February 4, 2013
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 1 / 29
2. Outline
1 A bit more on. . .
. . . tables. . .
. . . and sections.
2 References
Cross-references
Bibliography
3 Basic maths
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 2 / 29
3. A bit more on. . .
Outline
1 A bit more on. . .
. . . tables. . .
. . . and sections.
2 References
Cross-references
Bibliography
3 Basic maths
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 3 / 29
4. A bit more on. . . . . . tables. . .
What if I wanted to. . .
Col A Col B Col C Col D Col E
Row 1 A1 B1 C1 D1 E1
Row 2 A2-B2 C2 D2 E2
Row 3 A3-C3 D3 E3
Row 4 A4-D4 E4
Row 5 A5-E5
Table: A table with rows spanning over several columns
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 4 / 29
5. A bit more on. . . . . . tables. . .
Easy peasy!
First, call the package in the preamble:
usepackage{multicol}
Then, in the corresponding cell, specify the columns the cell must
span over, its text alignment and vertical lines, and its content:
multicolumn{3}{|c|}{Content of the cell}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 5 / 29
6. A bit more on. . . . . . tables. . .
Easy peasy!
First, call the package in the preamble:
usepackage{multicol}
Then, in the corresponding cell, specify the columns the cell must
span over, its text alignment and vertical lines, and its content:
multicolumn{3}{|c|}{Content of the cell}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 5 / 29
7. A bit more on. . . . . . tables. . .
Ready!
First column Second column
First row MULTICOLUMN
Second row single column single column
begin{table}[h]
begin{tabular}{|l|l|l|}
cline{2-3}
multicolumn{1}{c|}{} & First column & Second column hline
First row & multicolumn{2}{|c|}{MULTICOLUMN} hline
Second row & single column & single column hline
end{tabular}
end{table}
Borrega & Martins (UB) Introduction to L TEX Session #3
A February 4, 2013 6 / 29
8. A bit more on. . . . . . tables. . .
Ready!
First column Second column
First row MULTICOLUMN
Second row single column single column
begin{table}[h]
begin{tabular}{|l|l|l|}
cline{2-3}
multicolumn{1}{c|}{} & First column & Second column hline
First row & multicolumn{2}{|c|}{MULTICOLUMN} hline
Second row & single column & single column hline
end{tabular}
end{table}
Borrega & Martins (UB) Introduction to L TEX Session #3
A February 4, 2013 6 / 29
9. A bit more on. . . . . . tables. . .
Set!
Text alignment within cells (and number of columns):
begin{tabular}{clr}
Vertical lines: begin{tabular}{|c|l|r|}
Horizontal lines: hline
Cells that span over several columns: multicolumn{}{}{}
Cells that span over several rows: cline{}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 7 / 29
10. A bit more on. . . . . . tables. . .
Set!
Text alignment within cells (and number of columns):
begin{tabular}{clr}
Vertical lines: begin{tabular}{|c|l|r|}
Horizontal lines: hline
Cells that span over several columns: multicolumn{}{}{}
Cells that span over several rows: cline{}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 7 / 29
11. A bit more on. . . . . . tables. . .
Set!
Text alignment within cells (and number of columns):
begin{tabular}{clr}
Vertical lines: begin{tabular}{|c|l|r|}
Horizontal lines: hline
Cells that span over several columns: multicolumn{}{}{}
Cells that span over several rows: cline{}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 7 / 29
12. A bit more on. . . . . . tables. . .
Set!
Text alignment within cells (and number of columns):
begin{tabular}{clr}
Vertical lines: begin{tabular}{|c|l|r|}
Horizontal lines: hline
Cells that span over several columns: multicolumn{}{}{}
Cells that span over several rows: cline{}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 7 / 29
13. A bit more on. . . . . . tables. . .
Set!
Text alignment within cells (and number of columns):
begin{tabular}{clr}
Vertical lines: begin{tabular}{|c|l|r|}
Horizontal lines: hline
Cells that span over several columns: multicolumn{}{}{}
Cells that span over several rows: cline{}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 7 / 29
14. A bit more on. . . . . . tables. . .
Go!
Column 1 Column 2 Column 3 Column 4
Row A Above
Row B Below Above
Row C Below Above
Row D Below Above
Row E Below
Table: Today’s first exercise.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 8 / 29
15. A bit more on. . . . . . tables. . .
The solution
begin{table}[h]
centering
begin{tabular}{|c|c|c|c|c|}
cline{2-5}
multicolumn{1}{c|}{} & Column 1 & Column 2 & Column 3 & Column 4 hline
Row A & multicolumn{4}{|l|}{Above}
cline{1-2}
Row B & multicolumn{1}{|r}{Below} & multicolumn{3}{|l|}{Above}
cline{1-1} cline{3-3}
Row C & multicolumn{2}{|r|}{Below}& multicolumn{2}{|l|}{Above}
cline{1-1} cline{4-4}
Row D & multicolumn{3}{|r|}{Below}& multicolumn{1}{l|}{Above}
cline{1-1} cline{5-5}
Row E & multicolumn{4}{|r|}{Below} hline
end{tabular}
caption{Today’s first exercise.}
end{table}
Borrega & Martins (UB) Introduction to L TEX Session #3
A February 4, 2013 9 / 29
16. A bit more on. . . . . . and sections.
Section: others
If we want sections to appear with a different name in the table of
contents:
section[Title for the ToC]{Real title of the section}
If we want sections not to appear in the table of contents:
section*{Title of the section}
To include appendices (sections numbered in letters):
appendix AT THE BEGINNING OF THEM ALL
To make an abstract:
begin{abstract}
...
end{abstract}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 10 / 29
17. A bit more on. . . . . . and sections.
Section: others
If we want sections to appear with a different name in the table of
contents:
section[Title for the ToC]{Real title of the section}
If we want sections not to appear in the table of contents:
section*{Title of the section}
To include appendices (sections numbered in letters):
appendix AT THE BEGINNING OF THEM ALL
To make an abstract:
begin{abstract}
...
end{abstract}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 10 / 29
18. A bit more on. . . . . . and sections.
Section: others
If we want sections to appear with a different name in the table of
contents:
section[Title for the ToC]{Real title of the section}
If we want sections not to appear in the table of contents:
section*{Title of the section}
To include appendices (sections numbered in letters):
appendix AT THE BEGINNING OF THEM ALL
To make an abstract:
begin{abstract}
...
end{abstract}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 10 / 29
19. A bit more on. . . . . . and sections.
Section: others
If we want sections to appear with a different name in the table of
contents:
section[Title for the ToC]{Real title of the section}
If we want sections not to appear in the table of contents:
section*{Title of the section}
To include appendices (sections numbered in letters):
appendix AT THE BEGINNING OF THEM ALL
To make an abstract:
begin{abstract}
...
end{abstract}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 10 / 29
20. A bit more on. . . . . . and sections.
Section: others
To limit the depth of the table of contents:
setcounter{tocdepth}{2} IN THE PREAMBLE
All possible levels and their depth:
-1 part{title} NOT FOR ARTICLE
0 chapter{title} NOT FOR ARTICLE
1 section{title}
2 subsection{title}
3 subsubsection{title}
4 paragraph{title}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 11 / 29
21. A bit more on. . . . . . and sections.
Section: others
To limit the depth of the table of contents:
setcounter{tocdepth}{2} IN THE PREAMBLE
All possible levels and their depth:
-1 part{title} NOT FOR ARTICLE
0 chapter{title} NOT FOR ARTICLE
1 section{title}
2 subsection{title}
3 subsubsection{title}
4 paragraph{title}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 11 / 29
22. A bit more on. . . . . . and sections.
Yet another ‘copy what you see’ exercise. . .
https://dl.dropbox.com/u/4636832/exercise2.rar
Download the file above. . .
. . . and try to reproduce the file TocToc.pdf
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 12 / 29
23. References
Outline
1 A bit more on. . .
. . . tables. . .
. . . and sections.
2 References
Cross-references
Bibliography
3 Basic maths
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 13 / 29
24. References Cross-references
Label and refer
To refer to an element, first we must label it:
label{sec:biology}
Once labeled, it can be refered to anywhere in the text:
ref{sec:biology}
Or you can refer to the page the element is in:
pageref{sec:biology}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 14 / 29
25. References Cross-references
Label and refer
To refer to an element, first we must label it:
label{sec:biology}
Once labeled, it can be refered to anywhere in the text:
ref{sec:biology}
Or you can refer to the page the element is in:
pageref{sec:biology}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 14 / 29
26. References Cross-references
Label and refer
To refer to an element, first we must label it:
label{sec:biology}
Once labeled, it can be refered to anywhere in the text:
ref{sec:biology}
Or you can refer to the page the element is in:
pageref{sec:biology}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 14 / 29
27. References Cross-references
What and how to label
You can label/reference almost anything: figures, tables, sections,
items, equations,. . .
Where do I put the label?
sections Anywhere within the section (it is recommended to
place the label just after the section{} command).
figures Just after the caption{} (or within it).
tables Just after the caption{} (or within it).
items Either after the item label or after the item’s text. By
default, this only works in enumerations.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 15 / 29
28. References Cross-references
What and how to label
You can label/reference almost anything: figures, tables, sections,
items, equations,. . .
Where do I put the label?
sections Anywhere within the section (it is recommended to
place the label just after the section{} command).
figures Just after the caption{} (or within it).
tables Just after the caption{} (or within it).
items Either after the item label or after the item’s text. By
default, this only works in enumerations.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 15 / 29
29. References Cross-references
What and how to label
You can label/reference almost anything: figures, tables, sections,
items, equations,. . .
Where do I put the label?
sections Anywhere within the section (it is recommended to
place the label just after the section{} command).
figures Just after the caption{} (or within it).
tables Just after the caption{} (or within it).
items Either after the item label or after the item’s text. By
default, this only works in enumerations.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 15 / 29
30. References Cross-references
What and how to label
You can label/reference almost anything: figures, tables, sections,
items, equations,. . .
Where do I put the label?
sections Anywhere within the section (it is recommended to
place the label just after the section{} command).
figures Just after the caption{} (or within it).
tables Just after the caption{} (or within it).
items Either after the item label or after the item’s text. By
default, this only works in enumerations.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 15 / 29
31. References Cross-references
What and how to label
You can label/reference almost anything: figures, tables, sections,
items, equations,. . .
Where do I put the label?
sections Anywhere within the section (it is recommended to
place the label just after the section{} command).
figures Just after the caption{} (or within it).
tables Just after the caption{} (or within it).
items Either after the item label or after the item’s text. By
default, this only works in enumerations.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 15 / 29
32. References Cross-references
What and how to label
You can label/reference almost anything: figures, tables, sections,
items, equations,. . .
Where do I put the label?
sections Anywhere within the section (it is recommended to
place the label just after the section{} command).
figures Just after the caption{} (or within it).
tables Just after the caption{} (or within it).
items Either after the item label or after the item’s text. By
default, this only works in enumerations.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 15 / 29
33. References Cross-references
What and how to label
As labels grow in number, they might get messy.
Advice: use semantically meaningful labels.
chap:name chapter
sec:name section
fig:name figure
tab:name table
itm:keyword item
A
Table: The usual method of labelling in LTEX
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 16 / 29
34. References Cross-references
Let’s try all this on the file exercise2.tex
First:
1 Create an abstract at the beginning.
2 Change the title of section 4 in the ToC to Interbreeding.
3 Make section 5 disappear from the ToC.
4 Make The sapiens ascent an appendix.
Then, build references to:
1 Image 2
2 A table.
3 A section
4 A subsection.
5 An item of a list.
6 The page containing image 1.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 17 / 29
35. References Bibliography
Bibliography: the basics
Bibliography is best managed with BibTeX, a sepparate extension to
LaTeX.
References are stored in a .bib file.
The file is linked at the end of the main .tex file.
The style of the references is declared with the link to the
bibliography.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 18 / 29
36. References Bibliography
Bibliography: the basics
Bibliography is best managed with BibTeX, a sepparate extension to
LaTeX.
References are stored in a .bib file.
The file is linked at the end of the main .tex file.
The style of the references is declared with the link to the
bibliography.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 18 / 29
37. References Bibliography
Bibliography: the basics
Bibliography is best managed with BibTeX, a sepparate extension to
LaTeX.
References are stored in a .bib file.
The file is linked at the end of the main .tex file.
The style of the references is declared with the link to the
bibliography.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 18 / 29
38. References Bibliography
Bibliography: the basics
Bibliography is best managed with BibTeX, a sepparate extension to
LaTeX.
References are stored in a .bib file.
The file is linked at the end of the main .tex file.
The style of the references is declared with the link to the
bibliography.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 18 / 29
39. References Bibliography
The Bibliography .bib file
It is a database with all the references you wish to use in a specified
format.
Each type of publication needs some specific fields, and may have
additional information.
A piece of advice: put all your references in a single file, and use it for
any paper/thesis/abstract/whatever you are writting at the moment.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 19 / 29
40. References Bibliography
The Bibliography .bib file
It is a database with all the references you wish to use in a specified
format.
Each type of publication needs some specific fields, and may have
additional information.
A piece of advice: put all your references in a single file, and use it for
any paper/thesis/abstract/whatever you are writting at the moment.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 19 / 29
41. References Bibliography
The Bibliography .bib file
It is a database with all the references you wish to use in a specified
format.
Each type of publication needs some specific fields, and may have
additional information.
A piece of advice: put all your references in a single file, and use it for
any paper/thesis/abstract/whatever you are writting at the moment.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 19 / 29
42. References Bibliography
Hands on
@article{gibbons2011,
author = {Ann Gibbons},
title = {Who were the Denisovans?},
journal = {Science},
number = {333},
pages = {1084-87},
year = {2011}
}
Borrega & Martins (UB) Introduction to L TEX Session #3
A February 4, 2013 20 / 29
43. References Bibliography
Types of publications
compulsory optional
@article author, title, journal, year volume, number, pages,
month, note
@book author/editor, title, publisher, address, edition, volume,
year number, series, month, note
@inproceedings author, title, booktitle, year editor, volume, number, se-
ries, pages, address, month,
organization, publisher, note
@inbook author/editor, title, chapter volume, number, series, type,
and/or pages, publisher, year address, edition, month, note
@phdthesis author, title, year, school address, month, keywords,
note
@misc — auhor, title, howpublished,
month, year, note
Table: Quick reference chart for types of publications and their fields.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 21 / 29
44. References Bibliography
And citing, actually
In text references are called using the label of the publication:
cite{label}
nocite{label}
The bibliography is displayed by calling the bib file at the end of the
document:
bibliography{exercise2}
bibliographystyle{apalike}
end{document}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 22 / 29
45. References Bibliography
And citing, actually
In text references are called using the label of the publication:
cite{label}
nocite{label}
The bibliography is displayed by calling the bib file at the end of the
document:
bibliography{exercise2}
bibliographystyle{apalike}
end{document}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 22 / 29
46. References Bibliography
Try it on the file exercise2.tex
1 Add Gibbons’ reference to the end of the last paragraph of section 4.
2 Add Gould’s reference to his citation at the beginning of the
document.
3 Add Skoglund’s reference in the footnote
4 Change your bibliography style from apalike to plain
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 23 / 29
47. References Bibliography
Bibliography styles
You can find online examples of bibliography styles
here
here
and here
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 24 / 29
48. References Bibliography
What if I like the author(year) format?
usepackage{natbib} IN THE PREAMBLE, as always
begin{document}
... citet{label} ...
... citep{label} ...
... citep[e.g.,][]{label} ...
... citep[see][p.103]{label} ...
... citep[hereafter SJG, 89]{label} ...
end{document}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 25 / 29
49. Basic maths
Outline
1 A bit more on. . .
. . . tables. . .
. . . and sections.
2 References
Cross-references
Bibliography
3 Basic maths
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 26 / 29
50. Basic maths
Writing maths is easier than understanding maths
The maths environment allows for the use of lots of symbols:
Greek letters: α, β, ψ, ω, Σ, Θ, Ξ
Arrows: →, , , ⇔
Logic: ∀, ∃, ∈, ⊆
√
Maths: root, ÷, ≤, ≈
Miscellaneous: ℵ, c , ∞, ♥, ♠, ‡, √
n ∞ 2 π
Equations and complicated stuff: i=0 i
3
= 0
e −x dx = 2
It is delimited by $ . . . $ (inline) or $$ . . . $$ (displayed)
To use it properly, call the amsmath packages in the preamble:
usepackage{amsmath}
usepackage{amsfonts}
usepackage{amssymb}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 27 / 29
51. Basic maths
Writing maths is easier than understanding maths
The maths environment allows for the use of lots of symbols:
Greek letters: α, β, ψ, ω, Σ, Θ, Ξ
Arrows: →, , , ⇔
Logic: ∀, ∃, ∈, ⊆
√
Maths: root, ÷, ≤, ≈
Miscellaneous: ℵ, c , ∞, ♥, ♠, ‡, √
n ∞ 2 π
Equations and complicated stuff: i=0 i
3
= 0
e −x dx = 2
It is delimited by $ . . . $ (inline) or $$ . . . $$ (displayed)
To use it properly, call the amsmath packages in the preamble:
usepackage{amsmath}
usepackage{amsfonts}
usepackage{amssymb}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 27 / 29
52. Basic maths
Writing maths is easier than understanding maths
The maths environment allows for the use of lots of symbols:
Greek letters: α, β, ψ, ω, Σ, Θ, Ξ
Arrows: →, , , ⇔
Logic: ∀, ∃, ∈, ⊆
√
Maths: root, ÷, ≤, ≈
Miscellaneous: ℵ, c , ∞, ♥, ♠, ‡, √
n ∞ 2 π
Equations and complicated stuff: i=0 i
3
= 0
e −x dx = 2
It is delimited by $ . . . $ (inline) or $$ . . . $$ (displayed)
To use it properly, call the amsmath packages in the preamble:
usepackage{amsmath}
usepackage{amsfonts}
usepackage{amssymb}
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 27 / 29
53. Basic maths
A couple of examples...
(∀x)A(x) ↔ ¬(∃x)B(x)
$(forall x)A(x) leftrightarrow neg(exists x)B(x)$
√
T[past] ↔ ∅ { Hit}
$T_{[past]} leftrightarrow emptyset __{sqrt{textsc{Hit}}}$
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 28 / 29
54. Basic maths
A couple of examples...
(∀x)A(x) ↔ ¬(∃x)B(x)
$(forall x)A(x) leftrightarrow neg(exists x)B(x)$
√
T[past] ↔ ∅ { Hit}
$T_{[past]} leftrightarrow emptyset __{sqrt{textsc{Hit}}}$
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 28 / 29
55. Basic maths
Lists of symbols
Online, short reference guide.
PDF, comprehensive symbol list.
Borrega & Martins (UB) A
Introduction to L TEX Session #3 February 4, 2013 29 / 29