LATEX
LATEX
LATEX
Table of Contents
1. LATEX Basics 1
1.1 What is TEX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 What is LATEX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 How LATEX Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 The LATEX Input File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4.1 Entering LATEX Commands . . . . . . . . . . . . . . . . . . . . . . 2
1.4.2 Entering Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4.3 Special Characters . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4.4 Structure of the Input File . . . . . . . . . . . . . . . . . . . . . . 4
1.5 Some LATEX Vocabulary . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2. Creating A LATEX Document 7
2.1 Document Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Class Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.4 Making a Title Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.5 Making a Table of Contents . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.6 Behind the Scenes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.6.1 Auxiliary Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.6.2 How a Page is Built . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.7 Example: Report Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.8 Example: Letter Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3. Document Layout 13
3.1 Line Spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2 Paragraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.3 Text Justification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.4 Margins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.5 Headers, Footers, and Page Numbering . . . . . . . . . . . . . . . . . . . 15
ii ♦ Contents
9. Preparing a Bibliography 41
9.1 Using LATEX’s built-in Method . . . . . . . . . . . . . . . . . . . . . . . . 41
9.2 Using BibTEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
9.2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
9.2.2 Creating the .bib File . . . . . . . . . . . . . . . . . . . . . . . . 43
9.2.3 Running BibTEX . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
9.2.4 Bibliography Styles . . . . . . . . . . . . . . . . . . . . . . . . . . 44
1
2 ♦ Chapter 1. LATEX Basics
• The traditional way is to run the latex program, which creates a DVI (Device
Independent) file. This file is in binary format and not viewed directly. You
then run a previewing program for viewing on screen and/or the dvips program
to create a PostScript file for viewing or for printing via the ghostview/GSView
program. GSView can also convert the document to PDF format.
• Alternatively you can run the relatively recent pdflatex program to create a PDF
file for viewing or printing, usually with Adobe’s Acrobat Reader.
The second method is more direct for PDF output, but the first is quicker and more
convenient for previewing.
Some commands take an “argument,” placed within curly braces { } after the command
name. For example, \textbf{this text is bold} prints the text inside the braces in
boldface type: this text is bold
LATEX uses grouping to limit the effect of certain commands. Braces { ... } are used to
begin and end groups. (An environment is also a group; see page 5.) For example, the
\large command is usually used inside a group:
{\large this is bigger than normal} produces: this is bigger than normal
A command such as \large is called a “declaration” because, unless it is given within
a group, its effect will continue until another declaration (in this case \normalsize)
counteracts it. Note the difference between a declaration used inside a group and a
command like \textbf{...}, which will not work unless an argument is provided inside
a pair of braces following the command name.
The symbol % can be used to put a comment in your input file. When LATEX sees a %, it
ignores the rest of the line.
When you use commands that specify a length, such as a command to set the size of a
margin or a command to leave a certain amount of space, you will need to specify the
units of measurement. LATEX recognizes the following units:
cm centimeter pt printer’s point, ≈ 72 per inch
mm millimeter em font-dependent width of “m”
in inch ex font-dependent height of “x”
\documentclass[options]{class}
Preamble
\begin{document}
Document text
\end{document}
In the first command above, class specifies the type of document you intend to create.
You can choose from one of the LATEX classes described in the next chapter. If you wish,
you can also include one or more options to modify the behavior of the document class.
The preamble is the section of the file between the \documentclass{...} command and
the \begin{document} command. This is the place to put commands that will influence
the style of your entire document and macro definitions that you will use later. You may
also load packages that add new features to LATEX. Text is not allowed in the preamble.
1.5 Some LATEX Vocabulary ♦ 5
The \begin{document} command indicates the end of the preamble and the beginning
of your text. A corresponding \end{document} command always ends your files. A
really short LATEX input file might look like:
\documentclass{article}
\begin{document}
This LaTeX file is short and sweet. It uses the article class,
a good all-purpose layout. There is nothing in the preamble, which
is perfectly acceptable.
This LaTeX file is short and sweet. It uses the article class, a good all-purpose layout.
There is nothing in the preamble, which is perfectly acceptable.
This is a new paragraph. Here’s some italic text and some bold text. The text inside
these braces is smaller than normal. Now the text size is back to normal.
Longer examples, one using report class and one using letter class are included at the
end of the next chapter.
Optional arguments are allowed on some commands and are enclosed in square brack-
ets: [ ]. For example, the size of type to be used for your main text is an optional
argument in the {\documentclass} command. To use the article class in 11-point
type, you would type \documentclass[11pt]{article}. Without this optional
argument, you would get the default 10-point type.
6 ♦ Chapter 1. LATEX Basics
Declarations produce neither text nor space, but either affect the way LATEX prints
the following text or provide information for later use. Font size changes are an
example of declarations. \large will cause any text that follows to appear in a
larger type size. Declarations are often used within a group to limit their scope. For
example: {\large Only the text inside these braces will be large.}
* Some commands can have a * appended to the name, which indicates a variation on a
command or environment. For example, \\ indicates a line break. \\* indicates a
line break with the restriction that LATEX is not allowed to begin a new page at that
point. Space printed by \vspace and \hspace commands is normally dropped if
it appears at the beginning or end of a line or page. If you want the space printed
no matter where it falls, you would use \hspace* or \vspace*. Normally, section
headings are automatically numbered, but \section*{My Heading} will produce
an unnumbered section heading.
Chapter 2. Creating A LATEX Document
2.1 Document Classes
The document class determines the overall layout of the document. There are five
standard classes distributed with LATEX:
article for simple or short documents, including journal articles, and short reports. A
good all-purpose class.
report for small books and longer reports containing chapters.
book for books.
letter for letters, either business or personal.
slides for making transparencies for projection on a screen.
These classes provide preset formats with default margins, paragraph formatting, and
special commands suitable for producing specific sections. For example, the article,
report, and book classes include a variety of commands to format section headings
(\part, \chapter, \section, \subsection, \subsubsection, etc.), as well as com-
mands to produce a title page and a table of contents. There are minor differences
between these three classes. The book class, for example, uses a smaller printed page
size—about 5×7.5 inches—and is formatted for two-sided printing by default. The
article class is intended for shorter works and does not have chapters (so articles can
be easily included in reports or books). The letter class provides special commands to
produce the salutation, address, and closing.
These four classes are single-spaced by default, and have 10, 11, and 12-point type sizes
available as options. 10 points is the default size.
The slides class uses sans-serif type fonts much larger than the usual ones and expects
the document to be divided up into 1-page sections.
10pt, 11pt, 12pt Selects the point size of main font for the document. If no option is
specified, 10pt is assumed. This document uses 12-point type.
twocolumn Produces two-column pages.
titlepage Causes the \maketitle command to generate the title page on a separate
page for the article class. This option is not necessary for the book and report
classes, as they print separate title pages by default.
leqno Puts equation numbers on left side. (They are on the right by default.)
fleqn Left-aligns equations. (They are centered by default.)
twoside Formats for printing on both sides of paper. (Whether the document is actually
printed two-sided depends on the printer.) Twoside is the default for the book class,
but not for any of the other classes.
openright If the twoside option is in effect, chapters will begin on right hand pages.
This is the default for the book class. It does not apply to the article class,
which does not contain chapters. (The opposite of openright is openany.)
2.3 Packages
There are a large number of LATEX packages available that provide a variety of
additional features. Many packages are considered part of LATEX; others are provided
by expert users worldwide. If you sometimes find that the features of standard LATEX
do not provide the special formatting you want, chances are good that you can find a
package to meet your needs. A package generally consists of one or more files that
contain extra definitions and macros. Some packages are simple; others are complex and
can contain options. The file names usually have the extension .sty.
You load a package with the \usepackage command, which should come immediately
after the \documentclass command in your input file. The command has the form:
\usepackage[options ]{package }
Each package may be included with its own \usepackage command, or you may use one
command to load several packages by separating their names with commas. For example,
if you are inserting graphics in your document (see chapter 7.), the package graphicx
provides the commands to do this. The beginning of your input file might look like:
\documentclass[11pt]{article}
\usepackage{graphicx}
The \usepackage command above instructs LATEX to read the file graphicx.sty.
2.4 Making a Title Page ♦ 9
In addition to graphicx there are many other packages available, including packages to
rotate text, use PostScript fonts (e.g., Times, Palatino, etc), and customize such things
as headers and footers, citations and captions. Packages come with their own documen-
tation. Many packages are routinely distributed with LATEX and will already be on your
system. You’ll find documentation for these packages in the doc subdirectory of your
installation. For example, if you are using the TeXLive 2005 distribution for Windows,
package documentation is in folders under C:\TeXLive2005\texmf-dist\doc\latex\.
To see a current list of all available packages with brief descriptions, look at the Com-
prehensive TeX Archive Network (CTAN) catalog,
http://texcatalogue.sarovar.org/brief.html.
3.2 Paragraphs
To start a new paragraph, either leave a blank line or use the control sequence \par.
By default, paragraphs are indented by 1.5em, which means 1.5 times the point size
of the current font. (1 em is about the width of an “M”.) No extra blank space
is inserted between paragraphs. The commands \parindent and \parskip control
paragraph indentation and paragraph separation. To get block paragraphs, for example,
include in the preamble the commands:
\parindent=0in
\parskip=8pt % this is variable, choose the number you want
1
the section between the \documentclass command and the \begin{document} command
13
14 ♦ Chapter 3. Document Layout
3.4 Margins
Changing default margins, which depend on the class and the font size, is not as easy
as you might think. The best way to control margins is to use the geometry package.
This package has many options and extensive documentation in manual.pdf found in
your directory ...\doc\latex\geometry\. The following examples should be obvious:
\usepackage[margin=1in]{geometry} % 1 inch margins all around
\usepackage[left=1.2in,right=1in,top=1in,bottom=.8in]{geometry}
If you really want to do it manually, you need to know that internally top and left margins
are set in reference to a value of one inch (which means that setting these margins equal
to 0 produces one-inch margins). Therefore, setting topmargin to -.5in produces a top
margin of .5 inches. The opposite margins (bottom and right) are determined indirectly
by setting the height (textheight) and width (textwidth) of the text area.
to set margin change the command
top margin \topmargin
bottom margin \textheight
left margin (for odd pages or single sided) \oddsidemargin
left margin (for even pages, if using twoside) \evensidemargin
right margin \textwidth
LATEX also leaves .5 inch at the top of the page for a header and about .6 inch at the
bottom of the page for a footer. You must take this into account when choosing values
for topmargin and textheight. The values below leave one inch between the paper
edge and the text on all four sides.
\setlength{\topmargin}{-.5in} % top margin is .5 in
\setlength{\oddsidemargin}{0in} % left margin is 1 in on right pages
\setlength{\evensidemargin}{0in} % same for left pages, 2-sided document
\setlength{\textwidth}{6.5in} % leaves 1 in for right margin
\setlength{\textheight}{9in} % 9 inches reserved for the text
3.5 Headers, Footers, and Page Numbering ♦ 15
\pagestyle{plain}: The page number is in the foot and the head is empty. This is
the default page style for the article and report document classes.
\pagestyle{empty}: The head and foot are both empty.
\pagestyle{headings}: The page number and current section heading (the level of
the heading is determined by the document class) is put in the head; the foot is
empty. This is the default for the book class.
\pagestyle{myheadings}: Similar to the headings page style, except you specify the
information (other than the page number) that goes in the head by using the
markboth and markright commands. markboth is used for two-sided docu-
ments, and markright is used for one-sided:
\markboth{leftheader }{rightheader }
\markright{rightheader }
\thispagestyle{style}: Changes the page style for the current page only. For example,
to have nothing in the head and foot for the current page without affecting the
style for the rest of the pages, use \thispagestyle{empty}.
You can also specify arabic (the default) or roman page numbering either in the preamble
or in the text. It is common to put \pagenumbering{roman} before the text begins and
\pagenumbering{arabic} after the first \chapter command. These commands also
set the page number to 1. You can change the page number counter yourself with a
command such as \setcounter{page}{2}.
If the above pagestyle commands don’t do what you want, there is a package called
fancyhdr that allows you to customize your headers and footers in an easy way. With
this package you can define three-part headers and footers (left, right, and center), multi-
line headers and footers, separate headers and footers for even and odd pages, and more.
To use it, include the following commands in the preamble:
\usepackage{fancyhdr}
\pagestyle{fancy}
For simple use, you need only to include the following 6 commands in your preamble, sup-
plying your text inside the {} in each case: \lhead{}, \chead{}, \rhead{}, \lfoot{},
cfoot{}, \rfoot{}. To suppress the horizontal line drawn by default under the header,
use \renewcommand{\headrulewidth}{0pt}. For more information, see fancyhdr.pdf
in your directory ...\doc\latex\fancyhdr\.
Chapter 4. Within the Text
Within the text, there will always be certain sections that require special treatment—
such as a different size of type, indentation, or special placement on the page. Some
specialized areas of text (particularly those that require indentation) are formatted with
the help of LATEX environments.
16
4.2 Changing Type Style and Size ♦ 17
4.6 Footnotes
Footnotes are numbered automatically by LATEX. The command \footnote{footnote
text} should be placed exactly where you want the footnote number to appear, with no
extra space between the \footnote command and the text before it. For example:
This is text with a note.\footnote{This is the note text.
Here it is at the bottom of the page.}
produces:
This is text with a note.2
4.7 Centering
If you have only one line to center, it’s easiest to use the plain TEX command
\centerline; for example,
\centerline{This line will be centered}.
If you have several lines to be centered horizontally, the center environment is conve-
nient. The example below produces three lines, each horizontally centered.
\begin{center}
This is line one. \\
This is line two. \\
This is line three.
\end{center}
There is also the declaration \centering, which is always used within a group—either a
pair of braces or an environment. This is useful when you don’t want the extra vertical
space surrounding the center environment.
4.8 Quotations
The quote environment begins a new line and indents text from both sides. It
is delimited with \begin{quote} and \end{quote}. Any special effects (such
as changes to the type size or style) started within the quote environment
are terminated by \end{quote}.
New paragraphs are block style: that is, no indent and a blank line as sepa-
ration. This section is inside a quote environment.
There is also a very similar environment called quotation. The only difference is that
paragraphs in the quotation environment are indented with no blank line between.
2
This is the note text. Here it is at the bottom of the page.
20 ♦ Chapter 4. Within the Text
produces:
4.10 Lists
The three LATEX list environments all use the \item command to start new items in the
list. The enumerate environment numbers items sequentially, the itemize environment
puts a bullet in front of each item, and the description environment puts a boldface
word or phrase in front of each item.
The following examples show both the output and the input used to create them.
Example of Enumerate
\begin{enumerate}
\item Sugar 1. Sugar
\item Cream
\item Chocolate 2. Cream
\end{enumerate} 3. Chocolate
Example of Itemize
\begin{itemize} • Mix all ingredients together.
\item Mix all ingredients together.
\item Boil until the thermometer • Boil until the thermometer
reaches 112 $^\circ$C. reaches 112 ◦ C.
\item Stir and cool.
\end{itemize} • Stir and cool.
Example of Description
\begin{description} dog A loving animal that likes to
\item[dog] A loving animal that sleep on the furniture.
likes to sleep on the furniture.
\item[cat] Aloof creature that can cat Aloof creature that can warm
warm your feet on a winter’s night your feet on a winter’s night
\item[horse] Large animal, gives horse Large animal, gives great rides.
great rides. Eats a lot, luckily Eats a lot, luckily doesn’t sleep
doesn’t sleep on the furniture. on the furniture.
\end{description}
Below is an example of nesting list environments:
Here are some useful environments: Here are some useful environments:
\begin{itemize}
\item center environment • center environment
\item quote environment • quote environment
\item the three list environments:
\begin{enumerate} • the three list environments:
\item enumerate (uses numbers)
\item itemize (uses bullets) 1. enumerate (uses numbers)
\item description (uses words) 2. itemize (uses bullets)
\end{enumerate}
3. description (uses words)
\end{itemize}
22 ♦ Chapter 4. Within the Text
5.1 Tabbing
Tabbing uses the following commands:
\= Set a tab stop
\\ Terminate a line
Tabs are usually set in the first line but may also be added in later lines. A special line
ending with the command \kill may be used to set tabs but not print the line. Below
are two examples of tabbing. Note that the last entry does not require a \\ to end the
line.
23
24 ♦ Chapter 5. Tabular Material
5.2 Tabular
The tabular environment requires an additional argument that specifies the alignment
of each column (centered, left justified, etc.):
\begin{tabular}{align}
You may substitute any combination of the following symbols for the align argument:
The width necessary for each column is determined automatically from the widest entry.
Inside the tabular environment, use the tab character (&) to move to the next column,
\\ to end each line (except the last one), and \hline to insert a horizontal line.
The following examples illustrate the tabular environment. Note that you can center
a table by enclosing the tabular environment inside a center environment.
5.2 Tabular ♦ 25
\begin{center}
\begin{tabular}{|l|c|r|} % 3 cols (left, ctr, right); vert. lines
\hline % draw horizontal line
Name & Oblateness & Diameter \\
\hline
Mercury & 0 & 3,100 \\
Venus & 0 & 7,700 \\
Earth & 1/297 & 7,927 \\
Mars & 1/192 & 4,200 \\
Jupiter & 1/15 & 88,700 \\
Saturn & 1/9.5 & 75,100 \\
Uranus & 1/14 & 32,100 \\
Neptune & 1/40 & 27,700 \\
Pluto & ? & 3,600\\
\hline
\end{tabular}
\end{center}
Produces:
\begin{tabular}{@{} l @{}}
\hline
no leading or trailing space\\ no leading or trailing space
\hline
\end{tabular}
\begin{tabular}{l}
\hline
leading space left and right\\ leading space left and right
\hline
\end{tabular}
3
For an another method, see the dcolumn package, provided as part of the LATEX “tools” bundle.
Chapter 6. Mathematics
One of the greatest strengths of LATEX is its ability to typeset formulas and equations. To
make it easier to enter mathematical text, LATEX has defined several hundred Greek sym-
bols, mathematical symbols, delimiters, and operators. These are listed in Appendix A
of this memo.
LATEX has several modes for setting math text, which are described below. When in
math mode, LATEX sets type differently than when in text mode. For example, all letters
are set in the math italic typeface, and spaces in the input are ignored because LATEX
uses its own “mathematically correct” spacing. Therefore, if you want to use normal
text or retain spaces while in math mode, you must enclose this text with an “mbox”:
\mbox{this is normal text}. Also, new paragraphs are not allowed within math
mode, so be sure not to leave any blank lines.
If your mathematical expressions are particularly complex or sophisticated, you may
want to look at AMS-LATEX, a collection of packages that provides extensions to
LATEX’s mathematical capabilities. The amssymb package provides additional math-
ematical symbols; the amsmath package provides additional environments for build-
ing mathematical expressions. For help with using AMSLATEX, see The Short Math
Guide for LATEX, at: ftp://ftp.ams.org/pub/tex/doc/amsmath/short-math-guide.pdf.
The official documentation is amsldoc.pdf, which you can find on your system in
...\doc\latex\amslatex\.
28
6.2 Display Math (for unnumbered equations) ♦ 29
produces:
The derivative of the function f (x) at the point x0 is
f (x) − f (x0 )
f 0 (x0 ) = x→x
lim (1)
0 x − x0
30 ♦ Chapter 6. Mathematics
produces:
These three products can be expanded and simplified to produce these equations:
(a + b)(a + b) = a2 + ab + ba + b2
= a2 + 2ab + b2 (1)
(a + b)(a − b) = a2 − ab + ba − b2
= a2 − b 2 (2)
3
(a + b) = a3 + 3a2 b + 3ab2 + b3 (3)
6.6.4 Fractions
The ‘/’ can be used to make simple fractions, but the \frac commmand is used for most
fractions; its two arguments are the numerator and denominator. Two variations of a
fraction are provided by the plain TEX commands \atop and \choose.
$$ \frac{a}{b} \qquad \frac{a/b}{c/d}
\qquad {a\atop b} \qquad {a\choose b} $$
$$ 1 + 2 + 3 + \cdots + n = \frac{n(n+1)}{2} $$
$$ \lim_{n\rightarrow\infty}\frac{1}{n}=0
\qquad y’’=\frac{d^2y}{dx^2} $$
produces: !
a a/b a a
b c/d b b
n(n + 1)
1 + 2 + 3 + ··· + n =
2
2
1 dy
lim =0 y 00 = 2
n→∞ n dx
Integral signs are produced with the \int command, and summation signs are produced
with the \sum command. These symbols are often used with superscripts and subscripts:
$$\sum^{\infty}_{n=1} \qquad \int^b_a e^{x^2}\,dx $$
$$\sqrt{\sum_{i=1}^{n}i} \qquad \sum_{\stackrel{i=1}{j=2}}^{\infty}$$
$$\sum \Delta V=\int\!\!\!\int\!\!\!\int_V dv $$
produces:
∞ Z b 2
ex dx
X
n=1 a
v
u n
X ∞
X
t i
i=1 i=1
j=2
X ZZZ
∆V = dv
V
34 ♦ Chapter 6. Mathematics
produces:
c0 c1 c2 . . . cn
c1 c2 c3 . . . cn+1
det = c2 c3 c4 . . . cn+2 > 0.
. . . .
. . . .
cn cn+1 cn+2 . . . c2n
\[
\mbox{signum}(x)=\left\{
\begin{array}{rl}
1 & \mbox{if $x>0$} \\
0 & \mbox{if $x=0$} \\
-1 & \mbox{otherwise}
\end{array} \right.
\]
produces:
1 if x > 0
signum(x) = 0 if x = 0
−1 otherwise
Chapter 7. Including Graphics
7.1 Creating the Graphics File
The easiest way to put graphics into your LATEX document is to first create the graphic
using a software package, such as Maple, Matlab, CorelDRAW, Xfig, Gnuplot, etc.
If you are using LATEX plus dvips to produce your final output, you should save the
graphic as encapsulated PostScript (eps), the only acceptable format. If you are using
pdfLATEX (which produces a pdf file directly), acceptable formats are pdf, jpeg, or png,
but not eps. A general rule of thumb for graphics formats is to use pdf or eps for vector
graphics (line art, graphs, etc), jpeg for photographs, and png for screen shots.
If you are using pdfLATEX and your graphics files are in eps format, you can convert them to
pdf using the epstopdf utility, which is most likely on your system. Run this program from the
command line (in Windows, open a command window and cd to the appropriate folder):
epstopdf myfigure.eps generates myfigure.pdf
After doing this, you will have two files for your graphic, one eps and one pdf.
If you are using LATEX plus dvips, the jpeg2ps utility is handy. It converts JPEG images
to eps files without uncompressing the images. The JPEG data is simply “wrapped”
with PostScript, yielding considerably smaller PostScript files. Use it from the command
line:
jpeg2ps -h image.jpg > image.eps
You may already have jpeg2ps on your system; if not, you can download it from:
http://www.ctan.org/tex-archive/support/jpeg2ps/.
35
36 ♦ Chapter 7. Including Graphics
Complete documentation for the graphics bundle is in the file grfguide.pdf; look for it
on your system. Information on the graphicx package is in section 4.4. For an extensive
treatment of including graphics, see Using Imported Graphics in LATEX and pdfLATEX by
Keith Reckdahl of Stanford University. It includes all you would ever want to know with
many examples: http://www.ctan.org/tex-archive/info/epslatex.pdf.
Chapter 8. Placing Figures & Tables (Floats)
If you have figures or tables in your document, you’ll want to make sure that they are
not broken across pages. To accomplish this, LATEX provides two environments, figure
and table, which move or “float” the material inside the environment to a location
where it all fits. Meanwhile, LATEX fills the current page with text to avoid half empty
pages. The commands to use these two environments look like:
\begin{figure} \begin{table}
... figure material ... ... tabular material ...
\end{figure} \end{table}
There are also “starred” versions of these environments (table* and figure*), which,
in 2-column text, place floats across both columns.
Note that these environments have nothing to do with actually preparing your figures
or tabular material (discussed in chapters 5. and 7.); they only ensure that whatever
material is inside the environment gets “floated” and is not broken between pages.
To place the floated material, LATEX first tries to put the figure or table at the top of
the current page. If it doesn’t fit there, it next tries the bottom of the current page,
then the top of the next page. Failing that, it will try to place the figure or table on
a page containing only floated material (no text). Usually, the default behavior places
the floats satisfactorily. However, if you wish, you can supply an optional parameter to
specify a list of preferred locations; for example, if you begin a table:
\begin{table}[htp]
LATEX will first try to place the table “here”—that is, at the spot you gave the
\begin{table} command, then the top of the next page, and finally on a page con-
taining only floats (which often means on a page by itself). The possible positioning
parameters are:
h here: at the place in the text where the environment occurs.
t top: at the top of a text page.
b bottom: at the bottom of a text page.
p page: on a special page containing only floats.
37
38 ♦ Chapter 8. Placing Figures & Tables (Floats)
8.2 Examples
Note that you can put anything inside the figure environment: it can be text, a diagram,
an image (see chapter 7.) or any other kind of illustration. Likewise, a table environment
can contain any LATEX commands or text, but usually contains tabular material inside
the tabular environment (see section 5.2).
The example below encloses tabular material in the table environment, which allows it
to to float to an appropriate spot in the text. This table is floated to the top of the next
page because there is not enough room for it to be placed “here”. Note the placement
of the \caption and \label commands in this example and the example figure on the
next page.
\begin{table}[htp]
\caption{Contract Expenses to Date}
\label{tab:exp}
\begin{center}
\begin{tabular}{lr}
Item & Amount\\
\hline
Salaries (research assistants, secretary) & \$24,000 \\
Travel expenses & \$8,000 \\
Software & \$2,000 \\
\cline{2-2} \\[-8pt]
Total & \$34,000
\end{tabular}
\end{center}
\end{table}
8.2 Examples ♦ 39
The following example produces a figure that uses a line drawing of a cat, which LATEX
places “here” because there happens to be room for it. There are two versions of the
image, cat.eps and cat.pdf, so that either LATEX or pdfLATEX can be used. Note that
the \includegraphics command below does not specify an extension on the file name,
leaving it up to LATEX or pdfLATEX to find the appropriate file.
\begin{figure}[htp]
\centering
\includegraphics[angle=30,width=.6\textwidth]{cat}
\caption{A Tipsy Cat}
\label{fig:cat}
\end{figure}
41
42 ♦ Chapter 9. Preparing a Bibliography
References
[1] Leslie Lamport. LATEX – A Document Preparation System. Addison-Wesley,
Reading, MA, second edition, 1994.
[2] Helmut Kopka and Patrick W. Daly. A Guide to LATEX. Addison-Wesley, fourth
edition, Boston, MA, 2004.
[3] Michel Goossens, Frank Mittelbach et al. The LATEX Companion. Addison-
Wesley, second edition, Boston, MA, 2004.
If you want to change the heading for the reference listing, just change the value of
\refname (for article class) or \bibname (book or report class) by adding a line like this
in your preamble: \renewcommand{\bibname}{Literature Cited}.
If you like, you can choose a label to identify the work in both the text and in the
bibliography, instead of the number assigned by LATEX. You do this by including an
optional label on the \bibitem command. (The \cite command doesn’t change.) For
example, to refer to the third book as “companion,” its entry in the thebibliography
environment would be:
@article{Hefferon04,
author = "Jim Hefferon",
title = "{CTAN} for {S}tarters",
year = "2004",
journal = "{TUGB}oat",
volume = "25",
number = "2",
pages = "126--127"
}
The above example refers to an article within a journal. There are many different
document types: book, article (in a journal), article (in a collection), chapter (in a
book), thesis, report, paper (in a Proceedings), etc. There is a prescribed set of fields
for each type of document. A book entry might look like:
@book{Kopka04,
author = {Helmut Kopka and Patrick W.~Daly},
title = {Guide to {\LaTeX}},
edition = {fourth},
publisher = {Addison-Wesley},
address = {Boston, MA},
year = {2004}
}
If a work has more than one author, separate them with the keyword “and” so BibTEX
can distinguish the different names. If the BibTEX style does not preserve all your
capitalization (for example within titles), you can tell BibTEX to keep them by using
braces around the letters in question.
Suppose you have a file called myrefs.bib that contains the two bibliographics entries
above, and the file testbib.tex contains the following:
\documentclass{article}
\begin{document}
We are testing the use of Bib\TeX\ using two entries.
One is a book \cite{kopka04}, and the other is an
article in a journal. \cite{hefferon04}
\bibliographystyle{plain} % use style plain.bst
\bibliography{myrefs} % find references in myrefs.bib
\end{document}
The result of running LATEX, then BibTEX then LATEX twice more would be:
We are testing the use of BibTEX using two entries. One is a book [2],
and the other is an article in a journal. [1]
References
[1] Jim Hefferon. CTAN for Starters. TUGBoat, 25(2):126–127, 2004.
[2] Helmut Kopka and Patrick W. Daly. Guide to LATEX. Addison-Wesley,
Boston, MA, fourth edition, 2004.
We are testing the use of BibTEX using two entries. One is a book by Kopka
and Daly (2004); the second is an article in a journal (Hefferon, 2004).
References
Hefferon, J. (2004). CTAN for Starters. TUGBoat, 25(2):126–127.
Kopka, H. and Daly, P. W. (2004). Guide to LATEX. Addison-Wesley, Boston,
MA, fourth edition.
Chapter 10. Special Topics
10.1 Managing a Large Document
If you are preparing a book, thesis, or any document with multiple parts, it’s convenient
to work on the different chapters or sections separately. To do this, create a separate .tex
file for each section, and create a “root” .tex file that contains the \documentclass
command, the preamble material, the \begin{document} and \end{document} com-
mands, and multiple \include commands. The \include commands tell LATEX to read
the separate .tex files that contain the text of the document. Each \include command
starts a new page in your output. Note that the individual section files do not include
\begin{document} and \end{document} commands.
The command, \includeonly, which must go in the preamble, can be used to select
from the \include list only certain file(s) to be processed.
As an example, the root file for a book with 6 chapters might be called mybook.tex,
and the files for the chapters might be named chap1.tex, chap2.tex, etc. The root file
mybook.tex, which is the file on which you run LATEX, would look something like:
\documentclass{book}
\includeonly{chap1,chap2} % only these files will be processed
\begin{document}
\include{chap1}
\include{chap2}
\include{chap3}
\include{chap4}
\include{chap5}
\include{chap6}
\end{document}
46
10.3 Including hyperlinks ♦ 47
3. At the place you want the index to appear (usually the end of the document), put
the command: \printindex
4. Put index entries throughout the text (as close as possible to the actual word or
phrase being indexed) using the command \index{entry}, where entry is the index
entry. Examples of various index entries are shown in the table at the bottom of
the page.
Now, generate the index by running LATEX, then running makeindex, and finally running
LATEX once more. If you don’t have a “makeindex” button on the toolbar of your
editor/shell, you can run it from the command line or use the editor’s Help feature to
add it to the toolbar. Below is an example of doing the 3-step process from the command
line. Note that you should not include the filename extensions on your commands; the
programs will then do the right thing.
latex (or pdflatex) myfile In addition to producing the .dvi or pdf file, this generates
the file myfile.idx, which contains all the index entries
and page numbers.
makeindex myfile MakeIndex processes myfile.idx and produces the file
myfile.ind, which contains the LATEX commands to for-
mat the index.
latex (or pdflatex) myfile When LATEX or pdfLATEX finds the \printindex com-
mand, it reads in the file myfile.ind. The resulting out-
put includes the formatted index.
If you change your document after producing the .ind file, be sure to run MakeIndex
again to create an up-to-date .ind file before running LATEX for the final time.
The package showidx, which comes with LATEX, prints all index entries in the margin of
the text. This is a useful tool for checking the index in draft copies.
colorlinks makes the text of the link colored instead of framed with a box. It’s also pos-
sible to choose the color of the links with the linkcolor, urlcolor, and citecolor
options.
plainpages=false distinguishes between frontmatter and mainmatter page numbers.
With this option, hyperref writes different anchors for pages “ii’ and “2”.
pdfpagelabels sets PDF page labels so that Acrobat Reader displays the page number
as (say) “iv (4 of 40)” rather than simply “4 of 40”. plainpages=false and
pdfpagelabels are usually used together.
breaklinks allows a line break in a long link (such as a TOC entry). Works with
pdfLATEX only.
linktocpage makes the page number, not the text, the link in TOC, LOF, and LOT.
It’s especially useful if you use LATEX and dvips to get your PDF file, as this method
cannot use breaklinks. If you also have long URLs in the body of the thesis, the
breakurl package can help. For documentation, look on your system for the file
breakurl.pdf.
The hyperref package also provides the command \url{URL} to link to a URL from the
text, for example: \url{http://www.ctan.org/} or \url{mailto:email@email.com}.
The command \href{URL}{text} provides a more sophisticated method, where
“URL” is the address and “text” is the text displayed in the document. For
example, to avoid having the text “mailto:” appear in the document, use
\href{mailto:myfriend@rpi.edu}{myfriend@rpi.edu}.
Be sure to run LATEX or pdfLATEX twice to ensure correct hyperlinks.
The official documentation for hyperref is manual.pdf. Look for it on your system in
.../doc/latex/hyperref/.
10.4 Accents and Special Characters ♦ 49
Greek Alphabet
Miscellaneous Symbols
ℵ \aleph 0 \prime ∀ \forall
h̄\hbar ∅ \emptyset ∃ \exists
ı \imath ∇
√ \nabla ¬ \neg
\jmath \surd [ \flat
` \ell > \top \ \natural
℘ \wp ⊥ \bot ] \sharp
< \Re k \Vert or \| ♣ \clubsuit
= \Im 6 \angle ♦ \diamondsuit
∂ \partial 4 \triangle ♥ \heartsuit
∞ \infty 3 \Diamond ♠ \spadesuit
0 \mho 2 \Box \ \backslash
\sum \prod \coprod
P Q `
The symbols whose names are underlined require latexsym, a standard LATEX package.
Load it with the command: \usepackage{latexsym}.
50
♦ 51
Non-Mathematical Symbols
These symbols can be used in either text mode or math mode:
† \dag ‡ \ddag § \S ¶ \P c \copyright £ \pounds
Function Names
When using function names in a math environment, you can prefix them with a \ so
that they will print as normal text rather than in italics:
\arccos \arcsin \arctan \arg \cos \cosh
\cot \coth \csc \deg \det \dim
\exp \gcd \hom \inf \ker \lg
\lim \liminf \limsup \ln \log \max
\min \Pr \sec \sin \sinh \sup
\tan \tanh
Delimiters
The following symbols can expand in size to “fit around” the expressions they delimit. To
make a delimiter the right size, use it with the \left ... \right commands described
in section 6.6.6.
( ( ) ) b \lfloor c \rfloor
[ [ ] ] d \lceil e \rceil
{ \{ } \} h \langle i \rangle
| | k \| ↑ \uparrow ⇑ \Uparrow
/ / \ \backslash ↓ \downarrow ⇓ \Downarrow
l \updownarrow m \Updownarrow
Relational Operators
≤ \le or \leq ≥ \geq ≡ \equiv
≺ \prec \succ ∼ \sim
\preceq \succeq ' \simeq
\ll \gg \asymp
⊂ \subset ⊃ \supset ≈ \approx
⊆ \subseteq ⊇ \supseteq ∼
= \cong
< \sqsubset = \sqsupset ⊥ \perp
v \sqsubseteq w \sqsupseteq ./ \bowtie
∈ \in 3 \ni ∝ \propto
` \vdash a \dashv |= \models
.
^ \smile | \mid = \doteq
_ \frown k \parallel
6 < \not< 6 > \not> 6= \not=
Note that \not before a relation will negate it.
The symbols whose names are underlined require the latexsym package.
52 ♦ Appendix A: Mathematical Symbols
Binary Operators
± \pm ∩ \cap ∨ \vee
∓ \mp ∪ \cup ∧ \wedge
\ \setminus ] \uplus ⊕ \oplus
· \cdot u \sqcap \ominus
× \times t \sqcup ⊗ \otimes
∗ \ast / \triangleleft \oslash
? \star . \triangleright \odot
\diamond o \wr † \dagger
◦ \circ \bigcirc ‡ \ddagger
• \bullet 4 \bigtriangleup q \amalg
÷ \div 5 \bigtriangledown \lhd
\unlhd \unrhd \rhd
The symbols whose names are underlined require the latexsym package.
Math Accents
â \hat{a} ǎ \check{a} ă \breve{a}
á \acute{a} à \grave{a} ã \tilde{a}
ā \bar{a} ~a \vec{a} ȧ \dot{a}
ä \ddot{a} xd −y \widehat{x-y} xyz
g \widetilde{xyz}
Arrows
\leftarrow ←− \longleftarrow ↑ \uparrow
⇐ \Leftarrow ⇐= \Longleftarrow ⇑ \Uparrow
→ \rightarrow −→ \longrightarrow ↓ \downarrow
⇒ \Rightarrow =⇒ \Longrightarrow ⇓ \Downarrow
↔ \leftrightarrow ←→\longleftrightarrow l \updownarrow
⇔ \Leftrightarrow ⇐⇒\Longleftrightarrow m \Updownarrow
7 → \mapsto 7−→ \longmapsto % \nearrow
- \hookleftarrow ,→ \hookrightarrow & \searrow
( \leftharpoonup * \rightharpoonup . \swarrow
) \leftharpoondown + \rightharpoondown - \nwarrow
*
) \rightleftharpoons ; \leadsto
The symbols whose names are underlined require the latexsym package.
Appendix B
Error Messages
Most files need some debugging before they print properly. This section describes some
common errors and shows how to correct them.
Responding to Errors
When LATEX finds an error, it generates a message such as:
! Undefined control sequence.
l.9 \secton
{Introduction}
?
This means the \section command was misspelled, and the error occurred on line 9 of
the input file.
You can respond with:
h for help
x for exit
press the Return key to ignore it and hope for the best. LATEX will try to recover
from the error and continue processing. Sometimes you can tell from viewing the
output what went wrong.
If it stops with a * prompt, it often means you have forgotten \end{document}. Enter
it at the prompt (and fix the file later).
If you mistyped the file name or for some other reason LATEX cannot find a file, it will
ask for another filename. If you don’t want to enter a new filename, quit the program
by typing Ctrl-d or Ctrl-c. Another handy “Emergency stop sequence” is Ctrl-z.
Windows users: Do not simply close the Command window without responding!
The window may disappear but LATEX is still running, which will cause confusion when
you run it again.
53
54 ♦ Appendix B: Error Messages