The Not So Short Introduction To LaTeX2e
The Not So Short Introduction To LaTeX2e
Introduction to LATEX 2ε
Or LATEX 2ε in 90 minutes
by Tobias Oetiker
Hubert Partl, Irene Hyna and Elisabeth Schlegl
Copyright
2000
c Tobias Oetiker and all the Contributers to LShort. All rights
reserved.
This document is free; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
This document is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License along with
this document; if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA.
Thank you!
LATEX [1] is a typesetting system which is very suitable for producing scien-
tific and mathematical documents of high typographical quality. The system
is also suitable for producing all sorts of other documents, from simple letters
to complete books. LATEX uses TEX [2] as its formatting engine.
This short introduction describes LATEX 2ε and should be sufficient for
most applications of LATEX. Refer to [1, 3] for a complete description of the
LATEX system.
LATEX is available for most computers, from the PC and Mac to large
UNIX and VMS systems. On many university computer clusters, you will
find that a LATEX installation is available, ready to use. Information on
how to access the local LATEX installation should be provided in the Local
Guide [4]. If you have problems getting started, ask the person who gave
you this booklet. The scope of this document is not to tell you how to install
and set up a LATEX system, but to teach you how to write your documents
so that they can be processed by LATEX.
This Introduction is split into 5 chapters:
Chapter 1 tells you about the basic structure of LATEX 2ε documents. You
will also learn a bit about the history of LATEX. After reading this
chapter, you should have a rough picture of LATEX. The picture will
only be a framework, but it will enable you to integrate the information
provided in the other chapters into the big picture.
If you need to get hold of any LATEX related material, have a look in one of
the Comprehensive TEX Archive Network (CTAN) ftp archives. They can be
found e.g. at ctan.tug.org (US), ftp.dante.de (Germany), ftp.tex.ac.uk
(UK). If you are not in one of these countries, choose the archive closest to
you.
If you want to run LATEX on your own computer, take a look at what is
available from CTAN:/tex-archive/systems.
Preface v
2 Typesetting Text 15
2.1 The Structure of Text and Language . . . . . . . . . . . . . . 15
2.2 Linebreaking and Pagebreaking . . . . . . . . . . . . . . . . . 17
2.2.1 Justified Paragraphs . . . . . . . . . . . . . . . . . . . 17
2.2.2 Hyphenation . . . . . . . . . . . . . . . . . . . . . . . 18
2.3 Ready made Strings . . . . . . . . . . . . . . . . . . . . . . . 19
2.4 Special Characters and Symbols . . . . . . . . . . . . . . . . . 19
2.4.1 Quotation Marks . . . . . . . . . . . . . . . . . . . . . 19
viii CONTENTS
4 Specialities 55
4.1 Including EPS Graphics . . . . . . . . . . . . . . . . . . . . . 55
4.2 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.3 Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.4 Fancy Headers . . . . . . . . . . . . . . . . . . . . . . . . . . 59
4.5 The Verbatim Package . . . . . . . . . . . . . . . . . . . . . . 60
4.6 Protecting fragile commands . . . . . . . . . . . . . . . . . . 61
5 Customising LATEX 63
5.1 New Commands, Environments and Packages . . . . . . . . . 63
5.1.1 New Commands . . . . . . . . . . . . . . . . . . . . . 64
5.1.2 New Environments . . . . . . . . . . . . . . . . . . . . 65
5.1.3 Your own Package . . . . . . . . . . . . . . . . . . . . 65
CONTENTS ix
Bibliography 79
List of Figures
5.1 Fonts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.2 Font Sizes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.3 Absolute Point Sizes in Standard Classes. . . . . . . . . . . . 68
5.4 Math Fonts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
5.5 TEX Units. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Chapter 1
In the first part of this chapter, you will get a short overview about the philosophy
and history of LATEX 2ε . The second part of the chapter focuses on the basic
structures of a LATEX document. After reading this chapter, you should have a
rough knowledge of how LATEX works. When reading on, this will help you to
integrate all the new information into the big picture.
1.1.2 LATEX
LATEX is a macro package which enables authors to typeset and print their
work at the highest typographical quality, using a predefined, professional
layout. LATEX was originally written by Leslie Lamport [1]. It uses the TEX
formatter as its typesetting engine.
2 Things You Need to Know
copy
...
? ispell
emacs
editor
6
?
.mf .tex
...
AMS-Package
? ? LATEX 2ε
Plain
METAfont - .tfm - TEX - .log
? ?
.pk .dvi
. .
.
? xdvi
- driver dvips
- printer
screen
PostScript 6
Fonts - Typesetting -
In 1994 the LATEX package was updated by the LATEX3 team, led by Frank
Mittelbach, to include some long-requested improvements, and to reunify all
the patched versions which had cropped up since the release of LATEX 2.09
some years earlier. To distinguish the new version from the old, it is called
LATEX 2ε . This documentation deals with LATEX 2ε .
LATEX is pronounced “Lay-tech” or “Lah-tech.” If you refer to LATEX in
an ASCII environment, you type LaTeX. LATEX 2ε is pronounced “Lay-tech
two e” and typed LaTeX2e.
Figure 1.1 above shows how TEX and LATEX 2ε work together. This figure
is taken from wots.tex by Kees van der Laan.
1.2 Basics
1.2.1 Author, Book Designer, and Typesetter
To publish something, authors give their typed manuscript to a publishing
company. One of their book designers then decides the layout of the docu-
ment (column width, fonts, space before and after headings, . . . ). The book
1.2 Basics 3
designer writes his instructions into the manuscript and then gives it to a
typesetter, who typesets the book according to these instructions.
A human book designer tries to find out what the author had in mind
while writing the manuscript. He decides on chapter headings, citations,
examples, formulae, etc. based on his professional knowledge and from the
contents of the manuscript.
In a LATEX environment, LATEX takes the role of the book designer and
uses TEX as its typesetter. But LATEX is “only” a program and therefore
needs more guidance. The author has to provide additional information
which describes the logical structure of his work. This information is written
into the text as “LATEX commands.”
This is quite different from the WYSIWYG1 approach which most mod-
ern word processors such as MS Word or Corel WordPerfect take. With
these applications, authors specify the document layout interactively while
typing text into the computer. All along the way, they can see on the screen
how the final work will look when it is printed.
When using LATEX it is normally not possible to see the final output
while typing the text. But the final output can be previewed on the screen
after processing the file with LATEX. Then corrections can be made before
actually sending the document to the printer.
opposite. The best thing you can do when such a discussion starts is to keep
a low profile, since such discussions often get out of hand. But sometimes
you cannot escape . . .
So here is some ammunition. The main advantages of LATEX over normal
word processors are the following:
• Free add-on packages exist for many typographical tasks not directly
supported by basic LATEX. For example, packages are available to
include PostScript graphics or to typeset bibliographies conforming
to exact standards. Many of these add-on packages are described in
The LATEX Companion [3].
LATEX also has some disadvantages, and I guess it’s a bit difficult for me to
find any sensible ones, though I am sure other people can tell you hundreds
;-)
• LATEX does not work well for people who have sold their souls . . .
1.3.1 Spaces
“Whitespace” characters such as blank or tab are treated uniformly as
“space” by LATEX. Several consecutive whitespace characters are treated
as one “space”. Whitespace at the start of a line is generally ignored, and
a single linebreak is treated as “whitespace”.
An empty line between two lines of text defines the end of a paragraph.
Several empty lines are treated the same as one empty line. The text below
is an example. On the left hand side is the text from the input file, and on
the right hand side is the formatted output.
$ & % # _ { } ~ ^ \
As you will see, these characters can be used in your documents all the
same by adding a prefix backslash:
\$ \& \% \# \_ \{ \} $&%# {}
The other symbols and many more can be printed with special commands
in mathematical formulae or as accents. The backslash character \ can not
be entered by adding another backslash in front of it (\\), this sequence is
used for linebreaking.3
3
Try the $\backslash$ command instead. It produces a ‘\’.
6 Things You Need to Know
1.3.4 Comments
When LATEX encounters a % character while processing an input file, it ig-
nores the rest of the present line, the linebreak, and all whitespace at the
beginning of the next line.
This can be used to write notes into the input file, which will not show
up in the printed version.
This is an % stupid
% Better: instructive <----
example: Supercal% This is an example: Supercalifragilisticexpi-
ifragilist% alidocious
icexpialidocious
1.4 Input File Structure 7
The % character can also be used to split long input lines where no
whitespace or linebreaks are allowed.
For longer comments you should use the comment environment provided
by the verbatim package.
This is another
\begin{comment}
rather stupid, This is another example for embedding com-
but helpful ments in your document.
\end{comment}
example for embedding comments in your document.
\documentclass{...}
This specifies what sort of document you intend to write. After that, you
can include commands which influence the style of the whole document, or
you can load packages which add new features to the LATEX system. To load
such a package you use the command
\usepackage{...}
When all the setup work is done,4 you start the body of the text with
the command
\begin{document}
Now you enter the text mixed with some useful LATEX commands. At
the end of the document you add the
\end{document}
command, which tells LATEX to call it a day. Anything which follows this
command will be ignored by LATEX.
Figure 1.2 shows the contents of a minimal LATEX 2ε file. A slightly more
complicated input file is given in Figure 1.3.
4
The area between \documentclass and \begin{document} is called preamble.
8 Things You Need to Know
\documentclass{article}
\begin{document}
Small is beautiful.
\end{document}
\documentclass[a4paper,11pt]{article}
\usepackage{latexsym}
\author{H.~Partl}
\title{Minimalism}
\frenchspacing
\begin{document}
\maketitle
\tableofcontents
\section{Start}
Well, and here begins my lovely article.
\section{End}
\ldots{} and here it ends.
\end{document}
\documentclass[options]{class}
Here class specifies the type of document to be created. Table 1.1 lists the
document classes explained in this introduction. The LATEX 2ε distribution
provides additional classes for other documents, including letters and slides.
The options parameter customises the behaviour of the document class. The
options have to be separated by commas. The most common options for the
standard document classes are listed in Table 1.2.
Example: An input file for a LATEX document could start with the line
\documentclass[11pt,twoside,a4paper]{article}
1.5.2 Packages
While writing your document, you will probably find that there are some
areas where basic LATEX cannot solve your problem. If you want to include
graphics, coloured text or source code from a file into your document, you
report for longer reports containing several chapters, small books, PhD
theses, . . .
slides for slides. The class uses big sans serif letters. You might want
to consider using FoilTEXa instead.
a
CTAN:/tex-archive/macros/latex/contrib/supported/foiltex
10 Things You Need to Know
10pt, 11pt, 12pt Sets the size of the main font in the document. If
no option is specified, 10pt is assumed.
\usepackage[options]{package}
command where package is the name of the package and options is a list of
keywords which trigger special features in the package. Some packages come
with the LATEX 2ε base distribution (See Table 1.3). Others are provided
separately. You may find more information on the packages installed at your
site in your Local Guide [4]. The prime source for information about LATEX
packages is The LATEX Companion [3]. It contains descriptions of hundreds
of packages along with information of how to write your own extensions to
LATEX 2ε .
.sty LATEX Macro package. This is a file you can load into your LATEX
document using the \usepackage command.
.dtx Documented TEX. This is the main distribution format for LATEX style
files. If you process a .dtx file you get documented macro code of the
LATEX package contained in the .dtx file.
.ins Is the installer for the files contained in the matching .dtx file. If you
download a LATEX package from the net, you will normally get a .dtx
and a .ins file. Run LATEX on the .ins file to unpack the .dtx file.
.cls Class files define what your document looks like. They are selected
with the \documentclass command.
The following files are generated when you run LATEX on your input file:
.dvi Device Independent file. This is the main result of a LATEX compile
run. You can look at its content with a DVI previewer program or you
can send it to a printer with dvips or a similar application.
.log Gives a detailed account of what happened during the last compiler
run.
12 Things You Need to Know
latexsym To access the LATEX symbol font, you should use the
latexsym package. Described in latexsym.dtx and in The
LATEX Companion [3].
a
This file should be installed on your system, and you should be able to
get a dvi file by typing latex doc.dtx in any directory where you have write
permission. The same is true for all the other files mentioned in this table.
1.6 Files you might encounter 13
.toc Stores all your section headers. It gets read in for the next compiler
run and is used to produce the table of content.
.lof This is like .toc but for the list of figures.
.lot And again the same for the list of tables.
.aux Another file which transports information from one compiler run to
the next. Among other things, the .aux file is used to store information
associated with crossreferences.
.idx If your document contains an index. LATEX stores all the words which
go into the index in this file. This file must be processed with makeindex.
Refer to section 4.3 on page 58 for more information on indexing.
.ind Is the processed .idx file, ready for inclusion into your document on
the next compile cycle.
.ilg Logfile telling about what makeindex did.
\pagestyle{style}
command defines which one to use. Table 1.4 lists the predefined page styles.
plain prints the page numbers on the bottom of the page, in the middle
of the footer. This is the default page style.
headings prints the current chapter heading and the page number in
the header on each page, while the footer remains empty. (This is
the style used in this document)
It is possible to change the page style of the current page with the com-
mand
\thispagestyle{style}
A description how to create your own headers and footers can be found
14 Things You Need to Know
\include{filename}
you can use this command in the document body to insert the contents
of another file named filename.tex. Note that LATEX will start a new page
before processing the material input from filename.tex.
The second command can be used in the preamble. It allows you to
instruct LATEX to only input some of the \included files.
\includeonly{filename,filename,. . . }
\input{filename}
\usepackage{syntonly}
\syntaxonly
When you want to produce pages, just comment out the second line (by
adding a percent sign)
Chapter 2
Typesetting Text
After reading the previous chapter, you should know about the basic stuff of
which a LATEX 2ε document is made. In this chapter I will fill in the remaining
structure you will need to know in order to produce real world material.
% Example 1
\ldots when Einstein introduced his formula
\begin{equation}
e = m \cdot c^2 \; ,
\end{equation}
which is at the same time the most widely known
and the least well understood physical formula.
% Example 2
\ldots from which follows Kirchoff’s current law:
\begin{equation}
\sum_{k=1}^{n} I_k = 0 \; .
\end{equation}
% Example 3
\ldots which has several advantages.
\begin{equation}
I_D = I_F - I_R
\end{equation}
is the core of a very different transistor model. \ldots
take a short breath at every comma. If this feels awkward at some place,
delete that comma, if you feel the urge to breathe (or make a short stop) at
some other place, insert a comma.
Finally, the paragraphs of a text should also be structured logically at a
higher level, by putting them into chapters, sections, subsections, and so on.
However, the typographical effect of writing e.g. \section{The Structure
of Text and Language} is so obvious that it is almost self-evident how
these high-level structures should be used.
\\ or \newline
\\*
\newpage
do what their names say. They enable the author to influence their actions
with the optional argument n. It can be set to a number between zero
to four. By setting n to a value below 4 you leave LATEX the option of
ignoring your command if the result would look very bad. Do not confuse
these “break” commands with the “new” commands. Even when you give
a “break” command, LATEX still tries to even out the right border of the
page and the total length of the page as described in the next section. If
18 Typesetting Text
you really want to start a “new line”, then use the corresponding command.
Guess its name!
LATEX always tries to produce the best linebreaks possible. If it cannot
find a way to break the lines in a manner which meets its high standards, it
lets one line stick out on the right of the paragraph. LATEX then complains
(“overfull hbox”) while processing the input file. This happens most often
when LATEX cannot find a suitable place to hyphenate a word.2 You can in-
struct LATEX to lower its standards a little by giving the \sloppy command.
It prevents such over-long lines by increasing the inter-word spacing — even
if the final output is not optimal. In this case a warning (“underfull hbox”)
is given to the user. In most such cases the result doesn’t look very good.
The command \fussy brings LATEX back to its default behaviour.
2.2.2 Hyphenation
LATEX hyphenates words whenever necessary. If the hyphenation algorithm
does not find the correct hyphenation points, you can remedy the situation
by using the following commands to tell TEX about the exception.
The command
\hyphenation{word list}
causes the words listed in the argument to be hyphenated only at the points
marked by “-”. The argument of the command should only contain words
built from normal letters or rather signes which are regarded as normal let-
ters in the active context. The hyphenation hints are stored for the language
which is active when the hyphenation command occurs. This means that if
you place a hyphenation command into the preamble of your document it
will influence the english language hyphenation. If you place the command
after the \begin{document} and you are using some package for national
language support like babel, then the hyphenation hints will be active in the
language activated through babel.
The example below will allow “hyphenation” to be hyphenated as well
as “Hyphenation”, and it prevents “FORTRAN”, “Fortran” and “fortran”
from being hyphenated at all. No special characters or symbols are allowed
in the argument.
Example:
\hyphenation{FORTRAN Hy-phen-a-tion}
Several words can be kept together on one line with the command
\mbox{text}
‘‘Please press the ‘x’ key.’’ “Please press the ‘x’ key.”
20 Typesetting Text
The names for these dashes are: ‘-’ hyphen, ‘–’ en-dash, ‘—’ em-dash
and ‘−’ minus sign.
http://www.rich.edu/\~{}bush \\ http://www.rich.edu/˜bush
http://www.clever.edu/$\sim$demo http://www.clever.edu/∼demo
2.4.4 Ellipsis ( . . . )
On a typewriter a comma or a period takes the same amount of space as
any other letter. In book printing these characters occupy only a little space
and are set very close to the preceding letter. Therefore you cannot enter
‘ellipsis’ by just typing three dots, as the spacing would be wrong. Besides
that there is a special command for these dots. It is called
\ldots
Not like this ... but like this:\\ Not like this ... but like this:
New York, Tokyo, Budapest, \ldots New York, Tokyo, Budapest, . . .
2.4.5 Ligatures
Some letter combinations are typeset not just by setting the different letters
one after the other, but by actually using special symbols.
2.5 International Language Support 21
2. LATEX needs to know the hyphenation rules for the new language.
Getting hyphenation rules into LATEX is a bit more tricky. It means
rebuilding the format file with different hyphenation patterns enabled.
Your Local Guide [4] should give more information on this.
\usepackage[language]{babel}
\usepackage[T1]{fontenc}
Mr.~Smith was happy to see her\\ Mr. Smith was happy to see her
cf.~Fig.~5\\ cf. Fig. 5
I like BASIC\@. What about you? I like BASIC. What about you?
The additional space after periods can be disabled with the command
\frenchspacing
which tells LATEX not to insert more space after a period than after ordinary
character. This is very common in non-English languages, except bibliogra-
phies. If you use \frenchspacing, the command \@ is not necessary.
\section{...} \paragraph{...}
\subsection{...} \subparagraph{...}
\subsubsection{...} \appendix
You can use two additional sectioning commands for the report and the
book class:
\part{...} \chapter{...}
As the article class does not know about chapters, it is quite easy
to add articles as chapters to a book. The spacing between sections, the
numbering and the font size of the titles will be set automatically by LATEX.
Two of the sectioning commands are a bit special:
LATEX creates a table of contents by taking the section headings and page
numbers from the last compile cycle of the document. The command
\tableofcontents
\maketitle
They are useful for dividing your publication. The commands alter chap-
ter headings and page numbering to work as you would expect it in a book.
5
Note that these commands are not aware of what they refer to. \label just saves the
last automatically generated number.
26 Typesetting Text
2.9 Footnotes
With the command
\footnote{footnote text}
a footnote is printed at the foot of the current page. Footnotes should always
be put6 after the word or sentence they refer to.7
\emph{text}
to emphasize text. What the command actually does with its argument
depends on the context:
2.11 Environments
\begin{aaa}...\begin{bbb}...\end{bbb}...\end{aaa}
\flushleft
\begin{enumerate}
\item You can mix the list
environments to your taste: 1. You can mix the list environments to
\begin{itemize} your taste:
\item But it might start to
look silly. • But it might start to look silly.
\item[-] With a dash. - With a dash.
\end{itemize}
\item Therefore remember: 2. Therefore remember:
\begin{description}
Stupid things will not become smart
\item[Stupid] things will not
because they are in a list.
become smart because they are
in a list. Smart things, though, can be
\item[Smart] things, though, can be presented beautifully in a list.
presented beautifully in a list.
\end{description}
\end{enumerate}
\begin{flushleft}
This text is\\ left-aligned. This text is
\LaTeX{} is not trying to make left-aligned. LATEX is not trying to make
each line the same length. each line the same length.
\end{flushleft}
\begin{flushright}
This text is right-\\aligned. This text is right-
\LaTeX{} is not trying to make aligned. LATEX is not trying to make each
each line the same length. line the same length.
\end{flushright}
\begin{center}
At the centre
At the centre\\of the earth
of the earth
\end{center}
The quote environment is useful for quotes, important phrases and exam-
ples.
There are two similar environments: the quotation and the verse en-
vironments. The quotation environment is useful for longer quotes going
over several paragraphs, because it does indent paragraphs. The verse en-
vironment is useful for poems where the line breaks are important. The
lines are separated by issuing a \\ at the end of a line and a empty line after
each verse.
2.11 Environments 29
\verb+text+
The + is just an example of a delimiter character. You can use any character
except letters, * or space. Many LATEX examples in this booklet are typeset
with this command.
The \verb|\ldots| command \ldots
The \ldots command . . .
\begin{verbatim}
10 PRINT "HELLO WORLD "; 10 PRINT "HELLO WORLD ";
20 GOTO 10 20 GOTO 10
\end{verbatim}
\begin{verbatim*}
the starred version of the starred version of
the verbatim the verbatim
environment emphasizes environment emphasizes
the spaces in the text the spaces in the text
\end{verbatim*}
The verbatim environment and the \verb command may not be used
within parameters of other commands.
30 Typesetting Text
2.11.5 Tabular
The tabular environment can be used to typeset beautiful tables with
optional horizontal and vertical lines. LATEX determines the width of the
columns automatically.
The table spec argument of the
\begin{tabular}{table spec}
command defines the format of the table. Use an l for a column of left-
aligned text, r for right-aligned text, and c for centred text; p{width} for a
column containing justified text with linebreaks, and | for a vertical line.
Within a tabular environment, & jumps to the next column, \\ starts
a new line and \hline inserts a horizontal line.
\begin{tabular}{|r|l|}
\hline
7C0 & hexadecimal \\ 7C0 hexadecimal
3700 & octal \\ 3700 octal
11111000000 & binary \\ 11111000000 binary
\hline \hline
1984 decimal
1984 & decimal \\
\hline
\end{tabular}
\begin{tabular}{|p{4.7cm}|}
\hline
Welcome to Boxy’s paragraph. Welcome to Boxy’s paragraph.
We sincerely hope you’ll We sincerely hope you’ll all en-
all enjoy the show.\\ joy the show.
\hline
\end{tabular}
The column separator can be specified with the @{...} construct. This
command kills the inter-column space and replaces it with whatever is be-
tween the curly braces. One common use for this command is explained
below in the decimal alignment problem. Another possible application is to
suppress leading space in a table with @{}.
\begin{tabular}{@{} l @{}}
\hline
no leading space\\ no leading space
\hline
\end{tabular}
2.12 Floating Bodies 31
\begin{tabular}{l}
\hline
leading space left and right\\ leading space left and right
\hline
\end{tabular}
\begin{tabular}{c r @{.} l}
Pi expression &
\multicolumn{2}{c}{Value} \\ Pi expression Value
\hline π 3.1416
$\pi$ & 3&1416 \\ ππ 36.46
$\pi^{\pi}$ & 36&46 \\ (π π )π 80662.7
$(\pi^{\pi})^{\pi}$ & 80662&7 \\
\end{tabular}
\begin{tabular}{|c|c|}
\hline
\multicolumn{2}{|c|}{\textbf{Ene}} \\
Ene
\hline
Mene Muh!
Mene & Muh! \\
\hline
\end{tabular}
Let’s first have a look at the commands LATEX supplies for floats:
Any material enclosed in a figure or table environment will be treated
as floating matter. Both float environments support an optional parameter
called the placement specifier. This parameter is used to tell LATEX about the
locations to which the float is allowed to be moved. A placement specifier is
constructed by building a string of float-placing permissions. See Table 2.2.
Note: The 0pt and 1.05em are TEX units. Read more on this in table
5.5 on page 72.
A table could be started with the following line e.g.
\begin{table}[!hbp]
The placement specifier [!hbp] allows LATEX to place the table right here
(h) or at the bottom (b) of some page or on a special floats page (p), and
all this even if it does not look that good (!). If no placement specifier is
given, the standard classes assume [tbp].
LATEX will place every float it encounters, according to the placement
specifier supplied by the author. If a float cannot be placed on the current
page it is deferred either to the figures or the tables queue9 . When a new
page is started, LATEX first checks if it is possible to fill a special ‘float’
page with floats from the queues. If this is not possible, the first float on
each queue is treated as if it had just occurred in the text: LATEX tries
again to place it according to its respective placement specifiers (except ‘h’
9
These are fifo - ‘first in first out’ queues!
which is no longer possible). Any new floats occurring in the text get placed
into the appropriate queues. LATEX strictly maintains the original order of
appearance for each type of float. That’s why a figure which cannot be
placed pushes all further figures to the end of the document. Therefore:
Having explained the difficult bit, there are some more things to mention
about the table and figure environments. With the
\caption{caption text}
command, you can define a caption for the float. A running number and
the string “Figure” or “Table” will be added by LATEX.
The two commands
\caption[Short]{LLLLLoooooonnnnnggggg}
With \label and \ref, you can create a reference to a float within your
text.
The following example draws a square and inserts it into the document.
You could use this if you wanted to reserve space for images you are going
to paste into the finished document.
In the example above, LATEX will try really hard (!) to place the figure
right here (h).10 If this is not possible, it tries to place the figure at the
bottom (b) of the page. Failing to place the figure on the current page,
it determines whether it is possible to create a float page containing this
10
assuming the figure queue is empty.
34 Typesetting Text
figure and maybe some tables from the tables queue. If there is not enough
material for a special float page, LATEX starts a new page, and once more
treats the figure as if it had just occurred in the text.
Under certain circumstances it might be necessary to use the
Typesetting Mathematical
Formulae
Now you are ready! In this chapter, we will attack the main strength of TEX:
mathematical typesetting. But be warned, this chapter only scratches the sur-
face. While the things explained here are sufficient for many people, don’t
despair if you can’t find a solution to your mathematical typesetting needs here.
It is highly likely that your problem is addressed in AMS-LATEX1 or some other
package.
3.1 General
LATEX has a special mode for typesetting mathematics. Mathematical text
within a paragraph is entered between \( and \), between $ and $ or between
\begin{math} and \end{math}.
\begin{equation} \label{eq:eps}
\epsilon > 0
\end{equation} >0 (3.1)
From (\ref{eq:eps}), we gather From (3.1), we gather . . .
\ldots
\begin{displaymath}
\lim_{n \to \infty} n
X 1 π2
\sum_{k=1}^n \frac{1}{k^2} lim =
n→∞ k2 6
= \frac{\pi^2}{6} k=1
\end{displaymath}
There are differences between math mode and text mode. For example
in math mode:
1. Most spaces and linebreaks do not have any significance, as all spaces
either are derived logically from the mathematical expressions or have
to be specified using special commands such as \,, \quad or \qquad.
2. Empty lines are not allowed. Only one paragraph per formula.
\begin{equation}
\forall x \in \mathbf{R}:
\qquad x^{2} \geq 0 ∀x ∈ R : x2 ≥ 0 (3.2)
\end{equation}
\begin{equation}
x^{2} \geq 0\qquad
\textrm{for all }x\in\mathbf{R} x2 ≥ 0 for all x ∈ R (3.3)
\end{equation}
\begin{displaymath}
x^{2} \geq 0\qquad
\textrm{for all }x\in\mathbb{R} x2 ≥ 0 for all x ∈ R
\end{displaymath}
\begin{equation}
a^x+y \neq a^{x+y} ax + y 6= ax+y (3.4)
\end{equation}
$\lambda,\xi,\pi,\mu,\Phi,\Omega$ λ, ξ, π, µ, Φ, Ω
2
There is no uppercase Alpha defined in LATEX 2ε because it looks the same as a normal
roman A. Once the new math coding is done, things will change.
38 Typesetting Mathematical Formulae
The square root is entered as \sqrt, the nth root is generated with
\sqrt[n]. The size of the root sign is determined automatically by LATEX.
If just the sign is needed, use \surd.
$\sqrt{x}$ \qquad √ √
p √ 3
$\sqrt{ x^{2}+\sqrt{y} }$ x x2 + y 2
\qquad $\sqrt[3]{2}$\\[3pt] √ 2
[x + y 2 ]
$\surd[x^2 + y^2]$
$\overline{m+n}$ m+n
a + b + ··· + z
$\underbrace{ a+b+\cdots+z }_{26}$ | {z }
26
\begin{displaymath}
y=x^{2}\qquad y’=2x\qquad y’’=2 y = x2 y 0 = 2x y 00 = 2
\end{displaymath}
Names of log-like functions are often typeset in an upright font and not
in italic like variables. Therefore LATEX supplies the following commands to
typeset the most important function names:
\arccos \cos \csc \exp \ker \limsup \min \sinh
\arcsin \cosh \deg \gcd \lg \ln \Pr \sup
\arctan \cot \det \hom \lim \log \sec \tan
\arg \coth \dim \inf \liminf \max \sin \tanh
For the modulo function, there are two commands: \bmod for the binary
operator “a mod b” and \pmod for expressions such as “x ≡ a (mod b).”
A built-up fraction is typeset with the \frac{...}{...} command.
Often the slashed form 1/2 is preferable, because it looks better for small
amounts of ‘fraction material.’
$1\frac{1}{2}$~hours
\begin{displaymath} 1 12 hours
\frac{ x^{2} }{ k+1 }\qquad
x^{ \frac{2}{k+1} }\qquad x2 2
x k+1 x1/2
x^{ 1/2 } k+1
\end{displaymath}
\begin{displaymath}
n x
{n \choose k}\qquad {x \atop y+2}
\end{displaymath} k y+2
For binary relations it may be useful to stack symbols over each other.
\stackrel puts the symbol given in the first argument in superscript-like
size over the second which is set in its usual position.
40 Typesetting Mathematical Formulae
\begin{displaymath} Z
!
\int f_N(x) \stackrel{!}{=} 1 fN (x) = 1
\end{displaymath}
The integral operator is generated with \int, the sum operator with
\sum and the product operator with \prod. The upper and lower limits
are specified with ^ and _ like subscripts and superscripts. 3
\begin{displaymath}
\sum_{i=1}^{n} \qquad n
X Z π
2 Y
\int_{0}^{\frac{\pi}{2}} \qquad
\prod_\epsilon i=1 0
\end{displaymath}
For braces and other delimiters, there exist all types of symbols in
TEX (e.g. [ h k l). Round and square braces can be entered with the
corresponding keys, curly braces with \{, all other delimiters are generated
with special commands (e.g. \updownarrow). For a list of all delimiters
available, check table 3.8 on page 49.
\begin{displaymath}
{a,b,c}\neq\{a,b,c\} a, b, c 6= {a, b, c}
\end{displaymath}
\begin{displaymath}
3
1 + \left( \frac{1}{ 1-x^{2} } 1
\right) ^3 1+
1 − x2
\end{displaymath}
2
$\Big( (x+1) (x-1) \Big) ^{2}$\\ (x + 1)(x − 1)
$\big(\Big(\bigg(\Bigg($\quad )
o
$\big\}\Big\}\bigg\}\Bigg\}$\quad
$\big\|\Big\|\bigg\|\Bigg\|$
To enter three dots into a formula, you can use several commands.
\ldots typesets the dots on the baseline, \cdots sets them centred. Besides
that, there are the commands \vdots for vertical and \ddots for diagonal
dots. You can find another example in section 3.5.
\begin{displaymath}
x_{1},\ldots,x_{n} \qquad
x_{1}+\cdots+x_{n} x1 , . . . , xn x1 + · · · + xn
\end{displaymath}
\newcommand{\ud}{\mathrm{d}}
\begin{displaymath} ZZ
\int\!\!\!\int_{D} g(x,y) g(x, y) dx dy
\, \ud x\, \ud y D
\end{displaymath} instead of
instead of Z Z
\begin{displaymath} g(x, y)dxdy
\int\int_{D} g(x,y)\ud x \ud y D
\end{displaymath}
\newcommand{\ud}{\mathrm{d}} ZZ
\begin{displaymath}
dx dy
\iint_{D} \, \ud x \, \ud y D
\end{displaymath}
42 Typesetting Mathematical Formulae
\begin{displaymath}
\mathbf{X} =
\left( \begin{array}{ccc}
x11 x12 ...
x_{11} & x_{12} & \ldots \\ x21 x22 ...
X=
x_{21} & x_{22} & \ldots \\ .. .. ..
\vdots & \vdots & \ddots . . .
\end{array} \right)
\end{displaymath}
\begin{displaymath}
y = \left\{ \begin{array}{ll}
a & \textrm{if $d>c$}\\ a if d > c
b+x & \textrm{in the morning}\\ y= b + x in the morning
l & \textrm{all day long} l all day long
\end{array} \right.
\end{displaymath}
As within the tabular environment you can also draw lines in the array
environent, e.g. separating the entries of a matrix:
\begin{displaymath}
\left(\begin{array}{c|c}
1 & 2 \\
1 2
\hline
3 4
3 & 4
\end{array}\right)
\end{displaymath}
For formulae running over several lines or for equation systems, you can
use the environments eqnarray, and eqnarray* instead of equation. In
eqnarray each line gets an equation number. The eqnarray* does not
number anything.
The eqnarray and the eqnarray* environments work like a 3-column
table of the form {rcl}, where the middle column can be used for the equal
sign or the not-equal sign. Or any other sign you see fit. The \\ command
breaks the lines.
3.6 Phantom 43
\begin{eqnarray}
f(x) & = & \cos x \\ f (x) = cos x (3.5)
f’(x) & = & -\sin x \\
\int_{0}^{x} f(y)dy & f 0 (x) = − sin x (3.6)
Z x
= & \sin x f (y)dy = sin x (3.7)
\end{eqnarray} 0
Notice that the space on either side of the the equal signs is rather large. It
can be reduced by setting \setlength\arraycolsep{2pt}, as in the next
example.
Long equations will not be automatically divided into neat bits. The
author has to specify where to break them and how much to indent. The
following two methods are the most common ones used to achieve this.
{\setlength\arraycolsep{2pt}
\begin{eqnarray} x3 x5
\sin x & = & x -\frac{x^{3}}{3!} sin x = x − + −
3! 5!
+\frac{x^{5}}{5!}-{} 7
x
\nonumber\\ − + ··· (3.8)
& & {}-\frac{x^{7}}{7!}+{}\cdots 7!
\end{eqnarray}}
\begin{eqnarray}
\lefteqn{ \cos x = 1
-\frac{x^{2}}{2!} +{} } x2
cos x = 1 − +
\nonumber\\ 2!
& & {}+\frac{x^{4}}{4!} x4 x6
-\frac{x^{6}}{6!}+{}\cdots + − + ··· (3.9)
4! 6!
\end{eqnarray}
The \nonumber command causes LATEX to not generate a number for this
equation.
It can be difficult to get vertically aligned equations to look right with
these methods; the package amsmath provides a more powerful set of alter-
natives. (see split and align environments).
3.6 Phantom
We can’t see phantoms, but they still occupy some space in the minds of a
lot of people. LATEX is no different. We can use this for some interesting
spacing tricks.
When vertically aligning text using ^ and _ LATEX sometimes is just a
little bit too helpful. Using the \phantom command you can reserve space
for characters which do not show up in the final output. Best is to look at
the following examples.
44 Typesetting Mathematical Formulae
\begin{displaymath}
{}^{12}_{\phantom{1}6}\textrm{C}
\qquad \textrm{as opposed to} \qquad 12 12
6C as opposed to 6 C
{}^{12}_{6}\textrm{C}
\end{displaymath}
\begin{displaymath}
\Gamma_{ij}^{\phantom{ij}k}
\qquad \textrm{as opposed to} \qquad Γij k as opposed to Γkij
\Gamma_{ij}^{k}
\end{displaymath}
\begin{equation}
2^{\textrm{nd}} \quad
2^{\mathrm{nd}} 2nd 2nd (3.10)
\end{equation}
Nevertheless, sometimes you need to tell LATEX the correct font size. In
math mode, the fontsize is set with the four commands:
\begin{displaymath}
\mathop{\mathrm{corr}}(X,Y)=
\frac{\displaystyle
n
\sum_{i=1}^n(x_i-\overline x) X
(xi − x)(yi − y)
(y_i-\overline y)}
i=1
{\displaystyle\biggl[ corr(X, Y ) = n n 1/2
X X
\sum_{i=1}^n(x_i-\overline x)^2 (xi − x) 2
(yi − y) 2
\sum_{i=1}^n(y_i-\overline y)^2 i=1 i=1
\biggr]^{1/2}}
\end{displaymath}
5
The AMS-LATEX package makes the \textrm command work with size changing.
3.8 Theorems, Laws, . . . 45
This is one of those examples in which we need larger brackets than the
standard \left[ \right] provides.
\newtheorem{name}[counter ]{text}[section]
\begin{name}[text]
This is my interesting theorem
\end{name}
The “Jury” theorem uses the same counter as the “Law” theorem. There-
fore it gets a number which is in sequence with the other “Laws”. The ar-
46 Typesetting Mathematical Formulae
\flushleft
\newtheorem{mur}{Murphy}[section]
\begin{mur} Murphy 3.8.1 If there are two or more
If there are two or more ways to do something, and one of those
ways to do something, and ways can result in a catastrophe, then
one of those ways can result someone will do it.
in a catastrophe, then
someone will do it.\end{mur}
\begin{displaymath}
\mu, M \qquad \mathbf{M} \qquad
\mbox{\boldmath $\mu, M$} µ, M M µ, M
\end{displaymath}
Notice that the comma is bold too, which may not be what is required.
The package amsbsy (included by amsmath) makes this much easier as it
includes a \boldsymbol command.
\begin{displaymath}
\mu, M \qquad
\boldsymbol{\mu}, \boldsymbol{M} µ, M µ, M
\end{displaymath}
3.10 List of Mathematical Symbols 47
6
These tables were derived from symbols.tex by David Carlisle and subsequently
changed extensively as suggested by Josef Tkadlec.
48 Typesetting Mathematical Formulae
+ + − -
± \pm ∓ \mp / \triangleleft
· \cdot ÷ \div . \triangleright
× \times \ \setminus ? \star
∪ \cup ∩ \cap ∗ \ast
t \sqcup u \sqcap ◦ \circ
∨ \vee , \lor ∧ \wedge , \land • \bullet
⊕ \oplus \ominus \diamond
\odot \oslash ] \uplus
⊗ \otimes
\bigcirc q \amalg
4 \bigtriangleup 5 \bigtriangledown † \dagger
\lhd a \rhd a ‡ \ddagger
\unlhd a \unrhd a o \wr
3.10 List of Mathematical Symbols 49
† \dag § \S
c \copyright
‡ \ddag ¶ \P £ \pounds
Specialities
When putting together a large document, LATEX will help you with some special
features like index generation, bibliography management, and other things. A
much more complete description of specialities and enhancements possible with
LATEX can be found in the LATEX Manual [1] and The LATEX Companion [3].
2. Load the graphicx package in the preamble of the input file with
\usepackage[driver ]{graphicx}
\includegraphics[key=value, . . . ]{file}
\begin{figure}
\begin{center}
\includegraphics[angle=90, width=0.5\textwidth]{test}
\end{center}
\end{figure}
This includes the graphic stored in the file test.eps. The graphic is first
rotated by an angle of 90 degrees and then scaled to the final width of 0.5
times the width of a standard paragraph. The aspect ratio is 1.0, because
no special height is specified. The width and height parameters can also be
specified in absolute dimensions. Refer to Table 5.5 on page 72 for more
information. If you want to know more about this topic, make sure to read
[8] and [11].
4.2 Bibliography
You can produce a bibliography with the thebibliography environment.
Each entry starts with
\bibitem{marker }
The marker is then used to cite the book, article or paper within the
document.
\cite{marker }
Partl~\cite{pa} has
proposed that \ldots
\begin{thebibliography}{99}
\bibitem{pa} H.~Partl:
\emph{German \TeX}, Bibliography
TUGboat Vol.~9, No.~1 (’88)
\end{thebibliography}
For larger projects, you might want to check out the BibTEX program.
BibTEX is included with most TEXdistributions. It allows you to maintain
a bibliographic database and then extract the references relevant to things
you cited in your paper. The visual presentation of BibTEX generated bib-
liographies is based on a style sheets concept which allows you to create
bibliographies following a wide range of established designs.
4.3 Indexing
A very useful feature of many books is their index. With LATEX and the
support program makeindex5 , an index can be generated quite easily. In this
introduction, only the basic index generation commands will be explained.
For a more in-depth view, please refer to The LATEX Companion [3].
To enable the indexing feature of LATEX, the makeidx package must be
loaded in the preamble with:
\usepackage{makeidx}
\makeindex
\index{key}
commands, where key is the index entry. You enter the index commands
at the points in the text where you want the final index entries to point to.
Table 4.2 explains the syntax of the key argument with several examples.
When the input file is processed with LATEX, each \index command
writes an appropriate index entry together with the current page number
to a special file. The file has the same name as the LATEX input file, but a
different extension (.idx). This .idx file can then be processed with the
makeindex program.
makeindex filename
The makeindex program generates a sorted index with the same base
file name, but this time with the extension .ind. If now the LATEX input
5
On systems not necessarily supporting filenames longer than 8 characters, the program
may be called makeidx.
4.4 Fancy Headers 59
file is processed again, this sorted index gets included into the document at
the point where LATEX finds
\printindex
The showidx package which comes with LATEX 2ε prints out all index
entries in the left margin of the text. This is quite useful for proofreading a
document and verifying the index.
\documentclass{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
% with this we ensure that the chapter and section
% headings are in lowercase.
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhf{} % delete current setting for header and footer
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{0.5pt} % make space for the rule
\fancypagestyle{plain}{%
\fancyhead{} % get rid of headers on plain pages
\renewcommand{\headrulewidth}{0pt} % and the line
}
I suggest you fetch the documentation for the package at the address men-
tioned in the footnote.
\verbatiminput{filename}
command which allows you to include raw ASCII text into your document
as if it was inside a verbatim environment.
As the verbatim package is part of the ‘tools’ bundle, you should find it
preinstalled on most systems. If you want to know more about this package,
make sure to read [9]
4.6 Protecting fragile commands 61
\section{I am considerate
\protect\footnote{and protect my footnotes}}
Chapter 5
Customising LATEX
Documents produced by using the commands you have learned up to this point
will look acceptable to a large audience. While they are not looking fancy, they
obey all the established rules of good typesetting, which will make them easy
to read and pleasant to look at.
However there are situations where LATEX does not provide a command or
environment which matches your needs, or the output produced by some existing
command may not meet your requirements.
In this chapter, I will try to give some hints on how to teach LATEX new tricks
and how to make it produce output which looks different than what is provided
by default.
\begin{command}
\dum
\ci{dum}
\end{command}
\newcommand{name}[num]{definition}
\newcommand{\tnss}{The not
so Short Introduction to This is “The not so Short Introduction to
\LaTeXe} LATEX 2ε ” . . . “The not so Short Introduc-
This is ‘‘\tnss’’ \ldots{} tion to LATEX 2ε ”
‘‘\tnss’’
The next example illustrates how to define a new command which takes
one argument. The #1 tag gets replaced by the argument you specify. If
you wanted to use more than one argument, use #2 and so on.
\newcommand{\txsit}[1]
{This is the \emph{#1} Short
Introduction to \LaTeXe} • This is the not so Short Introduction
% in the document body: to LATEX 2ε
\begin{itemize} • This is the very Short Introduction to
\item \txsit{not so} LATEX 2ε
\item \txsit{very}
\end{itemize}
LATEX will not allow you to create a new command which would overwrite
an existing one. But there is a special command in case you explicitly
want this: \renewcommand. It uses the same syntax as the \newcommand
command.
5.1 New Commands, Environments and Packages 65
In certain cases you might also want to use the \providecommand com-
mand. It works like \newcommand, but if the command is already defined,
LATEX 2ε will silently ignore it.
There are some points to note about whitespace following LATEX com-
mands. See page 6 for more information.
\newenvironment{name}[num]{before}{after }
\newenvironment{king}
{\rule{1ex}{1ex}%
\hspace{\stretch{1}}}
{\hspace{\stretch{1}}%
\rule{1ex}{1ex}} My humble subjects . . .
\begin{king}
My humble subjects \ldots
\end{king}
The num argument is used the same way as in the \newcommand com-
mand. LATEX makes sure that you do not define an environment which
already exists. If you ever want to change an existing command, you can
use the \renewenvironment command. It uses the same syntax as the
\newenvironment command.
The commands used in this example will be explained later: For the
\rule command see page 77, for \stretch go to page 71, and more infor-
mation on \hspace can be found on page 71.
You can then use the \usepackage command to make the package available
in your document.
\ProvidesPackage{package name}
for use at the very beginning of your package file. \ProvidesPackage tells
LATEX the name of the package and will allow it to issue a sensible error
message when you try to include a package twice. Figure 5.1 shows a small
example package which contains the commands defined in the examples
above.
One important feature of LATEX 2ε is, that the font attributes are inde-
pendent. This means, that you can issue size or even font changing com-
mands and still keep the bold or slant attribute set earlier.
5.2 Fonts and Sizes 67
In math mode you can use the font changing commands to temporarily
exit math mode and enter some normal text. If you want to switch to another
font for math typesetting there exists another special set of commands. Refer
to Table 5.4.
In connection with the font size commands, curly braces play a significant
role. They are used to build groups. Groups limit the scope of most LATEX
commands.
The font size commands also change the line spacing, but only if the
paragraph ends within the scope of the font size command. The closing
curly brace } should therefore not come too early. Note the position of the
\par command in the next two examples. 1
1
\par is equivalent to a blank line
{\Large Don’t read this! It is not Don’t read this! It is not true.
true. You can believe me!\par}
You can believe me!
{\Large This is not true either. This is not true either. But re-
But remember I am a liar.}\par member I am a liar.
\begin{Large}
This is not true.
But then again, what is these
This is not true. But then again,
days \ldots what is these days . . .
\end{Large}
\newcommand{\oops}[1]{\textbf{#1}}
Do not \oops{enter} this room, Do not enter this room, it’s occupied by a
it’s occupied by a \oops{machine} machine of unknown origin and purpose.
of unknown origin and purpose.
This approach has the advantage that you can decide at some later stage
whether you want to use some other visual representation of danger than
\textbf without having to wade through your document, identifying all the
occurrences of \textbf and then figuring out for each one whether it was
used for pointing out danger or for some other reason.
5.2.3 Advice
To conclude this journey into the land of fonts and font sizes, here is a little
word of advice:
70 Customising LATEX
!
Remember The MO RE fonts you
use in a document, the
\linespread{factor }
\setlength{\parindent}{0pt}
\setlength{\parskip}{1ex plus 0.5ex minus 0.2ex}
in the preamble of the input file, you can change the layout of paragraphs.
These two commands increase the space between two paragraphs while set-
ting the paragraph indent to zero. In continental Europe, paragraphs are
often separated by some space and not indented. But beware, this also has
its effect on the table of contents. Its lines get spaced more loosely now as
well. To avoid this, you might want to move the two commands from the
preamble into your document to some place after the \tableofcontents or
to not use them at all, because you’ll find that most professional books use
indenting and not spacing to separate paragraphs.
If you want to indent a paragraph which is not indented, you can use
\indent
at the beginning of the paragraph.2 Obviously, this will only have an effect
when \parindent is not set to zero.
2
To indent the first paragraph after each section head, use the indentfirst package in
the ‘tools’ bundle.
5.3 Spacing 71
\noindent
as the first command of the paragraph. This might come in handy when
you start a document with body text and not with a sectioning command.
\hspace{length}
If such a space should be kept even if it falls at the end or the start of a
line, use \hspace* instead of \hspace. The length in the simplest case just
is a number plus a unit. The most important units are listed in Table 5.5.
This\hspace{1.5cm}is a space
This is a space of 1.5 cm.
of 1.5 cm.
The command
\stretch{n}
generates a special rubber space. It stretches until all the remaining space
on a line is filled up. If two \hspace{\stretch{n}} commands are issued
on the same line, they grow according to the stretch factor.
x\hspace{\stretch{1}}
x x x
x\hspace{\stretch{3}}x
\vspace{length}
This command should normally be used between two empty lines. If the
space should be preserved at the top or at the bottom of a page, use the
starred version of the command \vspace* instead of \vspace.
The \stretch command in connection with \pagebreak can be used to
typeset text on the last line of a page, or to centre text vertically on a page.
72 Customising LATEX
\vspace{\stretch{1}}
This goes onto the last line of the page.\pagebreak
\\[length]
command.
6
4i i
5 i
6 i
2
? ?
?
6 ?Header
6
6 6
Margin
Body i
7
Notes
- 9i
10i -
3i
-
i
8 -
? ?
1i- Footer
i
6
11
one line to the start of the next one. This is also the reason why newspapers
are typeset in multiple columns.
So if you increase the width of your body text, keep in mind that you
are making life difficult for the readers of your paper. But enough of the
cautioning, I promised to tell you how you do it . . .
LATEX provides two commands to change these parameters. They are
usually used in the document preamble.
The first command assigns a fixed value to any of the parameters:
\setlength{parameter }{length}
\addtolength{parameter }{length}
This second command is actually more useful than the \setlength com-
mand, because you can now work relative to the existing settings. To add
one centimetre to the overall text width, I put the following commands into
the document preamble:
\addtolength{\hoffset}{-0.5cm}
\addtolength{\textwidth}{1cm}
In this context, you might want to look at the calc package, it allows you
to use arithmetic operations in the argument of setlength and other places
where you can enter numeric values into function arguments.
\settoheight{command }{text}
\settodepth{command }{text}
\settowidth{command }{text}
\flushleft
\newenvironment{vardesc}[1]{%
\settowidth{\parindent}{#1:\ }
\makebox[0pt][r]{#1:\ }}{}
\begin{displaymath} a2 + b2 = c2
a^2+b^2=c^2
\end{displaymath} Where: a, b – are adjunct to the right angle
of a right-angled triangle.
\begin{vardesc}{Where}$a$,
$b$ -- are adjunct to the right c – is the hypotenuse of the triangle
angle of a right-angled triangle. and feels lonely.
d – finally does not show up here at
$c$ -- is the hypotenuse of all. Isn’t that puzzling?
the triangle and feels lonely.
5.6 Boxes
LATEX builds up its pages by pushing around boxes. At first, each letter is
a little box, which is then glued to other letters to form words. These are
again glued to other words, but with special glue, which is elastic so that a
series of words can be squeezed or stretched as to exactly fill a line on the
page.
I admit, this is a very simplistic version of what really happens, but the
point is that TEX operates on glue and boxes. Not only a letter can be a
box. You can put virtually everything into a box including other boxes.
Each box will then be handled by LATEX as if it was a single letter.
In the past chapters you have already encountered some boxes, although
I did not tell you. The tabular environment and the \includegraphics,
for example, both produce a box. This means that you can easily arrange
two tables or images side by side. You just have to make sure that their
combined width is not larger than the textwidth.
You can also pack a paragraph of your choice into a box with either the
\parbox[pos]{width}{text}
command or the
\makebox[width][pos]{text}
width defines the width of the resulting box as seen from the outside.5 Apart
from the length expressions you can also use \width, \height, \depth and
\totalheight in the width parameter. They are set from values obtained
by measuring the typeset text. The pos parameter takes a one letter value:
center, left flush, right flush or s which spreads the text inside the box to
fill it.
The command \framebox works exactly the same as \makebox, but it
draws a box around the text.
The following example shows you some things you could do with the
\makebox and \framebox commands.
\makebox[\textwidth]{%
c e n t r a l}\par
\makebox[\textwidth][s]{% central
s p r e a d}\par s p r e a d
\framebox[1.1\width]{Guess I’m
framed now!} \par Guess I’m framed now!
\framebox[0.8\width][r]{Bummer, Bummer, I am to wide
I am to wide} \par
\framebox[1cm][l]{never never mind,
Can you
so am
readI this?
mind, so am I}
Can you read this?
Now that we control the horizontal, the obvious next step is to go for
5
This means it can be smaller than the material inside the box. You can even set
the width to 0pt so that the text inside the box will be typeset without influencing the
surrounding boxes.
5.7 Rules and Struts 77
\raisebox{lift}[depth][height]{text}
command lets you define the vertical properties of a box. You can use
\width, \height, \depth and \totalheight in the first three parameters,
in order to act upon the size of the box inside the text argument.
\raisebox{0pt}[0pt][0pt]{\Large%
\textbf{Aaaa\raisebox{-0.3ex}{a}%
\raisebox{-0.7ex}{aa}%
\raisebox{-1.2ex}{r}% Aaaaaaa he shouted but not even
\raisebox{-2.2ex}{g}% the next one ringline noticed that something
\raisebox{-4.5ex}{h}}} terrible had happened
h to him.
he shouted but not even the next
one in line noticed that something
terrible had happened to him.
\rule[lift]{width}{height}
6
Total control is only to be obtained by controlling both the horizontal and the vertical
...
78 Customising LATEX
\rule{3mm}{.1pt}%
\rule[-1mm]{5mm}{1cm}%
\rule{3mm}{.1pt}%
\rule[1mm]{1cm}{5mm}%
\rule{3mm}{.1pt}
This is useful for drawing vertical and horizontal lines. The line on the title
page for example, has been created with a \rule command.
A special case is a rule with no width but a certain height. In professional
typesetting, this is called a strut. It is used to guarantee that an element
on a page has a certain minimal height. You could use it in a tabular
environment to make sure a row has a certain minimum height.
\begin{tabular}{|c|}
\hline
\rule{1pt}{4ex}Pitprop \ldots\\
Pitprop . . .
\hline
\rule{0pt}{4ex}Strut\\ Strut
\hline
\end{tabular}
Bibliography
[3] Michel Goossens, Frank Mittelbach and Alexander Samarin. The LATEX
Companion. Addison-Wesley, Reading, Massachusetts, 1994, ISBN 0-
201-54199-8.
[4] Each LATEX installation should provide a so-called LATEX Local Guide
which explains the things which are special to the local system. It should
be contained in a file called local.tex. Unfortunately, some lazy sysops
do not provide such a document. In this case, go and ask your local
LATEX guru for help.
[5] LATEX3 Project Team. LATEX 2ε for authors. Comes with the LATEX 2ε
distribution as usrguide.tex.
[6] LATEX3 Project Team. LATEX 2ε for Class and Package writers. Comes
with the LATEX 2ε distribution as clsguide.tex.
[7] LATEX3 Project Team. LATEX 2ε Font selection. Comes with the LATEX 2ε
distribution as fntguide.tex.
\!, 41 A4 paper, 10
", 19 A5 paper, 10
$, 35 accent, 21
\(, 35 acute, 21
\), 35 \addtolength, 74
\,, 36, 41 advantages of LATEX, 3
-, 20 æ, 21
−, 20 amsbsy, 46
\-, 18 amsfonts, 37, 53
–, 20 amsmath, 39–41, 43, 46
—, 20 amssymb, 37, 47
., space after, 23 \and, 25
. . . , 20 \appendix, 24
.aux, 13 \arccos, 39
.cls, 11 \arcsin, 39
.dtx, 11 \arctan, 39
\arg, 39
.dvi, 11
array, 42
.idx, 13
arrow symbols, 38
.ilg, 13
article class, 9
.ind, 13
\atop, 39
.ins, 11
\author, 25
.lof, 13
.log, 11 B5 paper, 10
.lot, 13 babel, 18, 22
.sty, 11 \backmatter, 25
.tex, 11 backslash, 6
.toc, 13 \backslash, 5
\:, 41 base font size, 10
\;, 41 \begin, 27
\@, 23 \bibitem, 57
\[, 36 bibliography, 57
\\, 17, 27, 28, 30, 72 \Big, 40
\\*, 17 \big, 40
\], 36 \Bigg, 40
~, 23 \bigg, 40
82 INDEX
\binom, 39 \atop, 39
blackboard bold, 37 \author, 25
\bmod, 39 \backmatter, 25
bold face, 67 \backslash, 5
bold symbols, 37, 46 \begin, 27
\boldmath, 46 \bibitem, 57
\boldsymbol, 46 \Big, 40
book class, 9 \big, 40
braces, 40 \Bigg, 40
\bigg, 40
calc, 74 \binom, 39
\caption, 33, 61 \bmod, 39
\cdots, 41 \boldmath, 46
center, 27 \boldsymbol, 46
\chapter, 24 \caption, 33, 61
\chaptermark, 59 \cdots, 41
\choose, 39 \chapter, 24
\ci, 63 \chaptermark, 59
\cite, 57 \choose, 39
\cleardoublepage, 34 \ci, 63
\clearpage, 34 \cite, 57
coloured text, 9 \cleardoublepage, 34
comma, 20 \clearpage, 34
command, 63 \cos, 39
commands, 6 \cosh, 39
\!, 41 \cot, 39
\(, 35 \coth, 39
\), 35 \csc, 39
\,, 36, 41 \date, 25
\-, 18 \ddots, 41
\:, 41 \deg, 39
\;, 41 \depth, 76, 77
\@, 23 \det, 39
\[, 36 \dim, 39
\\, 17, 27, 28, 30, 72 \displaystyle, 44
\\*, 17 \documentclass, 9, 11, 18
\], 36 \dum, 63
\addtolength, 74 \emph, 26, 67
\and, 25 \end, 27
\appendix, 24 \exp, 39
\arccos, 39 \footnote, 26, 61
\arcsin, 39 \footnotesize, 67
\arctan, 39 \frac, 39
\arg, 39 \framebox, 76
INDEX 83
\frenchspacing, 23 \log, 39
\frontmatter, 25 \mainmatter, 25
\fussy, 18 \makebox, 76
\gcd, 39 \makeindex, 58
\genfrac, 39 \maketitle, 25
\height, 76, 77 \mathbb, 37
\hline, 30 \mathbf, 68
\hom, 39 \mathcal, 68
\hspace, 65, 71 \mathit, 68
\Huge, 67 \mathnormal, 68
\huge, 67 \mathrm, 44, 68
\hyphenation, 18 \mathsf, 68
\idotsint, 41 \mathtt, 68
\iiiint, 41 \max, 39
\iiint, 41 \mbox, 19, 21, 76
\iint, 41 \min, 39
\include, 14 \multicolumn, 31
\includegraphics, 56, 75 \newcommand, 64, 65
\includeonly, 14 \newenvironment, 65
\indent, 70 \newline, 17
\index, 58 \newpage, 17
\inf, 39 \newtheorem, 45
\input, 14 \noindent, 71
\int, 40 \nolinebreak, 17
\item, 27 \nonumber, 43
\ker, 39 \nopagebreak, 17
\label, 25, 36 \normalsize, 67
\LARGE, 67 \overbrace, 38
\Large, 67 \overleftarrow, 38
\large, 67 \overline, 38
\LaTeX, 19 \overrightarrow, 38
\LaTeXe, 19 \pagebreak, 17
\ldots, 20, 41 \pageref, 25
\left, 40 \pagestyle, 13
\leftmark, 59 \par, 67
\lg, 39 \paragraph, 24
\lim, 39 \parbox, 75, 76
\liminf, 39 \parindent, 70
\limsup, 39 \parskip, 70
\linebreak, 17 \part, 24
\linespread, 70 \phantom, 43, 61
\listoffigures, 33 \pmod, 39
\listoftables, 33 \Pr, 39
\ln, 39 \printindex, 59
84 INDEX
\prod, 40 \textnormal, 67
\protect, 61 \textrm, 44, 67
\providecommand, 65 \textsc, 67
\ProvidesPackage, 66 \textsf, 67
\qquad, 36, 41 \textsl, 67
\quad, 36, 41 \textstyle, 44
\raisebox, 77 \texttt, 67
\ref, 25, 36 \textup, 67
\renewcommand, 64 \thispagestyle, 13
\renewenvironment, 65 \tiny, 67
\right, 40, 42 \title, 25
\right., 40 \tnss, 64
\rightmark, 59 \today, 19
\rule, 65, 77, 78 \totalheight, 76, 77
\scriptscriptstyle, 44 \underbrace, 38
\scriptsize, 67 \underline, 38
\scriptstyle, 44 \usepackage, 11, 22, 23, 66
\sec, 39 \vdots, 41
\section, 24, 61 \vec, 38
\sectionmark, 59 \verb, 29
\setlength, 70, 74 \verbatiminput, 60
\settodepth, 74 \vspace, 71
\settoheight, 74 \widehat, 38
\settowidth, 74 \widetilde, 38
\sin, 39 \width, 76, 77
\sinh, 39 comment, 7
\sloppy, 18 comments, 6
\small, 67 \cos, 39
\sqrt, 38 \cosh, 39
\stackrel, 39 \cot, 39
\stretch, 65, 71 \coth, 39
\subparagraph, 24 cross-references, 25
\subsection, 24 \csc, 39
\subsectionmark, 59 curly braces, 6, 67
\subsubsection, 24
\sum, 40 dash, 20
\sup, 39 \date, 25
\tableofcontents, 24 dcolumn, 31
\tan, 39 \ddots, 41
\tanh, 39 decimal alignment, 31
\TeX, 19 \deg, 39
\textbf, 67 delimiters, 40
\textit, 67 \depth, 76, 77
\textmd, 67 description, 27
INDEX 85
\det, 39 thebibliography, 57
diagonal dots, 41 verbatim, 29, 60
\dim, 39 verse, 28
dimensions, 71 eqnarray, 42
displaymath, 36 equation, 36
\displaystyle, 44 equation system, 42
doc, 12 eucal, 53
document font size, 10 eufrak, 53
document title, 10 executive paper, 10
\documentclass, 9, 11, 18 \exp, 39
dotless ıand , 21 exponent, 38
double line spacing, 70 exscale, 12, 40
double sided, 10 extension, 11
\dum, 63
fancyhdr, 59, 60
ellipsis, 20 figure, 32, 33
em-dash, 20 file types, 11
\emph, 26, 67 floating bodies, 31
empty, 13 flushleft, 27
en-dash, 20 flushright, 27
Encapsulated PostScript, 55 foiltex, 9
\end, 27 font, 66
enumerate, 27 font encoding, 12
environments font size, 66, 67
array, 42 fontenc, 12, 23
center, 27 footer, 13
command, 63 \footnote, 26, 61
comment, 7 \footnotesize, 67
description, 27 formulae, 35
displaymath, 36 \frac, 39
enumerate, 27 fraction, 39
eqnarray, 42 fragile commands, 61
equation, 36 \framebox, 76
figure, 32, 33 \frenchspacing, 23
flushleft, 27 \frontmatter, 25
flushright, 27 \fussy, 18
itemize, 27
math, 35 \gcd, 39
minipage, 75, 76 \genfrac, 39
parbox, 76 German, 22
quotation, 28 GhostScript, 55
quote, 28 graphics, 9, 55
table, 32, 33 graphicx, 55
tabular, 30, 75 grave, 21
86 INDEX
\textsl, 67 WYSIWYG, 3
\textstyle, 44
\texttt, 67
\textup, 67
thebibliography, 57
\thispagestyle, 13
three dots, 41
tilde, 20, 38
tilde ( ~), 23
\tiny, 67
title, 10, 25
\title, 25
\tnss, 64
\today, 19
\totalheight, 76, 77
two column, 10
umlaut, 21
\underbrace, 38
underfull hbox, 18
\underline, 38
units, 71, 72
upright, 67
URL, 20
\usepackage, 11, 22, 23, 66
\vdots, 41
\vec, 38
vectors, 38
\verb, 29
verbatim, 7, 60
verbatim, 29, 60
\verbatiminput, 60
verse, 28
vertical dots, 41
vertical space, 71
\vspace, 71
whitespace, 5
after commands, 6
at the start of a line, 5
\widehat, 38
\widetilde, 38
\width, 76, 77
www, 20
90 INDEX