Professional Documents
Culture Documents
Additional topics
Contents
1 Tabulars
1.1 Basics . . . . . . . . . . . . . . .
1.2 Partial rules . . . . . . . . . . . .
1.3 Multicolumn . . . . . . . . . . .
1.4 Decimal alignment . . . . . . .
1.5 Text columns . . . . . . . . . . .
1.6 Shortcuts . . . . . . . . . . . . .
1.7 Practice documents for tables .
.
.
.
.
.
.
.
2
2
3
3
3
3
4
4
4
5
6
6
7
8
9
4 Presentations
4.1 Alternatives . . . . . . . . . . .
4.2 Getting started with Beamer
4.3 Slides are frames . . . . . . .
4.4 Themes . . . . . . . . . . . . .
4.5 Modes . . . . . . . . . . . . . .
4.6 What about sections? . . . . .
4.7 Practice . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.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
11
12
12
12
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
6 Language support
13
6.1 Babel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
6.2 Non-western scripts with XeTeX and LuaTeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Documentation and online resources
13
Introduction
This weeks topics include tables, graphics and floats, objects which may be placed out of
sequence. The final main topic is presentations. Practice consists of:
Fall 2012
creating and modifying a presentation, starting out from a supplied sample presentation
ADDITIONAL TOPICS
This sessions zipfile 2more.zip contains sample code, a file with table examples to be recreated
and a subdirectory with graphics suitable for inclusion in LaTEX; see sections 1.7, 3.2 and 4.2.
Bonus topics are section 5, which contains some simple recipes for changing the appearance of
your document, and section 6 on typesetting in other languages.
1 Tabulars
1.1
Basics
Outside math mode, the tabular environment provides tables, which can be considered the
text counterpart of multicolumn arrays. As with math arrays, columns are separated with &
and rows with \\.
TeXstudio has a tabular wizard, but it is not much help when things get hairy.
A very basic table:
\begin{tabular}{lcr}
small & whatever & 1 \\
big
& huh?
& 10000
\end{tabular}
small
big
whatever
huh?
1
10000
small
big
whatever
10000
You do not need to put in an ampersand & for empty cells at the end.
You can add vertical rules in the preamble and horizontal rules with an \hline command:
\begin{tabular}[t]{|l|r|r|}
\hline
& \textit{Butter} & \textit{Cheese} \\
\hline
2000 & 9.1 & 5.7 \\
\hline
2001 & 11.7 & 6.3 \\
\hline
2002 & 12.2 & 6.5 \\
\hline
\end{tabular}
2000
2001
2002
Butter
9.1
11.7
12.2
Cheese
5.7
6.3
6.5
in the preamble, to get a little bit of space between rules and the cells below. You can also issue
an \extrarowheight command in the middle of your document.
Fewer rules is probably better; see table 1 (from now on, \extrarowheight is set to 1pt):
2000
2001
2002
Butter
9.1
11.7
12.2
Cheese
5.7
6.3
6.5
Tabulars
1.2
Partial rules
\begin{tabular}{|lrr|}
\hline
& \textit{Butter} & \textit{Cheese} \\
\cline{2-3}
2000 & 9.1 & 5.7 \\
2001 & 11.7 & 6.3 \\
2002 & 12.2 & 6.5 \\
\hline
\end{tabular}
1.3
2000
2001
2002
Butter
9.1
11.7
12.2
Cheese
5.7
6.3
6.5
Multicolumn
the \multicolumn macro lets you join columns, or change the alignment of a column:
\begin{tabular}{|lrr|}
\hline
& \multicolumn{2}{c|}{Products} \\
\cline{2-3}
& \multicolumn{1}{c}{\textit{B.}}
& \multicolumn{1}{c|}{\textit{C.}} \\
\cline{2-3}
...
1.4
2000
2001
2002
Products
B.
C.
910.1
5.7
1111.7
6.3
1112.2 66.5
Decimal alignment
Often, you can simply right-align, since typically all data in a column are specified with the
same number of decimal digits. This is the case with the Butter / Cheese examples above.
If this isnt the case, you can put the following code in your preamble:
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}
This lets you use column types d{n.m} with n digits before the decimal point and m after:
\begin{tabular}{|l|d{4.2}|d{4.1}|}
\hline
2000 & 910.1 & 5.7 \\
2001 & 1111.77 & 6 \\
2002 & 1112.2 & 6666.5 \\
\hline
\end{tabular}
1.5
2000
2001
2002
910.1
1111.77
1112.2
5.7
6
6666.5
Text columns
For multiline texts, there is the p{...} column specification:
\begin{tabular}{|lp{2.2in}|}
\hline
array
& An improved implementation of \LaTeXs
tabular and array environment\\
dcolumn & Provides decimal and other alignment
for tabular- and array environments\\
\hline
\end{tabular}
array
dcolumn
An improved implementation of
LaTEXs tabular and array environment
Provides decimal and other alignment
for tabular- and array environments
Usually, text cells are far too narrow for good justification. Here, ragged right would be much
better. This can be done with the array package, which provides syntax for adding LaTEX code
before (and after) each column entry:
Fall 2012
ADDITIONAL TOPICS
\usepackage{array}
\newcolumntype{P}[1]{%
>{\raggedright\hspace{0pt}\arraybackslash}p{#1}}
\begin{tabular}{|l|P{1.65cm}|}
\hline
What is \TeX? & \TeX{} is a programming
language for typesetting.\\
\hline
\end{tabular}
What is TEX?
TEX is a
programming
language
for typesetting.
See the documentation of the array- and dcolumn packages for additional details on typesetting
tabulars.
1.6
Shortcuts
Of course, nobody wants to re-key reams of numbers. There are several solutions:
If your data are in a simple text file, or at least in a reasonably simple binary format, it may
be a nice programming exercise to convert them into LaTEX.
There is an excel2latex plugin for Excel, available from CTAN, which can create a file with a
LaTEX tabular environment from a spreadsheet range.
There is a LaTEX package odsfile which can read OpenOffice/LibreOffice spreadsheets directly, e.g.:
\usepackage{odsfile}
...
\begin{tabular}{...}
\includespread[file=filename.ods,range=a3:f8]
\end{tabular}
This package requires the lualatex engine. It is or soon will be part of our TEX Live installation.
1.7
A quick-and-dirty method: you can export (part of) a spreadsheet in pdf format and include
it as a graphic; see the next section.
sample_tabs.tex
sample_tabs.pdf
The tables in utp-tables.pdf come from Unix Text Processing, an old Unix text which has been
republished in OReillys Open Book Project: http://oreilly.com/openbook/utp/1 .
2.1
External graphics
Before we go any further, you should have some rudimentary understanding of graphics file
formats. The most important distinction is between bitmaps and vectors.
Bitmaps are built up from pixels, i.e. tiny blocks of solid color. The smaller the blocks, the
sharper the picture and the bigger the file. If you scale them up too far, the blocks become
apparent; see figure 1.
Vector graphics are built up from mathematical shapes: lines, arcs, bzier curves, text objects;
see figure 2. They scale well.
Pdflatex and the other TEX engines can only work with certain types of graphics:
pdf can contain both bitmapped and vector elements.
eps is closely related to pdf and can also contain both bitmapped and vector elements. It will
be converted behind the scenes to pdf, at least if the TEX installation allows it2 .
png is a bitmapped format. It is first choice for screenshots.
jpg or jpeg is a bitmapped format with lossy compression3 . It is first choice for photographic
images.
2. If you need more control over the eps to pdf conversion, or need conversion the other way, or need to crop margins,
have a look at the PostScript- and pdf conversions utility in the Utilities submenu of the RuG TEX Live menu.
3. To reduce file size, bitmapped images are usually compressed. For png this is done in a lossless way, i.e. the
decompressed image and the original image contain identical information. Jpeg is compressed in a lossy way, i.e.
information gets lost. However, jpeg compression works very well for photographic images, which can be reduced to
10% of their original file size without visible loss of quality.
Fall 2012
ADDITIONAL TOPICS
Figure 2. Vector art: a LibreOffice data plot, a drawing adapted from a Ghostscript
example file and a graphic generated with MetaPost
2.2
2.3
he E
3
The End
01/04/07
\usepackage{graphicx}
Normally, you dont need to specify the extension. Pdflatex will look for your_picture.jpg,
your_picture.png and your_picture.pdf.
With the above code, the graphic file should be in the same directory as your .tex file. With a
command
\includegraphics{graphics/your_picture}
01/04/07
If the picture is too large or too small, you can scale it to the desired size with a width or
height parameter:
\includegraphics[height=.3in]{graphics/mouse}
You can also rotate a picture with an angle parameter, see Figure 4 which has been inserted
with
\includegraphics[width=.7in,angle=180]{graphics/mouse}
Fall 2012
ADDITIONAL TOPICS
In LaTEX, the term float indicates an object which can be relocated, e.g. to the top or bottom of
a page. LaTEX defines two float environments: the table- and the figure environment. It is
possible to define more. Table 1 on page 2 has been placed with the following code:
\begin{table}[b]
\begin{tabular}[t]{lrr}
...
\end{tabular}
\caption{Fewer rules are better}
\label{tab:rules}
\end{table}
Codes [t] [b] or [tb] are optional placement specifiers. They indicate preferred placement of
the float: at the bottom of the page (b), the top (t), here (h) or on a float page (p). Default:
[tbp].
Within both environments, a \caption command is defined. In the examples above, there is a
\label command after the \caption command for cross-referencing.
Placing floats where you want them can be a bit easier with some or all of the following commands in the preamble:
\setcounter{topnumber}{2}
\setcounter{bottomnumber}{2}
\setcounter{totalnumber}{3}
\setcounter{dbltopnumber}{2}
\renewcommand{\topfraction}{.9}
\renewcommand{\textfraction}{.1}
\renewcommand{\bottomfraction}{.75}
\renewcommand{\floatpagefraction}{.9}
\renewcommand{\dblfloatpagefraction}{.9}
\renewcommand{\dbltopfraction}{.9}
With these codes, LaTEX is more willing to put several floats on a single page and to devote a
larger portion of the page to floats without resorting to a dedicated float page.
3.1
Footnotes
Footnotes are another class of object that are placed out of order:
is the footnote.
A special case is a footnote attached to the title or author of an article. Note that the footnote
should be inside the title- or author parameter.
Presentations
Sample title
A.U. Thor
\title{Sample title\thanks{%
Supported by a grant}}
\author{A.U. Thor\thanks{%
And another grant}}
\maketitle
First line of regular text.\footnote{%
With a regular footnote.} And some more text.
by a grant
another grant
1 With a regular footnote.
And
3.2
sample_text.tex, a latex file to which you can add figures, tables and footnotes. You can
also try out the tweaks from section 5. You can use a text of your own if you prefer.
sample_text.pdf
4 Presentations
Currently, the most popular presentations package is Beamer, and that is the package that we
are going to discuss.
4.1
Alternatives
However, there are alternatives. For instance, if you have minimalistic tastes then you could
simply set up suitable page dimensions with the geometry package:
\usepackage[%
paperwidth=108mm,
paperheight=81mm,
width=88mm,
height=62mm,
top=9mm,
footskip=20pt]{geometry}
Some
discussion
points
4.2
Fall 2012
10
ADDITIONAL TOPICS
4.3
Despite the use of curly braces, the frame title is actually optional.
There are various ways to display a frame progressively. In Beamer terminology, these successive
stages are overlays. A simple way to create them is with the \pause command:
Short title
First
\begin{frame}{Points}
\begin{itemize}
\item Some
\pause
\item discussion
\pause
\item points
\end{itemize}
\end{frame}
Points
Some
discussion
points
4.4
Themes
Beamer uses themes to control different aspects of the presentation: layout, colors, headers and
footers, fonts. The manual shows examples of different themes such as the default theme (no
\usetheme command), Bergen, Madrid and CambridgeUS.
Instead of such a comprehensive theme you can also load component themes. Read Part III of
the manual for details.
4.5
Modes
Beamer makes it possible to combine an article and a presentation into a single source. There
is a \mode<thismode>{...} command to tell Beamer that the contents between braces only
applies to thismode, where thismode can be presentation or article.
4.6
4.7
Practice
Play around with mybeamer.tex from the zipfile and with the solution templates from the
Beamer documentation. Things to try:
Include graphics. Do not use a figure environment; just use an \includegraphics command and add little or no text to the frame
11
5.1
The left sample below is typeset without, the right one with this package:
On November 14, 1885, Senator & Mrs. Leland
Stanford called together at their San Francisco mansion the 24 prominent men who had been chosen as
the first trustees of The Leland Stanford Junior University.
They handed to the board the Founding Grant
of the University, which they had executed three days
before. This document with various amendments,
legislative acts, and court decrees remains as the
Universitys charter.
On November 14, 1885, Senator & Mrs. Leland Stanford called together at their San Francisco mansion
the 24 prominent men who had been chosen as the
first trustees of The Leland Stanford Junior University.
They handed to the board the Founding Grant of
the University, which they had executed three days
before. This document with various amendments,
legislative acts, and court decrees remains as the
Universitys charter.
This also takes care of vertical spacing of itemize- and enumerate environments. This is still
just a quick-and-dirty hack; for a professional result all measurements should be harmonized.
5.2
Double-spacing
This looks awful, but is often required for draft printouts. A line
\usepackage[doublespacing]{setspace}
or
\usepackage[onehalfspacing]{setspace}
5.3
ensures that displayed equations are not centered but left-aligned, with a fixed indentation from
the left. The left sample below has the default centered alignment of equations, the right one
has the option applied and has left-aligned equations:
ln
Q
L
= c0 +
0,T
IG
Q
+
(1)
0,T
5.4
ln
Q
L
= c0 +
0,T
IG
Q
+
(1)
0,T
ln C
C j
=
ln j
j C
(2)
Page dimensions
\usepackage[textwidth=10cm,textheight=17cm]{geometry}
There are a lot of options, also for page headers and -footers and for an asymmetric layout.
File-search for geometry with texdoctk.
Fall 2012
12
ADDITIONAL TOPICS
5.5
Font size
For a slightly larger font, use the 11pt- or 12pt document class option:
\documentclass[12pt]{article}
The default is 10pt. This only works for these predefined sizes. Anything else requires a lot
more coding.
5.6
Fonts
Several packages change the font for the entire document. However, good math fonts are in
short supply, so choices are limited if you want matching math typesetting. Check out A Survey of
Free Math Fonts for TEX and LaTEX (somewhat dated) and search for font in the CTAN Catalogue.
The typeset samples below have the required preamble commands on the left. Palatino:
ln
\usepackage[TS1,T1]{fontenc}
\usepackage{amsmath}
\usepackage{mathpazo}
Q
L
= c0 +
0,T
IG
Q
(1)
0,T
We expect official free math fonts for Times before the end of the year, as part of the TeX Gyre
font project. These will be included in TEX Live. For now, you can use e.g. the mathptmx package:
ln
\usepackage[TS1,T1]{fontenc}
\usepackage{amsmath}
\usepackage{mathptmx}
G
I
Q
= c0 +
+
L 0,T
Q 0,T
(1)
5.7
Q
L
= c0 +
0,T
IG
Q
(1)
0,T
13
Language support
displays this at the right end of the status bar at the bottom), or always write \e rather than .
And do not use the inputenc package.
Cambria. The Cambria font family is especially useful since it contains a full set of mathematical symbols. It is present on most Windows systems and is bundled with e.g. the free PowerPoint
viewer:
\usepackage{amsmath}
\usepackage{fontspec}
\usepackage{unicode-math}
\fontspec{Cambria}
\setmainfont{Cambria}
\setmathfont{Cambria Math}
ln ( ) = + ( ) +
,
,
(1)
6 Language support
This section is just to make you aware of LaTEXs support for non-english and multilingual typesetting. It contains no exercises.
6.1
Babel
TEX and LaTEX supports many languages, also within the same document. For LaTEX, language
support is provided by the Babel package. Its principal tasks are proper hyphenation and translation of text strings such as Table of Contents and Chapter.
For e.g. Dutch hyphenation and Dutch text strings, use the following code in the preamble:
\usepackage[dutch]{babel}
See e.g. section 2.5 in The Not So Short Introduction for more particulars.
6.2
. . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . (Calendar operations)
. . . . . . . . . . . . . . . . . . . . . . .
..
.
.
The Polyglossia package replaces Babel for XeTeX. At this moment, Polyglossia is not yet adapted
for LuaTeX, but this is hopefully a matter of time. In the meantime, use Babel.
Fall 2012
14
URL :
URL :
http://mirror.ctan.org/.
http://mirror.ctan.org/help/Catalogue/brief.html.
Dcolumn package (2001). Provides decimal and other alignment for tabular- and array environments, included in most TEX distributions.
Hartke, Stephen G. (2006). A Survey of Free Math Fonts for TEX and LaTEX. URL: http://mirror.
ctan.org/info/Free_Math_Font_Survey/en/.
Kroonenberg, Siep (2012). Figures in LaTEX. URL: http://tex.aanhet.net/rugtex/figlatex.
pdf.
Oetiker, Tobias et al. (2011). The Not So Short Introduction to LaTEX2" . Included in most free TEX
distributions. URL: http://mirror.ctan.org/info/lshort/.
Tantau, Till, Joseph Wright, and Vedran Miletic (2011). The BEAMER class. Published as part of
the beamer package.
TeX Gyre font project.
URL :
http://www.gust.org.pl/projects/e-foundry/tex-gyre/.
Siep Kroonenberg
N dot S dot Kroonenberg at rug dot nl