La Te XManual
La Te XManual
Helin Gai
Duke University
Coleen’s Workgroup
ii
,
Contents
3 Getting Started 7
3.1 The Basics: Control Sequence and Environment . . . . . . . . . . . . . . 7
3.2 Your first masterpiece with LATEX . . . . . . . . . . . . . . . . . . . . . . 8
3.3 Typesetting Chinese in LATEX . . . . . . . . . . . . . . . . . . . . . . . . 11
3.4 A Short Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.5 Dividing your text into parts, chapters, and sections . . . . . . . . . . . 13
3.6 Options of standard document classes . . . . . . . . . . . . . . . . . . . 14
à
iv CONTENTS
,
CONTENTS v
à
vi CONTENTS
,
1
The Grand History of TEX
This purpose of this chapter is twofold: to give you a general overview of the history of
TEX/LATEX, and to help you figure out whether or not you actually need it. My personal
attitude toward the comparison of TEX and Microsoft Word is also discussed in detail.
Overall, it’s a long and potentially tedious chapter. Feel free to skip this chapter—no harm
will come, except it might take longer for you to start appreciating the beauty of TEX.
à
2 The Grand History of TEX
The first popular release, LATEX 2.09, appeared in early 1980s and Lamport claims
that it “represents a balance between functionality and ease of use.” After a few years’
development, many new functionalities were added, along with which the problem of
incompatibility arose. In hopes of bringing this situation to an end, the LATEX3 Project
was started by a group led by Frank Mittelbach. This is a long term project, and the
first big step forward is the 1994 release, LATEX 2ε , which is the focus of this book.
In Duke University, LATEX
is required of all students Today, LATEX is used by most scientists, and many presses and academic societies
in Pratt School of require or prefer submission using LATEX.
Engineering.
1.2 I saw many people arguing over the pros and cons of LATEX
versus Microsoft Word. What is your attitude?
For me, LATEX and Word are two vastly different things, both of which do their own
jobs within their own domains.
TEX, as Knuth proposed, is “a new typesetting system intended for the creation of
beautiful books—and especially for books that contain a lot of mathematics.” It is used
by authors to write their manuscript, and many publishers use it in composition. When
the major consideration is typographic quality, TEX should be chosen over Word. There
are quite a few advantages:
ligature: Compare “fi”
with “fi,” the latter
• TEX uses a very sophisticated scheme for setting type. It understands concepts
evidently looks
unprofessional.
that Word has so far ignored, e.g., ligature, kerning, and so forth.
kerning: Try “wolf” with • TEX formats the entire paragraph at a time, while Word formats the text on a
the quotation marks in line-by-line basis. It is not rare for Word to produce a very tight line followed by a
Word with Times New loose one. But this hardly ever happens in TEX, because TEX always looks back
Roman—how pathetic can and forth to determine the best breakpoints possible.
it be? To be fair, this is
the font’s fault, but to • TEX has one of the most advanced hyphenation schemes. It could hyphenate
tune it in Word is tedious. about 90% of permissible hyphen points in a dictionary. What’s more, professional
typesetting requires that no more than three hyphens should appear consecutively
In my opinion, only Adobe at the end of lines, which is a breeze to accomplish in TEX. But you have to pray
Indesign has a that your soul is pure when using Word.
hyphenation algorithm
that is comparable.
• TEX produces the most beautiful math equations in the world. A classic demo is
shown in figure 1.2.
! "
f (p) =
t>1
f (t) dπ(t) ! f ( p) = " t >1
f ( t ) d# ( t )
p prime p prime
Figure 1.2: The equation on the left is produced with TEX, while the one on the right comes out
of Microsoft Office 2003.
,
1.3 How hard is LATEX? 3
Figure 1.3: The Tracking feature in Microsoft Word is handy when a document is reviewed by
other people.
LATEX is perceived to be much easier than Word in many countries. Most authors don’t
know much detail about TEX, and yet submit papers written in LATEX with ease. The
reason is that most publishers in, say the U.S., have prepared easy-to-use class files
and templates for authors. Therefore, authors are not concerned about the style of
their documents—all they are responsible for is to put text into the pre-estabished
“framework.” In fact, the editors will get very upset if you try to change the style.
CTEX has grown into a
The situation is quite different in China. Most authors in our country have far full-fledged TEX society.
exceeded the responsibility of an author—they have to create style files so as to typeset Its official website is
their paper according to the specifications, and this is a task involving much expertise. www.ctex.org.
The CTEX Society has done a great job creating templates and class files in hopes of
easing authors’ work, but there’s much more that needs to be done. This manual is
another effort in facilitating you in your endeavor.
Many people agree that the best way to study LATEX is simply to use it. So the best
way to make full use of this book is to try out the examples and do the exercises. This
helps you understand and memorize the commands better.
An article telling my
To get started, read chapters 2 and 3, and work on the examples. You’ll understand personal story of getting
most of the basic concepts in LATEX. When you’ve completed these two chapters, you started with LATEX can be
accessed at http://bbs
à .ctex.org/forums/
index.php?showtopic=
12955.
4 The Grand History of TEX
do not need to read the remaining of the book chapter by chapter. Rather, start using
LATEX—refer to the related chapter when you’re doing specific things in LATEX. You
shouldn’t expect to master LATEX in a day or two—your patience will pay off (as Master
Yoda might say).
Actually, you probably
If you have a question and can’t find an answer in this book, you can post it in the
never ever have to master
LATEX. forum of the Chinese TEX Society (bbs.ctex.org), and you could expect to receive an
answer within 24 hours. But do a search first! The forum has been running for over four
years and the questions that people asked previously have created a huge knowledgebase.
Most of the time, your question has already been answered and it’s always a nice thing
to save others their precious time.
,
2
LATEX Singing on Your Computer
3. Register WinEdt if you’re annoyed by the pop-up windows appearing like a bomb.
If you want more flexibility, you could also try the standalone MiKTEX. TEXLive
developed by the TUG is also a nice choice.
2. The tricky part is to set up Chinese—it is a hard task because “GBKfont,” the
famous application for creating Chinese fonts, has not yet been ported to Mac OS
X. As of this writing, the easiest way to install Chinese fonts on a Mac is to copy
à
6 LATEX Singing on Your Computer
,
3
Getting Started
1. Create a file with the extension .tex using any text editor, e.g., Notepad on
Windows, or TextEditor on Mac OS X; but WinEdt and TeXShop are widely used
for this purpose.
2. Enter your text along with commands to let LATEX know how to deal with your
manuscript.
• TEX is case sensitive, so \pi, \Pi, \pI, and \PI are four different commands.
• A space must be placed after a control sequence if it’s followed by a letter. For
example, the control word \TeX produces the logo “TEX.” If you want to enter the
word “TEXpert,” the answer is not to enter \TeXpert, because TEX will think it’s
processing a command that is composed of seven letters. The correct way is to
enter ‘\TeX pert’—the space terminates the command \TeX and will not actually
produce a space.
Interestingly, \TeX3 does produce TEX3—that’s because 3 is a digit, not a letter.
• Control sequences can be followed by declarations. There are two kinds of declara-
tions: optional and required.
One example is \section[Duke]{Duke University}. This command tells LATEX
that we’re going to start a new section and the section heading is “Duke University.”
But in the table of contents, we want the heading to be displayed as “Duke.” In
this example, [Duke] is optional, and can be simply omitted; {Duke University}
is required, you must put something between the braces. In short, we put optional
stuff between brackets and required declarations between braces.
à
8 Getting Started
\begin{environment_name}
The content ...
\end{environment_name}
\begin{center}
This line should be centered.
\end{center}
,
3.2 Your first masterpiece with LATEX 9
Contents
1 Fonts 1
2 LATEX 1
“If there hadn’t been room for this material on the present page, it
would have been inserted on the next one.”
1A term that comes from an early French word meaning “molding” or “casting.”
2 Oh, try to avoid footnotes!
Figure 3.1: The final result of your first masterpiece created with LATEX.
à
10 Getting Started
8 \tableofcontents
9
27 \end{document}
Save the file and name it example-1.tex. Press the button in WinEdt, or the
button in TeXShop. A file example-1.pdf will be created and you can see the
result in that file.
Now let’s make sense of what you’ve just entered.
A class file is an actual
Line 1: The control sequence \documentclass will appear in every single one of of
physical file with the
extension .cls. your LATEX file. It loads the correct “class file,” a file that has defined all the formatting
commands that you can use. In our case, we used the article class file, because all
that we are writing is a short article. The idea of “class file” is very smart and powerful.
Suppose that you decide to submit your paper to AMS (American Mathematical
Society), all you have to do is to change article to amsart, and your paper will be
reformatted according to the specifications required by AMS. (Why don’t you go ahead
and give it a try?) Other widely used class files include book and report.
A style file is also a
Line 2: Every once in a while, you’ll want some features that are not built into
physical file with the
extension .sty. LATEX itself. But most of the features that you want have been implemented by people
all over the world. They create what we call packages (style files) so that we can use
those features. In our example, we loaded the amsmath package, which is provided by
AMS and has many enhanced features for math typesetting.
The part before \begin{document} is called the preamble.
Line 3: \begin{document} tells LATEX that you’re officially ready to start your
document.
Lines 4–6 create the title part. You enter the title of your article with the \title
command, the \author command for author; everything is straightforward. Then
\maketitle outputs this part.
You’ve probably noticed that LATEX automatically added the date. This is controlled,
as you might have guessed, by the \date command. Try enter \date{March 35, 2020}
and see what happens. Enter \date{} if you don’t want the date to be displayed.
You might also have realized that I put \ after the command \LaTeX. As I’ve
mentioned before, the space after \LaTeX will be considered as the end of the command.
So we use a control space instead to output the space.
,
3.3 Typesetting Chinese in LATEX 11
1 \documentclass{article}
2 \usepackage{ctex}
3 \usepackage{amsmath}
4 \begin{document}
5 \title{·¥©öS}
6 \author{ä>}
7 \maketitle
8
9 \tableofcontents
10
11 \section{\£}
12 ¥©m Ѭ"¤±§,\3d? §L¬§
13 ´Ø¬w«Ñ5"\±^\ ù\ /ª5r1\Ñ"=©¥m
14 ´Ø¬¯K§5¿Ñ\ZÚ§ª(J´
15 "'XµThis is a sample~)JÚ~This is a
16 sample~´vk«O"ùk:·- ¡¬¯K"¤±§
17 \TeX perts~¥m@´¬",§XJ\½@§
18 ±Ñ\~\TeX\ perts"
à
12 Getting Started
·¥©öS
ä>
2006 c 6 3 F
8¹
1 \£ 1
2 o´ TEXº 1
1 \£
¥©mѬ"¤±§,\3d? §L¬§´
جw«Ñ5"\±^ ù /ª5r1\Ñ"=©¥m´
ج¯K§5¿Ñ\ZÚ§ª(J´"'
XµThis is a sample )JÚ This is a sample ´vk«O"ùk:·
- ¡¬¯K"¤±§TEXperts ¥m@´¬"
,§XJ\½@§±Ñ\ TEX perts"
y3ëYUüg£§Òm© #ã"CTeX ¬gÄ\3c¡Ñü
Çiål"
2 o´ TEXº
TEX ´«`D>füXÚ"§Jø @õUr¿ ©(¹
üó§§õ 900 õ^-§¿ TEX k÷õU§^r±Øä/½Âg
C·^#·-5*Ð TEX XÚõU"Nõ<|^TEX Jø÷½ÂõUé
TEX ?1 gmu§Ù¥'Ͷk{IêÆÆ¬í~·ÜuêÆ
[¦^ AMS-TEX ±9·Üu©Ù!w!Ö7 LATEX XÚ"
,
3.4 A Short Summary 13
19
20 y3ëYUüg£§Òm© #ã"CTeX~¬gÄ\3c¡Ñü
21 Çiål"
\documentclass{article/book/report}
\usepackage{ctex} % if you want to typeset Chinese
\usepackage{package_name}
\begin{document}
\title{Title}
\author{Author_name}
\date{Date}
\maketitle
\tableofcontents
\section[Short_title]{Long_title}
\section{...}
\subsection{...}
\subsubsection{...}
\paragraph{...}
\subparagraph{...}
à
14 Getting Started
If you want to split your document in parts without influencing the section
numbering you can use:
\part{...}
But if you try the following code (because you’re an eager beaver),
\documentclass{book}
\begin{document}
\section{A new section}
\end{document}
you’ll experience something you wouldn’t expect—the section number is “0.1.” The
reason is that the Level-A heading in the book class is chapter, not section. (Have you
heard of the saying “Divide your article into sections, but your book into chapters”?)
So the following code fixes the problem:
\begin{document}
\chapter{A new chapter}
\section{The first section of the chapter}
\end{document}
,
3.6 Options of standard document classes 15
à
16 Getting Started
,
4
Playing with Text
This chapter focuses on how you enter text and set type. Topics covered include: how to
enter the characters not readily available on your keyboard, how to change the typeface of
your text, etc.
Every once in a while, you’ll bump into a word like cafè. If you’re using Mac OS X, this
won’t present any difficulty for you. The keyboard shortcut Option + e creates a tilde,
Interestingly, if you press
and when you press the key e again, it will be placed under the tilde:
Option + e + i, the dot of
“i” will disappear: [.
W W
If you’re using other operation system, you could use TEX’s built-in command to
do the similar thing. Table 4.1 lists all the commands for producing accents and other
international symbols.
The dotless ı and are useful if you want to put accents over the letters i and j.
Occasionally, they are also used when the baselines are very close (to achieve special
typographic effect)—this is a special occasion when typography overrides logic.
\huge\baselineskip=8pt\lineskip=-2pt
\textbf{Buy\\
Buy
\hspace*{10.5pt}R\i ght} Rıght
à
18 Playing with Text
If you can use dashes correctly, you’ve mastered more than half about TEX’s treatment
of punctuation. There are four kinds of dashes built into TEX:
• Hyphens (obtained from -) are used a lot for compound words, e.g., daughter-in-law.
It’s also used extensively for separating characters, e.g., 1-800-621-2376.
There’s actually a second
kind of hyphen (a fifth • En dashes (obtained from --) are widely used instead of “to,” and for prefixing a
kind of dash), called a soft
compound word; e.g., pages 10–20, London–Paris train, post–World War II.
hyphen, which is discussed
in section about
• Em dashes (obtained from ---) are used for punctuating a sentence—they are
hyphenation.
what we often call simply dashes.
• Minus signs (obtained from $-$) are used in math formulas a lot, e.g., −1.
You will learn that all
“inline” math equations
are placed between dollar
In some Asian countries, number ranges are indicated with a tilde (∼) instead
signs. of an en dash. This is created with the command $\sim$. For example, $-1\sim 2$
produces “−1 ∼ 2.” The advantage is that you can use negative signs with it without
causing any confusion—the notation “−1–−2” is weird and unattractive. However, if ∼
is not a tradition in your country, that is, if you’re supposed to use en dash for number
ranges, you should consider using the word “to,” e.g., “−1 to −2.”
In some European countries, an en dash is used in place of an em dash – like what
you just saw. When an en dash is used in this way, you should place a space both before
and after it. However, no spaces are required around an em dash.
Em dashes are sometimes used instead of quotation marks to set off dialogue. In
this case, you should place a space after the dash:
--- Will Colin attend your wedding?\\ — Will Colin attend your wedding?
--- Of course. — Of course.
As is mentioned before, we use two ‘ (grave accent) for opening quotation marks and ’
(vertical quote) for closing quotation marks. For single quotes, you use just one of each.
‘‘Please press the ‘x’ key.’’ “Please press the ‘x’ key.”
Quotes within quotes can be very tricky. For example, a single quote followed by
a double quote, you can’t simply type ’’’ because LATEX will interpret it as a double
quote followed by a single quote, resulting in ”’. But ’ ’’ is unacceptable either—the
space is too big for this purpose. To solve this issue, we introduce thin spaces, which
can be obtained with either \, or \thinspace:
’\,’’ ’”
,
4.2 Punctuation—what makes life/reading easier 19
Colin, come downstairs. Lee’s here. Colin, come downstairs. Lee’s here.
What you could observe is that the space after the period is slightly bigger than
the one after the comma. TEX does this because traditional typography requires a
larger space to indicate the end of a sentence. Following along the same logic, TEX
puts more space after an exclamation point (!), and a question mark (?). However, this
tradition is obsolete as this extra space is disturbing. So you should almost always
execute \frenchspacing just before the beginning of every document, instructing TEX
to treat commas and periods in the same way, like this:
\frenchspacing
Colin, come downstairs. Lee’s here.
Colin, come downstairs. Lee’s here.
TEXnicality
If you decide to follow along the old tradition (like the part you’re currently reading
does), there are a few technical details that you should pay attention to.
• “Mr. Lee” should be entered as Mr.\ Lee (or better yet, Mr.~Lee).
• A period following a capital letter does not produce the extra space. So if a
sentence ends with “U.S.,” you’ll have to tell LATEX that the period actually
indicates the end of a sentence by prefixing it with \@, i.e., U.S\@.
• Quotes and parentheses can be “transcended,” i.e., if a period appears just
before a right quote or right parenthesis, the space after the right quote and the
right parenthesis is also bigger than you would imagine. Take care to treat these
special conditions.
4.2.4 Ellipsis
Ellipsis should be used with great care. There are a few different conventions as to how
to use ellipses, but the most widely adopted method is the three-or-four-dot method.
Here’s how The Chicago Manual of Style says about it:
Three dots indicate an omission within a quoted sentence. Four mark the omission
of one or more sentences. When three are used, space occurs both before the first
dot and after the final dot. When four are used, the first dot is a true period—
that is, there is no space between it and the preceding word. What precedes and,
normally, what follows the four dots should be grammatically complete sentences
as quoted, even if part of either sentence has been omitted.
So how to produce an ellipsis? The answer is not to type three periods—the result
of ... is “...” The dots are too close to be pleasant for our eyes. LATEX provides a
command for producing ellipsis, \ldots (low dots), which gives “. . .” But this is not
à
20 Playing with Text
the end of the story, unfortunately. If you enter H \ldots H, what you get is “H . . . H,”
i.e., the space is “eaten” by TEX. The solution seems to be H \ldots\ H, in which
we use a control space, but the result became “H . . . H.” Look closely! The space on
the right hand side is slightly bigger than the one on the left. The reason is that the
definition of \ldots includes a thin space after the third dots when it is used in text
mode—this is handy if you want to put a comma after it, \ldots, gives the correct
“. . . ,”. The solution, which you probably couldn’t understand, is to use $\ldots$, so
H $\ldots$ H gives the “H . . . H,” which is perfect.
Another question to explore is how to get four dots. The logical way to do so seems
to be . $\ldots$, which gives “. . . . ” But typographic convention dictates even spaces
between the dots, so the solution seems to be use a thin space: .\,$\ldots$ which
gives “. . . .” But the best solution is to use the illogical ‘\ldots.’. (The reason is that
LATEX treats the space after a period differently from a normal word space, as is talked
about in “TEXnicality” in section 4.2.3.)
Here’s a concrete example for your reference:
The tricky part is to decide the typeface of the punctuation. One commonly asked
question is “Should the comma after an italic word be italic?” There is no consensus,
,
4.4 Controlling the size of your text 21
but I again conform to The Chicago Manual of Style, which states: “All punctuation
marks should appear in the same font—roman or italic—as the main or surrounding
text, except for punctuation that belongs to a title or an exclamation in a different
font.”
Smith played the title role in
\textit{Hamlet}, \textit{Macbeth}, and Smith played the title role in Hamlet, Mac-
\textit{King Lear}; after his final beth, and King Lear ; after his final perfor-
performance, he announced his retirement. mance, he announced his retirement.
She is the author of Who Next?
She is the author of \textit{Who Next?}
Note: In what follows . . .
\textbf{Note}: In what follows \dots
à
22 Playing with Text
# $ % ^ & _ { } ~ \
These characters are reserved by TEX to do unique things. To obtain them, prefix
them with a backslash:
Some clarification:
• \^ and \~ are special—they’re used for placing accents on letters, e.g., \^{a}
produces â, \~{e} produces ẽ. That’;s what the braces are about. They instruct
ând t̃o put the accent on nothing.
• \\ won’t work because it’s actually used to start a new line. To produce a backslash,
enter $\backslash$.
4.5.2 Ligatures
Ligatures are standard to every professional typesetting system, e.g., TEX/LATEX, Adobe
Indesign, QuarkXpress, etc. Even Apple’s standard text editor, TextEdit, has built-in
support for ligatures, but the most renowned Microsoft Office doesn’t have this feature.
Let’s take a look at some standard ligature in LATEX’s computer modern font:
\textrm{fi, fl, ff, ffi, ffl}\\ fi, fl, ff, ffi, ffl
\textbf{fi, fl, ff, ffi, ffl}\\ fi, fl, ff, ffi, ffl
\textit{fi, fl, ff, ffi, ffl}\\ fi, fl, ff, ffi, ffl
\textsl{fi, fl, ff, ffi, ffl}\\ fi, fl, ff, ffi, ffl
\textsf{fi, fl, ff, ffi, ffl}\\ fi, fl, ff, ffi, ffl
\textsc{fi, fl, ff, ffi, ffl}\\ fi, fl, ff, ffi, ffl
\texttt{fi, fl, ff, ffi, ffl} fi, fl, ff, ffi, ffl
,
4.6 Manual kerning 23
an informed decision. But the way to disable ligatures in LATEX is simply to divide the
letters up:
à
24 Playing with Text
,
5
Working with Paragraphs
Hyphenation and justification—H&J, for short—is the process a computer program uses
to fit type into lines. TEX, as I’ve mentioned a couple of times, has one of the best H&J
engines in the world by formating one paragraph at a time. This chapter helps you deal with
paragraphs in TEX more effectively. We get started with basic controls over line breaks and
such, and later get into the details of TEX’s typesetting engine.
TEX, by default, automatically divides your paragraph into lines of the same length,
using its sophisticated hyphenation and justification (H&J) scheme. But every once
in a while, you’ll want to start a new line without starting a new paragraph. You’ve
actually seen a few examples—you can do so with \\.
The command \newline produces the same effect. In addition, \\* creates a line
break but also prohibits a page break after the forced line break.
There’s also the \linebreak[n] command. The optional argument n satisfies n ∈ Z
and n ∈ [0, 4], and denotes the level you encourage a line break here. So if breaking a
line at the point you specified would produce something hideous, but meanwhile you
specified that n = 1, this command might be possibly ignored. However, \linebreak[4]
would almost always produce a line break. Also notice that the result of \linebreak
differs from that of \newline:
That is, \linebreak will justify the text. This command is quite useful when
you are fine tuning your text and have to manually interfere with the text flow. One
application is when you are setting a URL. As you’ll see later in this book, you could
use the \url{...} command provided by the URL package to typeset URLs, and these
URLs will be broken into lines if necessary. However, the way this package works is
to break after periods, while The Chicago Manual of Style requires breaking before a
period. This is the time you’ll have to interfere with LATEX. For example,
à
26 Working with Paragraphs
You could visit the site You could visit the site www.admissions
www.admissions\linebreak[0].duke.edu .duke.edu for more information about apply-
for more information about applying to Duke. ing to Duke.
\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
each line the same length. 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 samelength. line the samelength.
\end{flushright}
\begin{center}
At the centre
At the centre\\of the earth
of the earth
\end{center}
,
5.3 Shaping a paragraph 27
the white space before the section heading is exactly 20 points, so I set the paragraph
indents to be that size in order to create a sense of balance.
The second kind is the hanging indent, which starts after at least one preceding
line has been set “normal.” To achieve this effect, you need to combine two control
sequences:
\hangindent=3em \hangafter=2
Duke University is a very young school. Our
Duke University is a very young school. Our
history can be traced to as early as 1839, when
history can be traced to as early as 1839,
Brown’s school house was established.
when Brown’s school house was established.
But it was not until 1924 that Duke
But it was not until 1924 that Duke came
came into existence.
into existence.
The third kind is the running indent, which affect a series of line, at the right or
left margin, or even both. Interestingly, we could use the commands above to achieve
this effect, except that \hangindent should be set negative:
\hangindent=-3em \hangafter=2
Duke University is a very young school. Our
Duke University is a very young school. Our
history could be traced to as early as 1839,
history could be traced to as early as 1839,
when Brown’s school house was estab-
when Brown’s school house was established.
lished. But it was not until 1924 that
But it was not until 1924 that Duke came
Duke came into existence.
into existence.
\hangindent=-3em \hangafter=-2
Duke University is a very young school.
Duke University is a very young school. Our
Our history could be traced to as early
history could be traced to as early as 1839,
as 1839, when Brown’s school house was es-
when Brown’s school house was established.
tablished. But it was not until 1924 that Duke
But it was not until 1924 that Duke came
came into existence.
into existence.
As you can see \hangindent and \hangafter are very powerful, so let’s summarize
their usage a little bit: If \hangindent=x, \hangafter=n, the width of the measure is
h; then if n ≥ 0, hanging indents will occur on lines n + 1, n + 2, . . . of the paragraph,
but if n < 0, it will occur on lines 1, 2, . . . , |n|. The indented lines will be of width
h − |x|; if x ≥ 0, the lines will be indented at the left margin, otherwise at the right.
But most of the time, you probably don’t need this much power. The most
important running indents turn out to be used in quotations. And LATEX provides two
environments for this purpose: The quote environment doesn’t indent the first line
while the quotation environment does.
à
28 Working with Paragraphs
\parindent=2em
In discussing the reasons for political
disturbances Aristotle observes that In discussing the reasons for political distur-
\begin{quote} bances Aristotle observes that
revolutions also break out when opposite
revolutions also break out when opposite
parties $\ldots$ are equally balanced\dots.
parties . . . are equally balanced. . . .
\end{quote}
In discussing the reasons for political dis-
In discussing the reasons for political
turbances Aristotle observes that
disturbances Aristotle observes that
\begin{quotation} revolutions also break out when op-
revolutions also break out when opposite posite parties . . . are equally balanced. . . .
parties $\ldots$ are equally balanced\dots.
\end{quotation}
If you actually try them out, you’ll see that the final result you obtain is different
from what is shown above—both the left and the right margins are indented. And
most of the time, you wouldn’t like the default indentation value set by these two
environments. Changing the style of these environments involves more expertise, and
will be introduced in section 1.
Lastly, I’d like to introduce a command that gives you the ultimate power to control
every single line of your paragraph: \parshape. Here’s how The TEXbook describes
it:
In general, ‘\parshape=n i1 l1 i2 l2 . . . in ln ’ specifies a paragraph whose first n
lines will have lengths l1 , l2 , . . . , ln , respectively, and they will be indented from
the left margin by the respective amounts i1 , i2 , . . . , in . If the paragraph has fewer
than n lines, the additional specifications will be ignored; if it has more than n
lines, the specifications for line n will be repeated ad infinitum. You can cancel the
effect of a previously specified \parshape by saying ‘\parshape=0’.
Below is a pretty sophisticated example. You could simply ignore the part that I
use to insert the figure and focus on how I use \parshape to control the shape of the
paragraph to leave room for the figure. You’ll understand what I am doing here later in
your life.
\parshape=5
0cm 4cm 0cm 4cm
0cm 4cm 0cm 4cm 0cm \linewidth
Lee is my superfriend. He
\leavevmode\smash{\rlap{\hspace*{4.4cm}%
goes to Fudan Univer-
\lower1.2cm\hbox{%
sity and majors in Soft-
\includegraphics[width=20mm]
ware Engineering. He’s
{ColinLee.jpg}}}}%
very smart and loves playing World of War-
Lee is my superfriend. He goes to Fudan
craft very much.
University and majors in Software
Engineering. He’s very smart and loves
playing World of Warcraft very much.
The shapepar is a pretty By using \parshape, you could literally make your paragraph any shape you want.
cool package. Read But if you want your paragraph to be shaped a heart, there’s a package, shapepar, that
ftp://ftp.duke.edu/ could ease your work. The package provides a few predefined shapes that you could call
pub/tex-archive/
up by using \diamondpar, \squarepar, and \heartpar.
macros/latex/contrib/
shapepar/shapepar.pdf
for more information.
,
5.4 Reflowing the text 29
A running indent
draws the mar- gin of the type
\heartpar{A running indent draws the in from the right or left edge of the
margin of the type in from the right or text frame by a specified distance.
left edge of the text frame by a specified Typically page layout programs re-
distance. Typically page layout programs fer to these as simply left and right
refer to these as simply left and right indents. Because it is construed
indents. Because it is construed as a as a paragraph attribute, any
paragraph attribute, any left or right left or right indent will
indent will affect all lines in a paragraph.} affect all lines in a
paragraph.
♥
The website of the \ctex\ Society is The website of the CTEX Society is
www.ctex.org. www.ctex.org.
We could reflow the text by specifying a “potential” breakpoint with the \linebreak[0]
command:
The website of the \ctex\ Society is The website of the CTEX Society is www
www\linebreak[0].ctex.org. .ctex.org.
à
30 Working with Paragraphs
O
f all the great rivers of the world, none is as intriguing
as the Pearl. short by world standards, it epitomizes the
old expression that good things come in small pack-
ages. Though the Pearl measures less than 50 miles in total
length from its modest source as a cool mountain spring to the
screaming cascades and steaming estuary of its downstream
reaches, over those miles, the river has in one place or another
everything you could possibly ask for. You can roam among
lush temperate rain forests, turgid white water canyons, con-
templative meanders among aisles of staid aspens (with trout
leaping to slurp all the afternoon insects from its calm sur-
face), and forbidding swamp land as formidable as any that
Humphrey Bogart muddled through in The African Queen.
Figure 5.1: This is an example of “river” from The Complete Manual of Typography. It is more
dramatic when blurred. “There’s no avoiding them, only fixing them.”
Notice that if a linebreak at the point specified will cause dramatic ugliness,
\linebreak[0] will be ignored. The optional argument 0 works pretty well in this case,
but it takes practice to get to know the exact value that you should use.
The website of the Chinese \TeX\ Society The website of the Chinese TEX Society is
is www\linebreak[0].ctex.org. www.ctex.org.
Now let’s take a look at another example: a very short word ends a paragraph and
is set on an individual line:
\parindent=25pt
The most amazing feature of \TeX\ is that it The most amazing feature of TEX is that it
typesets your document awfully fast and typesets your document awfully fast and al-
always tries to find the best breakpoints ways tries to find the best breakpoints ever.
ever. However, sometimes, it does make mis-
takes.
However, sometimes, it does make mistakes.
This is specially bad if the paragraph indent is huge (as is shown in the previous
example), which causes much visual discomfort. There’s a simple command to deal with
this problem: \looseness. If the optimum breakpoints that TEX obtained according
to the normal procedure end up with n lines, and if \looseness=l, then TEX will try
to reflow the text so as the make the final number of lines as close a possible to n + l
without exceeding the current tolerance. Notes: 1) l could be a negative integer so that
,
5.5 Hyphenation and Justification technology 31
TEX will try to reduce the number of lines; 2) TEX only “tries” to make the number of
lines as close to n + l as possible—by no means does it mean it will actually succeed.
Naturally, we could “try” to eliminate widows and orphans in the same way.
\parindent=25pt \looseness=-1
The most amazing feature of \TeX\ is that it The most amazing feature of TEX is that
typesets your document awfully fast and it typesets your document awfully fast and
always tries to find the best breakpoints always tries to find the best breakpoints ever.
ever. However, sometimes, it does make
mistakes.
However, sometimes, it does make mistakes.
A third way is to change the value of \tolerance, which specifies how bad a
paragraph could be. (Section 5.5 gives more detail on this question.)
This paragraph is actually just fine, but maybe you think the word spaces are a
big too close and want to enlarge them to your favor. Of course, you could execute
\looseness=1 to make the paragraph one line longer. But for experiment purposes,
let’s do something more dramatic—by reducing the value of \tolerance.
\tolerance=60
Book printing differs significantly from Book printing differs significantly from ordi-
ordinary typing with respect to dashes, nary typing with respect to dashes, hyphens,
hyphens, and minus signs. In good math and minus signs. In good math books, these
books, these symbols are all different; symbols are all different; in fact there usually
in fact there usually are at least four are at least four different symbols.
different symbols.
à
32 Working with Paragraphs
hyphen points in a large dictionary, which is good enough. 2) When different sources
have different ways to hyphenate a word, TEX generally follows Webster’s, which is
the golden standard in the publishing industry. But still, the truth is that TEX does
make mistakes and cannot hyphenate every word. If the word “galaxy” needs to be
hyphenated and TEX fails to do so, you could interfere by adding discretionary breaks
(i.e., soft hyphens) manually. There are a few ways to do so. If the word galaxy appears
only once in the document, you could add these breaks with \-, e.g., gal\-axy. Another
useful command works as follows:
\discretionary{pre-break}{post-break}{no-break}
• Glue: LATEX treats every character as a box and glue is used to link the boxes
together. It’s not hard to understand what a glue is. A word space, for instance,
is a glue—it separates two word and shows up on the screen and printout as a
white space, and one fascinating feature of a word space is its ability to stretch
and shrink. But word spaces are not the only kind of glue in TEX, the space before
a heading, for example, is also a glue (at least by default).
Suppose the widths of Boxes A and B are 5 points and 6 points respectively, and
the glue between them has a natural width of 3 points, a stretchability of 3 points,
and a shrinkability of 2 points. If Boxes A and B need to be fit on a line of 14
points, that’s great, the natural width of the glue will be adopted. If the line is 16
points, then the glue will stretch by 2 points so that 5 + 6 + 3 + 2 = 16 points.
• Badness: Although word spaces are glue and can shrink and stretch, we do not
want them to shrink or stretch too much. And we first devise a way to measure
the typographic quality of the glue. The badness is defined as an integer that is
approximately 100 times the cube of the ratio by which the glue inside the line
must stretch or shrink to make the line of the required measure. If the badness
calculated exceeds 10 000, then the value 10 000 is used. For instance, if the line
has a total shrinkability of 10 points, but the glue actually shrinks by 9 points, the
badness is then 100 × (9/10)3 = 72.9 ≈ 73 (since we take the integer).
A line whose badness is 13 or more is considered “bad.” If its glue shrinks, it is
considered tight; if its glue stretches, it is loose. If the badness is 100 or more and
the line stretches, is is very loose. If the badness is 12 or less, then the line is
regarded as decent. Two adjacent lines are said to be visually incompatible if their
classifications are not adjacent.
• Penalty: A penalty represents the undesirability (“ ‘aesthetic cost’ ”) of breaking
at a certain place. For example, if the line has to break at a discretionary hyphen
(i.e., a soft hyphen), a value of 50 (as will be explained soon) will be used. In other
words, hyphenation is not that desirable in TEX’s eye[s?].
,
5.5 Hyphenation and Justification technology 33
a second attempt by using \tolerance (200 by default). Here’s a trick, if you make
\pretolerance=10000, the first pass will almost always pass, therefore hyphenations
will not be tried. But this generally results in very bad typographic quality and should
be used with great care.
So TEX will now calculate the so-called demerits for every line, by using the formula
below:
(l + b)2 + p2 , if 0 ≤ p ≤ 10 000;
d = (l + b)2 − p2 , if −10 000 < p < 0;
(l + b)2 , if p ≤ −10 000;
where l is the current value of \linepenalty (10 by default), b is the badness of the
line, and p is the penalty associated with the breakpoint.
What TEX does is simply to minimize the total demerits of an entire paragraph. In
addition, there’s a bit of more detail. If two consecutive lines are visually incompatible,
the current value of \adjdemerits is added to d (10 000 by default); if two consec-
utive lines end with a soft hyphen, the \doublehyphendemerits are added (10 000
by default); and if the second-last line of the entire paragraph is hyphenated, the
\finalhyphendemerits are added (5000 by default).
à
34 Working with Paragraphs
,
6
Elements of Your Document
Note how you can easily nest these environments, and oh, a special bonus is that
you can also use cross referencing commands as is shown above.
à
36 Elements of Your Document
\renewcommand\labelenumi{\S\theenumi.}
\begin{enumerate} §1. Hello!
\item Hello!
\item I’m a Mac! §2. I’m a Mac!
\end{enumerate}
One of the most popular list style is the circled numbering style (¬, , . . .) The
definition of the \theenumi command is tricky and you probably don’t want to get into
the detail. But the gist is the use of \protect to help such commands as \setcounter to
survive the label-generating process. You need to first load the calc and pifont packages,
then the following code will do the job:
\newcounter{local}
\renewcommand\theenumi
{\protect\setcounter{local}%
{171+\the\value{enumi}}
\protect\ding{\value{local}}} ¬ Hello!
\renewcommand\labelenumi{\theenumi}
I’m a MacBook Pro!
\begin{enumerate}
\item Hello!
\item I’m a MacBook Pro!
\end{enumerate}
,
6.3 Columns—story in the world of wide documents 37
The two major parameters that you might want to set are \columnseprule, which
controls the width of the rule (default to 0.0 pt), and \columnsep, controlling the
distance between columns (default to 10.0 pt). Here’s an example,
\setlength\columnseprule{0.5pt}
\setlength\columnsep{5pt}
\begin{multicols}{2} Anything from 45 to a single-column page
Anything from 45 to 75 characters is widely 75 characters is widely set in a serifed text
regarded as a satisfactory length of line regarded as a satisfac- face in a text size.
for a single-column page set in a serifed tory length of line for
text face in a text size.
\end{multicols}
By default, the multicol package produces balanced columns. If you wish to place
more text in the left columns, you can increase the value of the counter unbalance,
which determines the number of additional lines in the columns in comparison to the
number that the balancing routine has calculated.
\begin{multicols}{2}
\setcounter{unbalance}{1} Anything from 45 column page set in a
Anything from 45 to 75 characters is widely to 75 characters is serifed text face in a
regarded as a satisfactory length of line widely regarded as text size.
for a single-column page set in a serifed a satisfactory length
text face in a text size. of line for a single-
\end{multicols}
\begin{multicols}{2}
\setcounter{unbalance}{2} Anything from 45 serifed text face in a
Anything from 45 to 75 characters is widely to 75 characters is text size.
regarded as a satisfactory length of line widely regarded as
for a single-column page set in a serifed a satisfactory length
text face in a text size. of line for a single-
\end{multicols} column page set in a
à
38 Elements of Your Document
Before we get start with this topic, I’d like to have the honor to quote Jill Knuth,
Donald’s daughter, “Don’t use footnotes in your books, Don.” It’s true that sometimes
footnotes can be distractive, but this section assumes that they are a good thing.
To generate a footnote, simply use the command \footnote{...}. For example,
\footnote{Footnotes came ...} produces the footnote at the bottom of the page.1
There are many things you can do to change the default appearance of footnotes:
• The \thefootnote command controls the numbering style of footnotes. For exam-
ple, if you want to use symbols instead of numbers, simply type
\renewcommand\thefootnote{\fnsymbol{footnote}}.
• The \footnoterule changes the appearance of the rule. For example, if you want
to use dashed lines, use
\renewcommand\footnoterule
{\vspace*{-2pt}\dotfill\hfill\hfill\hfill\vspace{2pt}}.
• The distance between footnotes are affected with the length of \footnotesep.
• The distance between the main text and the start of the footnotes is defined by
\skip\footins.
On most occasions, it is
not a good idea to reset
footnote numbers on • The article class numbers all footnotes throughout the entire document, while the
every new page, especially book and report classes resets the footnotes every time a new chapter is started. If
you’re cross referencing you want footnote numbers to be reset on every new page, try
them. Even if you’re not, \usepackage[perpage]{footnote}.
the reader might be. It’s
always nice to bear the • If you want all footnotes to show up only in the right column in a two-column
reader in mine when document, you could use the ftnright package.
writing and designing. . . .
Two lower level command for controlling the footnote mark that I think worth
mentioning are \@makefnmark and \@makefntext. The default definitions are:
\renewcommand\@makefnmark
{\mbox{\textsuperscript{\normalfont\@thefnmark}}}
\renewcommand\@makefntext[1]
{\noindent\makebox[1.8em][r]{\@makefnmark}#1}
The book you’re reading uses a customized style, which is actually pretty popular
in the publishing industry. It is defined with the following modification to the original
definition:
\makeatletter
\renewcommand\@makefntext[1]{\noindent\@thefnmark\kern1em#1}
\makeatother
,
6.5 Programming codes 39
\renewcommand\notesname{End NOTES}
In a world of endnotes,(I) we can’t resist the
\renewcommand\theendnote{\Roman{endnote}}
temptation.(II)
\renewcommand\makeenmark
{\textsuperscript{(\theenmark)\enspace}}
In a world of endnotes,% End NOTES
\endnote{Endnotes are popular.}
we can’t resist the temptation.% (I) Endnotes are popular.
\endnote{Unless you have to.} (II) Unless you have to.
\theendnotes
\margipar[$\Rightarrow$]{$\Leftarrow$}
\verb"Hello, \TeX!"
Hello, \TeX! and Hello, \TeX!
and \verb*"Hello, \TeX!"
As you might have guessed, the star (*) version makes the spaces (more) visible.
You could also use the verbatim environment to create typed texts that are more than
one line long.
1 Footnotes should came after, not before, any punctuation.
à
40 END NOTES
An interesting package that you might want to try out is alltt, which implements
the alltt environment—it is like verbatim except that backslashes (\) and braces ({
and }) retain their usual meanings.
\begin{alltt}
\TeX\ \emph{is cool}. TEX is cool.
\begin{math}a+b\end{math} a+b
\end{alltt}
\lstset{numberstyle=\tiny,
numbers=left}
\begin{lstlisting}[language=Pascal] 1 f o r i :=1 to maxint do
for i:=1 to maxint do 2 begin
begin 3 WrItE( ’ This i s s t u p i d ’ ) ;
WrItE(’This is stupid’); 4 end .
end.
\end{lstlisting}
The detail of the package is beyond the scope of the book. But you can find
its documentation at http://www.ctan.org/tex-archive/macros/latex/contrib/
listings/listings-1.3.pdf. Have fun with it!
\mbox{text} \fbox{text}
\makebox[width][pos]{text} \framebox[width][pos]{text}
\raisebox{lift}[height][depth]{contents}
\setlength\fboxrule{2pt}
\setlength\fboxsep{2mm}
\framebox[5cm][r]{Some words}. Some words . Test Hello!
Test \raisebox{2pt}{Hello!}
\parbox[pos]{width}{text}
\begin{minipage}[pos]{width}
...
\end{minipage}
,
6.7 Index 41
\begin{minipage}[b]{12mm}
A A A A A A A A A A A A A
\end{minipage}\quad A A A
\begin{minipage}[c]{12mm} B B B
A A A
B B B B B B B B B B B B B
A C C C
\end{minipage}\quad B B B
C C C
\begin{minipage}[t]{12mm} B
C C C
C C C C C C C C C C C
\end{minipage}
\rule[lift]{width}{height}
6.7 Index
page vi:
\index{animal}
page 5:\index{animal}
page 6:\index{animal}
page 7:\index{animal}
page 11:
\index{animalism|see{animal}}
page 17:
\index{animal@\emph{animal}}
\index{mammal|textbf}
page 26: \index{animal!mammal!cat}
page 32: \index{animal!insect}
mammal, 17
6.8 Bibliography
à
42 END NOTES
,
7
LATEX with Designers
This chapter focuses on how to design with LATEX. It deals with page layout, and the design
of headers and headings. Although LATEX has its built-in mechanism for working on these
things, I will approach them with external packages for simplicity as well as power. The
design of this book is also briefed in this chapter as well. When reading this chapter, bear
in mind that the author of the book is not a professional full-time typographer and that
typography composes probably only about 1/5 of his current life.
As is stated in the introduction to this chapter, we’ll not use LATEX’ own built-in
mechanism for designing a page but the geometry package instead, because it provides
a much better and easier-to-use interface.
Here is a quote from
Shaping a page is a definite art that I haven’t quote mastered. Robert Bringhurst’s Robert Bringhurst that I
The Elements of Typographic Style provides much insight into the topic, ranging from really want to share, “A
the history of different sizes of paper to the musical notation of them. My job is to book is a flexible mirror of
tell you how to create what you want to create. Your first task should be to decide the mind and the body. Its
the size of the paper. Of course, you could simply provide an optional argument to overall size and
the \documentclass command, but using the geometry package works better most of proportions, the color and
the time. The predefined paper size include a0paper to a6paper, b0paper to b6paper, texture of the paper, the
letterpaper, exectivepaper, and legalpaper. To specify the paper size that you sound it makes as the
wanna use, simply say: pages turn, and the smell
of the paper, adhesive and
ink, all blend with with
\usepackage[letterpaper]{geometry} the size and form and
placement of the type to
Sometimes, you may want to use a paper size that is not predefined. Here’s how: reveal a little about the
world in which it was
\usepackage[paperwidth=<dimen>, paperheight=<dimen>]{geometry} made.”
or
\usepackage[papersize={width,height}]{geometry}
Going on, I’d like to introduce an easy way to place the text block. For instance,
in most institutions, professors require that papers be written on the lettersize paper
(8.5 in × 11 in) and that all margins be 1 inch wide. With this information, we can
calculate that the measure (width of the text body) and the text height should be
8.5 − 2 = 6.5 in and 11 − 2 = 9 in, respectively. Simply enter the following:
\usepackage[letterpaper,body={6.5in,9in}]{geometry}
à
44 LATEX with Designers
paper
6top head headheight
? headsep
total body total body
paperheight
height body textheight
left
- - right
(inner) (outer)
width textwidth
6bottom foot footskip
?
paperwidth
Figure 1: Dimension names used in the geometry package. width=textwidth and
Figure 7.1: height=textheight
Dimension names used byin
default.
the geometry top and bottom are margins. If margins on
package.
left, right,
verso pages are swapped by twoside option, margins specified by left and right options
are used for the inside and outside margins respectively. inner and outer are aliases of left
LATEX willandautomatically get everything else properly set up.
right respectively.
However, if you want more control over the layout, refer to figure 7.1. Most of the
parameters (a)
youdefault
might want to change is shown.(b) few missing and
A includehead ones are listed here:
includefoot
paper paper
footnotesep changes the dimension \skip\footins, separation between the bottom
of text body andhead oftop
the top 6 footnote text. 6top
?
marginparwidth6changes the width of the marginal ntoes.
head
? total body
marginparsep textheight
changes the distance between body and
6 margin notes.
textheight
You might have to play with these parameters many times and prepare a few
different sample pages
bodybefore you find the satisfactorybody
layout. But there’s a pretty
useful package, layouts, which can help you visualize your layout parameter settings.
For example, figure 7.2, which is a thumbnail of the layout of this book is generates
with the following code: ?
? foot
\newcommand\showpage{% 6
foot bottom 6bottom
\setlayoutscale{0.25} ? ?
\setlabelfont{\tiny}
%\printheadingsfalse
Figure 2: includehead and includefoot include the head and foot respectively into total body. (a)
%\printparametersfalse
height = textheight (default). (b) height = textheight + headheight + headsep +
\currentpage\pagedesign}
footskip if includehead and includefoot. If the top and bottom margins are fixed,
\showpage
includehead and includefoot make textheight shorter than default.
The circle is at 1 inch from the top and left of the page. Dashed lines represent (\hoffset + 1
inch) and (\voffset + 1 inch) from the top and left of the page.
b Header
Body
Margin
Note
Footer
Yeah, there are many arguments, and it will take a while before you get full grasp of its
capability. (Believe me, it’s very powerful!) Anyway, all the arguments are explained in
table 7.1.
For example,
\titleformat{\section}[runin]{\normalfont\scshape}
{\S\,\oldstylenums{\thesection}.}{0.5em}{}.\quad]
\titlespacing*{cmd}{left-sep}{before-sep}{after-sep}[right-sep]
You don’t have to use the starred version. The star would suppress the paragraph
indentation for the paragraph following the heading. This command is much easier than
\titleformat, and a paragraph of explanation will be more than enough:
à
46 LATEX with Designers
The left-sep argument specifies the increase of the left margin for headings with
the block, display, hang, or frame shape. With leftmargin, rightmargin, or drop
it specifies the width of the heading title, with wrap it specifies the maximum width for
the title, and with runin it specifies the indentation before the title. before-sep specifies
the vertical space added above the heading. after-sep is the distance between the title
and the following paragraph. It could be vertical or horizontal depending on the shape.
And finally, right-sep is the optional length specifying an increase of the right margin.
,
7.3 The flight of the navigator—headers 47
LEFT 1 RIGHT
...................................................
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{LEFT} \chead{\thepage} \rhead{RIGHT}
\lfoot{Foot\\ on the left}
\cfoot{}
\rfoot{Foot on the right}
\renewcommand\headrule{\dotfill}
\renewcommand\footrulewidth{0.5pt}
This is be pretty straightforward. You have to tell LATEX the kind of page style
you want to use is fancy provided by the fancyhdr package. You define the headers and
footers with \nhead and \nfoot, where n could be l (left), c (centered), and r (right).
You could customize the lines by modifying \headrule, \footrulewidth, etc.
Let’s now go straight to the second example, shown in figure 7.4.
The code used to generate the example is here:
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[RO,LE]{TITLE}
\fancyhead[LO]{\it\rightmark}
\fancyhead[RE]{\leftmark}
\fancyhead[C]{\thepage}
\fancyfoot[C]{}
\renewcommand\headrule{\hrule height2pt width\headwidth
\vspace{1pt}
\hrule height1pt width\headwidth \vspace{-4pt}}
Again, you have to specify that you’ll be using the fancy page style. All the
headers are defined with \fancyhead and \fancyfoot. (Actually you could first execute
\fancyhf{} to reset everything). You use a combination of L (left), R (right), C (centered),
O (odd-numbered pages), and E (even-numbered pages) to specify which parameter you
want to modify. The two commands \leftmark and \rightmark will be explained in
detail in section 7.4.
For example, to produce a running heading that spans marginal notes, load the
calc package, then write
\fancyheadoffset[RO,LE]{\marginparsep+\marginparwidth}
à
48 LATEX with Designers
\markboth{main_mark}{sub_mark}
\markright{sub_mark}
The first command generates a pair of markers, while changes only the sub-mark one,
inheriting the main-mark text from a previous \markboth. For instance, you can set
chapter headings as the main-marks and section headings as sub-marks.
When LATEX starts outputting pages, two other markers get involved in the picture;
namely, \leftmark contains the main-mark, and the \rightmark command contains
the current sub-mark.
These markers can be automatically generated from the corresponding heading
commands. This scheme works as follows: all standard heading commands internally
invoke a command \namemark, where name is the name of the heading command (e.g.,
\chaptermark, \sectionmark). For instance, in the book class these commands are
defined (approximately) as follows:
\renewcommand\chaptermark[1]
{\markboth{\chaptername\ \thechapter.#1}{}}
\renewcommand\sectionmark[1]{\markright{\thesection. #1}}
Knowledge is best learned in practical life. In this section, I’ll discuss how the book
you’re reading is designed, with the commands introduced in this and the preceding
chapters.
First of all, I decided that this book would be distributed over the Internet;
therefore, the only choices I have are the letter-size paper and the A4 paper. Since I’m
able to print files free of charge in the computer labs at Duke, where my education and
letter size paper are available, 8.5 × 11 inch because my apparent choice. Now let’s get
down to the design process.
,
7.5 The design of this book 49
Letter size paper is intrinsically wide, and I personally love making notes in the margin
and the bottom of the page, so I decided to give generous space to these areas. I chose
top space = inner margin space = 1.1 inches; I decided that the outer margin will be
twice as big as the inner margin space, which is 2.2 inches; and I made the bottom
space to be 1.4 inches. Now the text block has the dimension 5.2 inches × 8.5 inches.
I then decided that the running headers will be 15 points away from the text at the
The dimension of the text
top. Although the generous margin at the bottom is deliberate, I found it too blank
block is chosen with the
to be pleasing to the eye. So I decided to put some decoration symbols at the foot, golden mean in mind;
which are 0.4 inches away from the text. (I could have put the page numbers here, but 8.5/5.2 ≈ 1.63, which is
I decided to put them at the topic, sticking out in the margin to illustrate some other fairly close to the golden
commands.) I made the marginal notes to be 1.4 inches wide and 0.25 inches away from mean, 1.618.
the right margin of the text. Now everything is well planned. To get these specifications
into LATEX, I put
\usepackage[letterpaper,inner=1.1in,outer=2.2in,bottom=1.4in,
top=1.1in,headsep=15pt,headheight=12pt,marginparwidth=1.4in,
marginparsep=0.25in,footskip=0.4in]{geometry}
I decided that there will be three levels of headings, A-heads being chapters, B-heads
being sections, and C-heads being subsections.
I chose the bold sans serif typeface for chapter headings, used the Oxford style,
and decided that all the nouns, verbs and other substantive be capitalized. Since I’m
using very lively expressions (even sentences) in my section headings, I decided that
only the first letters be capitalized. But I also chose small caps as the typeface for better
visual effects. The same logic went with subsection headings. Here’s how I implemented
everything with the titlesec package:
\usepackage{titlesec}
\usepackage{color}
\definecolor{darkblue}{rgb}{0,0.08,0.45}
\titleformat{\chapter}[display]
{\normalfont\huge\sffamily\bfseries\filcenter}
{\vspace*{-2cm}
\leavevmode\leaders\vrule height7pt width3pt depth0pt%
\hfill\kern8pt\thechapter\kern8pt%
\leaders\vrule height7pt width3pt depth0pt\hfill}{3pt}
{\vspace*{-5pt}\hrule\vspace{6pt}}
[\vspace{1pt}\hrule\vspace{1cm}]
\newcommand\Bheadfont{\fontsize{11pt}{\baselineskip}\selectfont}
\titleformat{\section}[hang]
{\normalfont\sc\color{blue}\Bheadfont}
{\thesection\hskip0.618em}{0em}{}
\titlespacing*{\section}
{0pt}{15pt plus 2pt minus 2pt}{9pt plus 2pt minus 2pt}
\titleformat{\subsection}[hang]
à
50 LATEX with Designers
{\normalfont\sc\color{darkblue}}
{\thesubsection\hskip0.618em}{0em}{}
\titlespacing*{\subsection}
{0pt}{8pt plus 2pt minus 2pt}{8pt plus 2pt minus 2pt}
\titleformat{\subsubsection}[hang]{\normalfont\it}{}{0.618em}{}
\titlespacing*{\subsubsection}
{0pt}{8pt plus 2pt minus 2pt}{4pt plus 2pt minus 2pt}
7.5.3 Designing running headers
I decided to make the page numbers stick out into the margin so that the wide margin
looks less dramatic. I decided to use the chapter title (with no chapter numbers) on even-
numbered pages and section headings (with section numbers) on odd-numbered pages. I
also decided to put two small symbols at the bottom of the page to balance the generous
margin. You’ll see how I used the commands \chaptermark and \sectionmark.
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhf{}
\fancyhead[RO]
{\itshape\rightmark\mbox{\rlap{\hskip0.6cm\normalfont\bfseries\thepage}}}
\fancyhead[LE]
{\mbox{\llap{\bfseries\thepage\hskip0.6cm}}\normalfont\itshape\leftmark}
\fancyfoot[LE]{\ding{44}}
\fancyfoot[RO]{\ding{224}}
\renewcommand{\headrulewidth}{0pt}
\fancypagestyle{plain}{%
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}
}
,
8
When TEX Dates Math
When TEX dates math, math feels happy. The story of mathematics in LATEX is long and You might be surprised to
know that this chapter is
interesting (at least for me), and no doubt that the length of the chapter is pretty amazing.
It has much information about how to typeset your math properly. actually an abstraction
from my The LATEX
Mathematics Companion.
8.1 Extremely simple formulas If you are interested in
more typographic detail,
The simplest formulas are put between special math brackets, the dollar sign $ (“Because you could read the full
mathematics is supposedly expensive,” said Knuth). Here are some examples: version at http://bbs
.ctex.org/forums/
index.php?showtopic=
$-a+2b=3c-4d(5e+6f)$\\ −a + 2b = 3c − 4d(5e + 6f29603.
)
$(x+y)/(x-y)$\\ (x + y)/(x − y)
$\{a,b,c,d,e\}$ {a, b, c, d, e}
Note how TEX automatically sets all variables in an italic typeface while all
numerals are upright, which is a math tradition.
Also, if you look closely, you’ll realize that there is some extra space surrounding the
+ and − sign, but none around the / sign. That’s because TEX regards such expressions
as “1 / 2” to be incorrect. Spacing in equations can be rather challenging, but TEX has
a pretty good mechanism to cope with it automatically. So most of the time, you don’t
need to bother about that. As a matter of fact, TEX even prevents you from doing
stupid things by ignoring any spaces that you put between $’s. For example,
However, if you really need a blank space in your formula, you can type ‘\ ’. For
example, the output of ‘$2\ a$’ is ‘2 a’, which doesn’t make much sense (a little sense
though).
OK, now that you know how to get ‘a + b = c’, what about ‘α + β 6= γ’ ? Well,
you’ll find that most symbols can be obtained simply by putting their names after ‘\’.
For example, ‘α’ can be obtained by typing ‘\alpha’, ‘β’ by ‘\beta’, etc. Others might
need to be memorized, but normally they are not that hard to remember. For example,
‘6=’ is obtained by typing ‘\neq’, which is short for “not equal to.” The symbol ‘∈’
which means “is included in” can be obtained from ‘\in’.
An amazing document, “The Comprehensive LATEX Symbol List,” can be download
at http://www.ctan.org/tex-archive/info/symbols/comprehensive/symbols-letter.
pdf. You can find virtually all the symbols you need to write anything—both good and
horrifying mathematics.
à
52 When TEX Dates Math
So far, we’ve been talking about inline equations (also called in-text equations).
What if you want to center an equation on an individual line (the so-called displayed
equation)? There are a few LATEX environments that can assist you:
\begin{equation}
\delta\times\varepsilon=\theta
\end{equation} δ×ε=θ (8.1)
\begin{equation*}
\varphi-\rho\neq\kappa ϕ − ρ 6= κ
\end{equation*}
The equation environment not only centers the equation and puts it on an
individual line, it also numbers the equation automatically. The equation* environment
is a variant of equation. It does pretty much the same thing except that it doesn’t
number the equation.
In addition to equation*, you may also try out the displaymath environment.
You can even type a simple \[...\]. Some people might tell you to use $$...$$. Well,
don’t (unless you’re using plain TEX, not LATEX)! It probably gives the same result as
you want now, but later it might cause you much headache as it is not compatible with
some LATEX commands.
8.2 Super
b scripts
Super
b scripts prevail in mathematics. In computers and calculators, we frequently use ‘^’
to indicate a superscript, and ‘_’ to indicate a subscript. The same method is adopted
in LATEX:
$z^2$, $b_n$,\\ z 2 , bn ,
$x^2y^2$, $x ^2y ^2$\\ x2 y 2 , x2 y 2
$x_12$, $x^12$ x1 2, x1 2
Notice that ‘^’ and ‘_’ apply only to the next single character. If you want more
than one characters to get super
b scripted, you need to group them with braces:
Notice that it is illegal to type ‘x^y^z’ and ‘x_y_z’. Even human beings cannot
tell the exact meaning of these notations—obviously, ${x^y}^z$ (xy z ) and $x^{y^z}$
z
(xy ) are different. You have to tell TEX which one you want. As a matter of fact, the
former is quite inappropriate, if not totally wrong. You should use (xy )z , which reduces
ambiguity.
Sometimes, you might need to type something like ‘2 F3 ’, in which the subscript ‘2’
follows nothing. You can just type ‘$_2F_3$’. However, the best way would be to insert
an empty group: ‘${}_2F_3$’. (Do you know why?)
But how do we get superscripts and subscripts simultaneously, like super b scripts?
Well, you may enter the subscript and superscript in any order you want:
,
8.2 Super
b scripts 53
$x^{31415}_{92}+\pi$,
x31415
92 + π, x31415
92 +π
$x_{92}^{31415}+\pi$\\
F22 , F 22
$F_2^2$, $F{}_2^2$
One more problem about this topic: primes. To get a prime, simply enter ‘’’:
We’ve already known that Ri jkl can be obtained from $R_i{}^j{}_{\!kl}$. This is
rather hard to enter! The tensor package provides an easier solution. Here’s how:
$R\indices{_i^j_{\!kl}}$ Rijkl
You can even do some very complex things with this package:
a c a c
$\tensor[^a_b^c_d]{M}{^a_b^c_d}$ b dM b d
The two commands mentioned above also have “starred” forms, which can collapse
the spacing. This can be quite useful! For example,
14
$\tensor*[^{14}_6]{\text{C}}{}$ 6C
Since we are talking about tensor, we might as well cover vectors here. The vector
package provides some commands to ease the typesetting of vectors. Keep in mind that
the designer of the package might not necessarily abide by the rules I proposed. Anyway,
let me demonstrate some useful commands:
p = (q1 , . . . , qn )
\begin{gather*}
q1
\uvec{p}=\left(\irvec{q}\right)\\
q̂ = ...
\uuvec{q}=\left(\!\!\icvec{q}\!\!\right)\\
\buvec{r}=\{\rvec{r}{1}{6}\}\\ qn
\bvec{s}=\left[ r̂ = {r1 , r2 , r3 , r4 , r5 , r6 }
\!\!\cvec{s}{0}{2}\!\!\right]
s0
\end{gather*}
s = s1
s2
à
54 When TEX Dates Math
√
8.3 Roots
Roots are produced by ‘\sqrt[...]{...}’:
√ √ √
$\sqrt2$, $\sqrt2y$, $\sqrt{2y}$\\ √ 2, 2y, 2y
3 √
$\sqrt[3]{2}$, $\sqrt[n+1]{x+y}$ 2, n+1 x + y
√
β
Some people might find the standard k unacceptable. You can tune the position
of the index with the amsmath package.
$\sqrt[\leftroot{2}\uproot{4}\beta]{k}$, √
β √
β
$\sqrt[\leftroot{1}\uproot{3}\beta]{k}$ k, k
√ √ √
Some obsessive ones might even find x + y + z unacceptable. (I’m not among
them.) Two commands should be of help: (1) The command \mathstrut produces an
invisible box whose width is zero and whose height and depth are the height and depth
of a parenthesis ‘(’. (2) The command \smash{...} typesets its contents but ignores
both their height and depth. The amsmath package provides an optional argument, used
as follows: \smash[t]{...} ignores the height of the box’s contents, but retains the
depth, while \smash[b]{...} ignores the depth and keeps the height. Compare:
√ √ √
$\sqrt{x}+\sqrt{y}+\sqrt{z}$\\ x+ y+ z
√ p √
$\sqrt{x}+\sqrt{\mathstrut y}+\sqrt{z}$\\
√x + √ y + √ z
$\sqrt{x}+\sqrt{\smash[b]{y}}+\sqrt{z}$ x+ y+ z
Fractions
8.4 Binomials
\frac{numerator}{denominator}
What is challenging about this? Well, if you try typing a fraction in inline mode and in
display mode, you’ll find that the results are different:
$\frac{1}{2}$, 1
\begin{equation*} 2,
1
\frac{1}{2}
\end{equation*} 2
a+b
LATEX does this for a good reason: an inline ruins the line spacing, as you
c+d
can see here; a displayed
a+b
c+d
is equally unacceptable. However, you can change LATEX’s behavior by using a few
commands provided by the amsmath package: (1) \dfrac always typesets a fraction as
if it is being typeset in the display mode; (2) \tfrac always typesets a fraction as if it
is being typeset in the inline mode. For example:
,
Fractions
8.4 Binomials 55
Although amsmath makes it fairly easy to achieve whatever you want in your
manuscript, you should try not to abuse it. A general principle is that a math formula
should not affect the line spacing if at all possible. So most inline fractions should
actually be set in the slashed form (e.g., a/b) except for numerical fractions (e.g.,
1
4 ); therefore, the command \dfrac should never be used in an inline equation. Also,
fractions in subformulas (like sub- and superscripts) should also be set in the slashed
form.
The amsmath package also provides a command for typesetting continued fractions,
\cfrac. It can also be following by an optional [r] or [l] to specify the position of the
numerator:
\begin{equation*}
a_0+\cfrac{b_1}{ b1
a0 +
a_1+\cfrac[l]{b_2}{ b2
a_2+\cfrac[r]{b_3}{ a1 +
b3
a_3+\cdots}}} a2 +
a3 + · · ·
\end{equation*}
\[a_0+\frac{b_1}{a_1+}
b 1 b 2 b3
\frac{b_2}{a_2+} a0 + ···
\frac{b_3}{a_3+}\cdots\] a1 + a2 + a3 +
Binomial coefficients, like fractions, ought to be treated very carefully. The most
basic command for producing a binomial coefficient is ‘\binom{...}{...}’:
In inline mode: k2 .
In inline mode: $\binom{k}{2}$.\\
In display mode: In display mode:
\begin{equation*} \binom{k}{2}
k
\end{equation*}
2
I recommend that you use this command all the time. But if you do want to do
some crazy things, you can also use the commands \dbinom and \tbinom provided by
the amsmath package (Think a million times before you do so!!!):
à
56 When TEX Dates Math
In inline mode: $\dbinom{k}{2}$, k
which is horrible.\\ In inline mode: , which is horrible.
2
In display mode: In display mode:
\begin{equation*} \tbinom{k}{2}.
k
\end{equation*} 2 .
It might be helpful to introduce the concept of “styles.” In math mode, there are
four styles:
scriptscript For further levels of sub- and superscripting, such as subscripts of super-
scripts.
TEXnicality
In case you want to use displayed fractions in inline mode (sigh), I’d also like to
introduce two more commands that would be helpful.
First take a look at the following output:
1
This is a test. This is a test. This is a test. This is a test. This is a test.
2
This is a test. This is a test. This is a test. This is a test. This is a test.
The numerator and denominator almost touch the text above and below. But
after adding the following two lines:
\lineskiplimit=3pt
\lineskip=4pt
,
8.5 Sum and integration 57
This is actually pretty nice output. However, you might sometimes want to change
the position of the “limits.” Here’s how:
\begin{equation*} ZZ ZZ
\iint_A,\qquad \iint\limits_A ,
A
\end{equation*} A
There are a few more commands for producing different integral signs:
\begin{equation*} ZZZ Z Z I
\iiint\limits_V, , ··· ,
\idotsint\limits_V, \oint_V V
V V
\end{equation*}
Rb
There is a special symbol representing the Cauchy principal value of a f (x) dx.
It is not built into LATEX, and is so far not provided by any packages available on the
Internet. But here’s how you can construct it:
\def\Xint#1{\mathchoice
{\XXint\displaystyle\textstyle{#1}}%
{\XXint\textstyle\scriptstyle{#1}}%
{\XXint\scriptstyle
\scriptscriptstyle{#1}}%
{\XXint\scriptscriptstyle Z b
\scriptscriptstyle{#1}}% − f (x) dx
\!\int} a
\def\XXint#1#2#3{{
\setbox0=\hbox{$#1{#2#3}{\int}$}
\vcenter{\hbox{$#2#3$}}\kern-.5\wd0}}
\def\dashint{\Xint-}
\[\dashint_a^bf(x)\,\rd x\]
Sometimes, you might have to produce limits of more than one line. The amsmath
package provides the command ‘\substack’ which is helpful:
X
\[\sum_{\substack{0\leq i\leq m\\ P (i, j)
0<j<n}} P(i,j)\] 0≤i≤m
0<j<n
à
58 When TEX Dates Math
You could stop reading here. But if you want to do more crazy things, continue.
You can try the “style commands” introduced in section 8.4 to change the behavior
of TEX:
Inline: $\displaystyle\sum_{n=1}^k$,
k Z b
$\displaystyle\int_a^b$. X
Inline: , . Don’t do these!
Don’t do these!\\ a
n=1
Display: \begin{equation*} Display:
\textstyle\sum_{n=1}^k,\int_a^b. Pk Rb
n=1 , a .
\end{equation*}
The opposite of \limits is \nolimits (you need a really good reason to use it):
k
P Rb
Inline: $\sum\limits_{n=1}^k$, Inline: ,
$\int\limits_a^b$\\ n=1 a
Display:
Display: \begin{equation*}
Zb
\sum\nolimits_{n=1}^k,\int\limits_a^b Xk
\end{equation*} ,
n=1
a
8.6 Functions
Functions like sin and cos needs special treatment. For one thing, they should be typeset
in an upright typeface. In addition, they should be followed by a thin space provided
that what follows is not a parenthesis. Again, LATEX can handle the rules above most of
the time. For example,
Inline: $\lim\limits_{n\to0}
Inline: lim ((sin2 2x)/x2 ) = 1
((\sin^22x)/x^2)=1$\\ n→0
Display: \begin{equation*} Display:
\lim\nolimits_{n\to0}\frac{\sin^2x}{x^2}=1 sin2 x
limn→0 =1
\end{equation*} x2
,
8.7 Delimiters—never big enough 59
Occasionally, you’ll come across functions that are not predefined, e.g., if you type
\arccot, you’ll get an error message.
The command \DeclareMathOperator{cmd}{text} provided by the amsmath
package defines cmd to produce text in the appropriate font for “textual operators.” If
the new function being named is an operator that should, when used in displays, “take
limits” (so that any subscripts and superscripts are placed above and below), then use
the starred form \DeclareMathOperator*. For example, after defining:
\DeclareMathOperator{\arccot}{arccot}
\DeclareMathOperator\meas{meas}
\DeclareMathOperator*\esssup{ess\,sup}
you can type these commands to get amazing results:
\[
a ci
\left(\frac{a}{b}\right)
+
+\left(\frac{c}{d}\right] b d
\]
à
60 When TEX Dates Math
Table 8.2 gives all the delimiters that are recognized by TEX.
If you type ‘.’ after \left or \right, instead of specifying one of the basic
delimiters, you get the so-called null delimiter (which is blank):
\begin{equation*} a
\left(\frac{a}{b}\right.
\end{equation*} b
If you leave out the \left and \right, what you get is | − x| = | + x|. The reason
is that TEX does not really understand mathematics. It thinks that you are subtracting
‘x’ from ‘|’ and adding ‘x’ to ‘|’, resulting in the extra spaces.
However, the mechanism of \left and \right does not always work as well as
you hope:
\begin{equation*}
\left(a+(a+b)\right) (a + (a + b))
\end{equation*}
\begin{equation*}
\bigl(a+(a+b)\bigr) a + (a + b)
\end{equation*}
The \big delimiters are just enough bigger than ordinary ones so that the difference
can be perceived, yet small enough to be used in the text of a paragraph. Here are all
of them, in the ordinary size and in the \big size:
()[]{}bcdehi/\|k ↑⇑↓⇓lm
x~wx~
wyy
,
8.7 Delimiters—never big enough 61
You can also type \Bigl or \Bigr to get larger symbols suitable for displays:
hinojklmDE./ x~wx~
www
wyy
There are \biggl and \biggr versions that are 50% taller than their \big coun-
terparts:
x~wx~
www
www
wyy
Finally, there are \Biggl and \Biggr versions, 2.5 times as tall as the \bigl and
\bigr delimiters:
!"#()$%&'*+,- x~wx~
www
www
www
wyy
Any ‘\...l’ delimiter is an opening, and any ‘\...r’ is a closing. There are also
‘\...m’ for use in the middle of formulas.
\begin{equation*}
\left\{\,x\in\mathbb{R}\biggm|
5 a+1 c+1
0<\left|x\right|<\frac{5}{3}\,\right\}, x ∈ R 0 < |x| < ,
\quad\frac{a+1}{b}\bigg/\frac{c+1}{d} 3 b d
\end{equation*}
The ‘\,’ in the first example is for fine tuning. They add the so-called thin spaces.
Also note that in the second example, we use \bigg, not \biggm. That’s because
there’s no need to put extra space around ‘/’. Compare:
\begin{equation}
\frac{a+1}{b}\biggm/\frac{c+1}{d} a+1 c+1
(8.2)
\end{equation} b d
BTW, there’s a pretty nice package called braket which can greatly reduce your
effort in typesetting sets:
\begin{equation*}
\Set{x\in\mathbb{R}| 5
x ∈ R 0 < |x| <
0<\left|x\right|<\frac{5}{3}}\\ 3
\end{equation*}
Sometimes, \left and \right choose a larger delimiter than you want. You can
tune them:
\begin{equation*} !
n n
X
\left(\sum_{k=1}^n A_k \right)\quad X
Ak Ak
\biggl(\sum_{k=1}^n A_{k}\biggr)
k=1 k=1
\end{equation*}
However, most of the time, \left and \right are the clear choice. The values of
them are: (1) They are “automatic”—that’s why they produce problems sometimes;
and (2) They can produce arbitrarily large delimiters—much bigger than \biggggg!
à
62 When TEX Dates Math
What’s the word that comes up to your mind when you see the output? “Ugly,” I
suppose. This is what happens here: Only a few root signs were defined in TEX. When
they are used out, TEX will “construct” new root signs—that’s how the vertical ones
come into being. However, if you load the yhmath package, the output would be very
v
different and better:
u
uÑÐÏ
u
u ÎÍÌ
u
u sÊÉq
u
u È√
t x
v
delimiters. That is to say, virtually all large delimiters will be different from the original
uÑÐÏ
u
output of TEX. (I hardly ever use this package because although it does provide really
u ÎÍÌ
neat root signs, the parentheses are way beyond my sense of aesthetic.)
u
u sÊÉq
u
Anyway, here are a few other features of the package. It also offers some wide accents.
u È√
\widetilde{ABCDEFG} would become ABCDEF
u
You might remember that there is a limit to TEX’s commands such as \widetilde, e.g.,
t
^ G, which is awful. But after loading x
the yhmath package, the output becomes:
å
ABCDEF G
Yet, I still insist that (ABCDEF G)∼ is a better solution. Hopefully you would agree
with me.
The yhmath package also provides the amatrix environment which is used the
same as amsmath’s pmatrix, but instead of parenthesis, angles are used. For example,
you can easily construct the following:
a1 a2
a3 a4
I listed here some important features of yhmath which I think are most likely to be
used. But it has other functions. Please refer to http://texcatalogue.sarovar.org/
entries/yhmath.html.
$\mathrm{i}^2=-1$ i2 = −1
Although we write ~a, vectors in printed documents are set in boldface. Some people
like upright bold, some prefer italic bold. Both are acceptable, and here’s how to produce
them:
$\mathbf{a}$, $\bm{a}$. a, a.
(To use the command \bm, you have to load the bm package first.)
As you’ve seen in section 8.7, sets of numbers are set in what we call the Blackboard
font, e.g., R denotes the set of real numbers. Let’s take a look how to produce this:
If you use the upright ‘d’, ‘e’, and ‘i’ a lot, you should define them in your
manuscript:
\newcommand\rd{\mathrm{d}}
\newcommand\re{\mathrm{e}}
\newcommand\ri{\mathrm{i}}
Now, you can get the upright ‘d’, ‘e’, and ‘i’ by simply typing ‘\rd’, ‘\re’, and
‘\ri’:
Pr−j = 0 if r − j is odd.
à
64 When TEX Dates Math
That’s because blank spaces are ignored in math mode. Now try this:
However, the amsmath package provides a \text command which is really helpful:
\[P_{r-j}=0\text{ if
$r-j$ is odd.}\] Pr−j = 0 if r − j is odd.
One question remains: how do we get an upright lowercase greek letter? For
instance, some publishers mandates that all constants be typeset in an upright greek;
this obviously includes “pi.” Unfortunately, TEX doesn’t have built-in upright lowercase
Greek letters. But I’ve discovered a few approaches that you might want to try:
• Load the package upgreek. Then you can access upright lowercase Greek letters by
typing \up..., e.g., \uppi. This is probably the easiest way on earth, but the bad
news is that the letters produced in this method don’t look that good (for me).
• Load the package txfonts. Then you can access lowercase Greek letters by typing
\...up, e.g., \piup. But the txfonts packages affects the typeface of the whole
documents. An alternative is not to load the package and put the following codes
in your preamble:
\DeclareSymbolFont{lettersA}{U}{txmia}{m}{it}
,
8.8 Changing typefaces 65
\DeclareMathSymbol{\piup}{\mathord}{lettersA}{25}
\DeclareMathSymbol{\muup}{\mathord}{lettersA}{22}
\DeclareMathSymbol{\deltaup}{\mathord}{lettersA}{14}
......
• You can also use the PostScript symbols. Try the following codes:
\usepackage{ifthen}
\makeatletter
\newcommand{\allmodesymb}[2]{\relax\ifmmode{\mathchoice
{\mbox{\fontsize{\tf@size}{\tf@size}#1{#2}}}
{\mbox{\fontsize{\tf@size}{\tf@size}#1{#2}}}
{\mbox{\fontsize{\sf@size}{\sf@size}#1{#2}}}
{\mbox{\fontsize{\ssf@size}{\ssf@size}#1{#2}}}}
\else
\mbox{#1{#2}}\fi}
\makeatother
\newcommand{\greeksym}[1]{\usefont{U}{psy}{m}{n}#1}
\newcommand{\ualpha}{\allmodesymb{\greeksym}{a}}
\newcommand{\udelta}{\allmodesymb{\greeksym}{d}}
\newcommand{\upi}{\allmodesymb{\greeksym}{p}}
......
• The lowercase Greek letters provided by GreekTEX is rather good. But there are
(at least) two problems: (1) It might cause compatibility issues; (2) If you put the
letters in subscripts or superscripts, their size remain the same as in text style.
Anyway, here are the codes:
\input{greektex}
\newcommand\uppi{\text{\gr p}}
\newcommand\upd{\text{\gr d}}
......
TEXnicality
Some publishers require that defined operator be typeset in an upright font; e.g.,
the ‘d’ in dx. Well, the ‘d’ operator shouldn’t present any difficult for you, but the
default partial operator produced by \partial is italic, like this ‘∂’. We can define
the upright version ourselves:
\font\ursymbol=psyr at 10pt % You also use other font sizes.
\def\urpartial{\mbox{\ursymbol\char"B6}}
Now the code ‘\frac{\urpartial f}{\urpartial x}’ gives the following out-
put:
∂f
,
∂x
which is perfect!
à
66 When TEX Dates Math
8.9 Spacing
We’ve seen the command ‘\,’ which produces a thin space a couple of times. Here’s
another application:
But this is by no means the end of the story. LATEX provides quite a few commands
for producing horizontal spaces, as are listed in table 8.4.
A few words about the command \phantom in the table. By using the \phantom
command, you can reserve space for characters that do not show up in the final output:
\begin{equation*}
{}^{12}_{\phantom{1}6}\textrm{C}
\qquad \textrm{versus} \qquad 12 12
6C versus 6 C
{}^{12}_{6}\textrm{C}
\end{equation*}
TEXnicality
Most of the time, TEX can producing the desired spacing. But there are a few
occasions that require your attention:
• A thin space should be added between a number and a unit, e.g., 1 m = 100 cm.
,
8.9 Spacing 67
En (t) → e−t as t → ∞.
x(a + b) or y(a − b)
• A two-em quad should be used between two separate formulas in the same line
of a display
x2 + y 2 = a, x + y = b.
However, it is generally accepted that symbols in different formulas must be
separated by words, e.g., instead of saying “consider Sq , q < p,” write “consider
Sq , where q < p.”
• A two-em quad should be used between a symbolic statement and a condition
on the statement.
xn − y n − z n = A (n = 0, 1, . . . , p)
√
$\sqrt{2}\,x$\\ √2 x
$\sqrt{\,\lg x}$\\ lg x√
$O\bigl(1/\sqrt{n}\,\bigr)$\\ O 1/ n
$[\,0,1)$\\ [ 0, 1)
$\lg n\,(\lg\lg n)^2$\\ lg n (lg lg n)2
$x^2\!/2$\\ x2/2
$n/\!\lg n$\\ n/lg n
$\Gamma_{\!2}+\Delta^{\!2}$\\ Γ2 + ∆2
j
$R_i{}^j{}_{\!kl}$\\ R
R xi Rkly
$\int_0^x\!\int_0^y\rd F(u,v)$\\ 0 0
dF (u, v)
$(2n)!/\bigl(n!\,(n+1)!\bigr)$ (2n)!/ n! (n + 1)!
There are also a few commands controlling the vertical space in and around displays.
The vertical spaces before and after each display environment are controlled by the
following rubber lengths, where the values in parentheses are those for \normalsize
with the (default) 10pt option in the standard LATEX classes:
• \abovedisplayskip, \belowdisplayskip
The normal vertical space added above and below a mathematical display (default
10pt plus 2pt minus 5pt).
• \abovedisplayshortskip, \belowdisplayshortskip
The (usually smaller) vertical space added above and below a “short display” (0pt
à
68 When TEX Dates Math
plus 3pt and 6pt plus 3pt minus 3pt, respectively). A short display is one that
starts to the right of where the preceding text line ends.
\small
\abovedisplayshortskip=5pt
\belowdisplayshortskip=5pt
\abovedisplayskip=15pt Before
Z
\belowdisplayskip=15pt sin x
f (x) = dx (8.3)
\noindent x
Before \begin{equation} The line doesn’t end before the formula.
f(x) = \int\frac{\sin x}{x}dx
Z
\end{equation} sin x
f (x) = dx (8.4)
\noindent The line doesn’t x
end before the formula.
\begin{equation} And the next line starts as usual with some
f(x) = \int\frac{\sin x}{x}dx text. . . .
\end{equation}
\noindent And the next line starts as
usual with some text\dots.
8.10 Punctuation
In math mode, commas and semicolons are treated as punctuation marks, so TEX puts
some extra spaces after them. For example,
$f(x,y;z)$ f (x, y; z)
This is a good mechanism, but it can cause problems. In the U.S., numbers are
grouped by using commas, e.g., ‘123,456’. If you type $123,456$, what you get is
‘123, 456’. But I prefer to group numbers with a thin space, e.g., 123 456, as you’ve seen
before.
Interestingly, a period is not treated as a punctuation mark, so $123.456$ does
produce the correct ‘123.456’.
Colon is also treated as a special punctuation in TEX—representing “ratio,” e.g.,
‘3 : 4’. But it’s wrong to type something like f : A → B. Instead, try the following:
$f\mathpunct{:}A\to B$ f: A → B
As a matter of act, if you are using standard LATEX (without loading the amsmath
package), you can type $f\colon A\to B$. However, the amsmath package makes
unfortunate major changes to the spacing produced by the command \colon.
Now, let’s talk about something more general. When a formula is followed by a
period, comma, semicolon, question mark, exclamation point, etc., put the punctuation
after the $, when the formula is in the text; but put the punctuation before the end of
a display math environment. For example,
,
8.10 Punctuation 69
It should be
(Better yet, use a tie: ‘or~$c$’.) The reason is that TEX will typeset expression ‘$x=a,b$’
as a single formula, so it will put a “thin space” between the comma and the b. This
space will not be the same as the space that TEX puts after the comma following the b,
since spaces between words are always bigger than thin spaces.
Another reason for not typing $x=a,b$ is that it inhibits breaking lines in a
paragraph: TEX will never break at the space between the comma and the b because
breaks after commas in formulas are usually wrong. For example, in the equation, we
certainly don’t want to break something like P (1, 2).
We’ve talked much about ellipsis in texts. Now let’s get into the math mode. Since
we realize that \ldots does not produce a thin space after it when used in math mode,
it might cause some problems. Look at the following examples:
$a_1,a_2,a_3,\ldots$.\\ a1 , a2 , a3 , . . ..
$a_1,a_2,a_3,\ldots.$ a1 , a2 , a3 , . . . .
The first one is logical, but the output is “awesome.” The second one looks OK,
but the space after the period would be distorted since it is not really considered an
ending-a-sentence period. The correct way is to type this:
$a_1,a_2,a_3,\ldots\,$. a1 , a2 , a3 , . . . .
à
70 When TEX Dates Math
The amsmath package decides the position of the ellipsis according to what kind of
symbol follows \dots. If the next symbol is a plus sign, the dots will be centered; if it
is a comma, they will be on the baseline. If the dots fall at the end of a mathematical
formulas, the next object will be something like \end or $, etc., which does not give any
information about how to place the dots. In such a case, you must help by using \dotsc
for “dots with commas,” \dotsb for “dots with binary operator/relation symbols,”
\dotsm for “multiplication dots,” \dotsi for “dots with integrals,” or even \dotso for
“none of the above.” For example,
I also adapt the following examples from The TEXbook to illustrate the proper use
of ellipses:
$x_1+\dots+x_n$\\ x1 + · · · + xn
$x_1=\dots=x_n$\\ x1 = · · · = xn
$A_1\times\dots\times A_n$\\ A1 × · · · × An
$f(x_1,\dots,x_n)$\\ f (x1 , . . . , xn )
$x_1x_2\dots x_n$\\ x1 x2 . . . xn
$(1-x)(1-x^2)\dots(1-x^n)$\\ (1 − x)(1 − x2 ) . . . (1 − xn )
$n(n-1)\dots(1)$\\ n(n − 1) . . . (1)
$x_1\cdot x_2\cdot\ldots\cdot x_n$ x1 · x2 · . . . · xn
Caution: the example on the last line is not a typo! But it does look odd, so try to
avoid it.
is not valid, as no line breaks are allowed in an equation* environment. What about
\begin{equation*}
(a+b)^2=a^2+2ab+b^2
\end{equation*} (a + b)2 = a2 + 2ab + b2
\begin{equation*}
\sin^2\eta+\cos^2\eta=1 sin2 η + cos2 η = 1
\end{equation*}
,
8.11 More about Displayed Equations 71
You’ll find that there’s too much space between the two equations.
OK, here comes the solution: you can try the gather or gather* environment:
\begin{gather}
(a+b)^2=a^2+2ab+b^2\\ (a + b)2 = a2 + 2ab + b2 (8.5)
\sin^2\eta+\cos^2\eta=1 2 2
sin η + cos η = 1 (8.6)
\end{gather}
If you do not want the equation number, just use the starred form. What if you
want to number the first equation but not the second one?
\begin{gather}
(a+b)^2=a^2+2ab+b^2\\ (a + b)2 = a2 + 2ab + b2 (8.7)
\sin^2\eta+\cos^2\eta=1\notag 2 2
sin η + cos η = 1
\end{gather}
The gather environment is perfect for putting two or more equations on individual
lines, centered. But sometimes, we want to “align” them at a relation symbol. We can
use the align or align* environment.
\begin{align}
x^2+y^2 &= z^2\\ x2 + y 2 = z 2 (8.8)
x^3+y^3 &< z^3+\cdots 3 3 3
x + y < z + ··· (8.9)
\end{align}
Again, if you do not want the equation numbers, use the starred form.
Another challenge, what if we want to “group” these equations and “center” the
equation number vertically? The answer is to use the ...ed variant of the environments
above.
\begin{equation}
\begin{gathered}
(a+b)^2=a^2+2ab+b^2\\ (a + b)2 = a2 + 2ab + b2
\sin^2\eta+\cos^2\eta=1 (8.10)
sin2 η + cos2 η = 1
\end{gathered}
\end{equation}
Another example:
\begin{equation*}
\begin{aligned}
x^2+y^2 &= z^2\\ x2 + y 2 = z 2
x^3+y^3 &< z^3+\cdots x3 + y 3 < z 3 + · · ·
\end{aligned}
\end{equation*}
à
72 When TEX Dates Math
\begin{equation}
\begin{split}
x^2+y^2 &= z^2\\ x2 + y 2 = z 2
x^3+y^3 &< z^3+\cdots (8.11)
x3 + y 3 < z 3 + · · ·
\end{split}
\end{equation}
Remember how I talked about the “null delimiter”? Let’s take a look at its
application:
\begin{equation*}
\left.
\begin{aligned} )
\bm{B}’&=-c\nabla\times\bm{E}\\ B 0 = −c∇ × E
Maxwell’s
\bm{E}’&=c\nabla\times\bm{B}-4\pi\bm{J} E 0 = c∇ × B − 4πJ
\end{aligned}\right\}
\text{Maxwell’s}
\end{equation*}
\begin{align}
A_1&=N_0(\lambda;\Omega’)- A1 = N0 (λ; Ω0 ) − φ(λ; Ω0 ) (8.12)
\phi(\lambda;\Omega’)\\
A_2&=\phi(\lambda;\Omega’) A2 = φ(λ; Ω0 )φ(λ; Ω) (8.13)
\phi(\lambda;\Omega)
\intertext{and finally} A_3&= and finally
\mathcal{N}(\lambda;\omega) A3 = N (λ; ω) (8.14)
\end{align}
There’s a chance that TEX will break after either of the = signs (it prefers this) or
after the - or + or - (in an emergency). But there won’t be a break after the comma in
any case.
If you don’t want to permit breaking in this example except after the = signs, you
could type
,
8.13 Breaking a Displayed Equation 73
On the other hand, if you do want to break after the comma, try this:
This is not a good example. But sometimes, you might want to break something
like (x1 , . . . , xm , y1 , . . . , yn ).
Another interesting example:
anequation
$f(x,y)=x^2-y^2=(x+y)(x-y)$\\
anequation f (x, y) = x2 − y 2 = (x + y)(x − y)
anequation
anequation f (x, y) = x2 − y 2 = (x + y)(x − y)
$f(x,y)=x^2-y^2=(x+y)\*(x-y)$\\
equation f (x, y) = x2 − y 2 = (x + y)(x − y)
equation
$f(x,y)=x^2-y^2=(x+y)\*(x-y)$
The command \* acts like \-. However, instead of inserting a hyphen, a × sign is
inserted in text size.
Breaking a displayed equation is mostly not preferable, but sometimes you just have to.
Two things that you have to keep in heart when breaking a displayed equation: (1) It is
stated in The TEXbook that “Although formulas within a paragraph always break after
binary operations and relations, displayed formulas break before binary operations and
relations.” (2) Retain the logic of your math equations! I formatted the equations in
this section rather carefully, in the hope that you can figure out the rules lying behind
the surface.
The first environment to introduce is the multline environment, which does the
following:
\begin{multline}
First line of a multline
\text{First line of a multline}\\
\text{Centered Middle line}\\ Centered Middle line
\shoveright{\text{A right Middle}}\\ A right Middle
\text{Another centered Middle}\\ Another centered Middle
\text{Yet another centered Middle}\\
Yet another centered Middle
\shoveleft{\text{A left Middle}}\\
\text{Last line of the multline} A left Middle
\end{multline} Last line of the multline (8.15)
à
74 When TEX Dates Math
\begin{multline}
A=\lim_{n\to\infty}\Delta x\Bigl(a^2+
\bigl(a^2+2a\Delta x
A = lim ∆x a2 + a2 + 2a∆x + (∆x)2
+(\Delta x)^2\bigr)\\ n→∞
+ a2 + 2 × 2a∆x + 22 (∆x)2
+\bigl(a^2+2\times2a\Delta x+
2^2(\Delta x)^2\bigr)\\
+ a2 + 2 × 3a∆x + 32 (∆x)2
+\bigl(a^2+2\times3a\Delta x+
3^2(\Delta x)^2\bigr)\\ + ···
+\cdots\\
+ a2 + 2 · (n − 1)a∆x + (n − 1)2 (∆x)2
+\bigl(a^2+2\cdot(n-1)a\Delta x+
(n-1)^2(\Delta x)^2\bigr)\Bigr)\\ = 31 (b3 − a3 ). (8.16)
=\tfrac{1}{3}(b^3-a^3).
\end{multline}
\begin{align*}
(a+b)^3&=(a+b)(a+b)^2\\ (a + b)3 = (a + b)(a + b)2
&=(a+b)(a^2+2ab+b^2)\\ = (a + b)(a2 + 2ab + b2 )
&=a^3+3a^2b+3ab^2+b^3
= a3 + 3a2 b + 3ab2 + b3
\end{align*}
You can achieve the same effect with the split environment.
\begin{equation*}
\begin{split}
(a+b)^3&=(a+b)(a+b)^2\\ (a + b)3 = (a + b)(a + b)2
&=(a+b)(a^2+2ab+b^2)\\ = (a + b)(a2 + 2ab + b2 )
&=a^3+3a^2b+3ab^2+b^3 = a3 + 3a2 b + 3ab2 + b3
\end{split}
\end{equation*}
Another example. With the following codes (Pay attention to the use of the
command \quad):
\begin{verbatim}
\begin{align*}
x_nu_1+\cdots+x_{n+t-1}u_t&=
x_nu_1+(ax_n+c)u_2+\cdots\\
&\quad+\bigl(a^{t-1}x_n+
c(a^{t-2}+\cdots+1)\bigr)u_t\\
&=(u_1+au_2+\cdots+a^{t-1}u_t)x_n
+h(u_1,\ldots,u_t).
\end{align*}
\end{verbatim}
,
8.13 Breaking a Displayed Equation 75
\begin{verbatim}
\newcommand\ve{\varepsilon} \newcommand\tve{t_{\varepsilon}}
\newcommand\vf{\varphi} \newcommand\yvf{y_{\varphi}}
\newcommand\bfE{\mathbf{E}}
\newcommand\relphantom[1]{\mathrel{\phantom{#1}}}
\begin{equation}
\begin{split}
f_{h,\ve}(x,y)&=\ve\bfE_{x,y}\int_0^{\tve} L_{x,\yvf(\ve u)}\vf(x)\,\rd u\\
&=h\int L_{x,z}\vf(x)+\rho_x(\rd z)\\
&\relphantom{=}{}+h\Biggl(\frac{1}{\tve}\biggl(
\bfE_y \int_0^{\tve} L_{x,y^x(s)}\vf(x)\,\rd s\
-\tve \int L_{x,z}\vf(x)\rho_x(\rd z)\biggr)\\
&\relphantom{=}\phantom{{}+h\Biggl(}+
\frac{1}{\tve}
\biggl(\bfE_y\int_0^{\tve} L_{x,y^x(s)}\vf(x)\,\rd s
-\bfE_{x,y}\int_0^{\tve} L_{x,\yvf(\ve s)}\vf(x)\,\rd s\biggr)\Biggr)
\end{split}
\end{equation}
\end{verbatim}
Standard LATEX also provides the eqnarray environment for typesetting equations
that will spread onto a few lines. I hardly use it. But it is introduced below FYI.
\setlength\arraycolsep{2pt}
\begin{eqnarray} y =a+b+c+d
y & = & a+b+c+d\nonumber\\
+e + f + g
& & +e+f+g\nonumber\\
& & {}+h+i+j\nonumber\\ +h+i+j
& \geq & {}-k-l-m ≥ −k−l−m (8.18)
\end{eqnarray}
I have two comments: (1) Notice the use of the {}. (Can you explain what happens
right here?) (2) Setting \arraycolsep to 2 pt could give better output. (It controls the
space before and after the sign enclosed between &’s.)
By the way, by default LATEX does not allow any page break within a displayed
equation. If you do want to allow page breaks, put \allowpagebreak in the preamble
of your document.
à
76 When TEX Dates Math
8.14 Array
Arrays, in mathematics, are produced with the array environment. It has a single
argument that specifies the number of columns and the alignment of items within the
columns. For each column in the array, there is a single letter in the argument that
specifies how items in the column should be positioned: c for centered, l for flush left,
or r for flush right. Within the body of the environment, adjacent rows are separated
by a \\ command and adjacent items within a row are separated by an & character.
For example,
\[
\begin{array}{clcr}
a+b+c & uv & x-y & 27\\ a + b + c uv x−y 27
a+b & u+v & z & 134\\ a+b u+v z 134
a & 3u+uw & xyz & 2\,978 a 3u + uw xyz 2 978
\end{array}
\]
\begin{equation*}
P_{r-j}=\left\{\!\!\!
\begin{array}{ll}
0 & \text{if $r-j$ is odd,}\\ 0 if r − j is odd,
Pr−j =
r!\,(-1)^{(r-j)/2} & r! (−1)(r−j)/2 if r − j is even.
\text{if $r-j$ is even.}
\end{array}\right.
\end{equation*}
\begin{equation*}
P_{r-j}=
\begin{cases} (
0 & \text{if $r-j$ is odd,}\\ 0 if r − j is odd,
Pr−j =
r!\,(-1)^{(r-j)/2} & r! (−1)(r−j)/2 if r − j is even.
\text{if $r-j$ is even.}
\end{cases}
\end{equation*}
If you look closely at the two outputs, you’ll find that they are actually slightly
different. Coleen’s Workgroup prefers the former one, though it is more difficult to enter.
Matrices are produced in the similar way:
\begin{equation*}
\left(\!\!\!\begin{array}{cc} 0& -1\\ 0 −1
1 & 0\end{array}\!\!\!\right) 1 0
\end{equation*}
,
8.14 Array 77
\begin{gather*}
\begin{matrix}0&1\\ 1&0\end{matrix}\quad 0 1 0 1
\begin{pmatrix}0&1\\ 1&0\end{pmatrix}\\ 1 0 1 0
\begin{bmatrix}0&1\\ 1&0\end{bmatrix}\quad 0 1 0 1
\begin{Bmatrix}0&1\\ 1&0\end{Bmatrix}\\ 1 0 1 0
\begin{vmatrix}0&1\\ 1&0\end{vmatrix}\quad 0 1 0 1
\begin{Vmatrix}0&1\\ 1&0\end{Vmatrix} 1 0 1 0
\end{gather*}
There’s also a command provided by TEX that produces a special kind of matrix:
\[\bordermatrix{ 0 1 2
& 0 & 1 & 2\cr
0 A B C
0 & A & B & C\cr
1 d e f
1 & d & e & f\cr
2 1 2 3
2 & 1 & 2 & 3}\]
A final trick. Some people (including me) feel the braces are too big when used
with arrays. The following example might give you some insight:1
\[f(x)= \left\{%
\vphantom{\begin{array}{c} a\\[13ex]
\end{array}}\right.\kern-7pt
4, if x ∈ (4, ∞),
\begin{array}{ll}
3, if x ∈ (3, 4],
4, & \text{if} \quad x\in (4,\infty), \\
f (x) = 2, if x ∈ (2, 3],
3, & \text{if} \quad x\in (3,4], \\
1, if x ∈ (1, 2],
2, & \text{if} \quad x \in (2,3], \\
0, if x ∈ (−∞, 1].
1, & \text{if} \quad x \in (1,2], \\
0, & \text{if} \quad x \in (-\infty,1].
\end{array}\]
à
78 When TEX Dates Math
\[
\begin{pmat}({.|})
a_{11} & a_{12} & b_{11} \cr a11 a12 b11
a_{21} & a_{22} & b_{21} \cr\- a21 a22 b21
c_{11} & c_{12} & d_{11} \cr c11 c12 d11
\end{pmat}
\]
A lot of parameters may be changed to modify the appearance. For more in-
formation, refer to ftp://ibiblio.org/pub/packages/TeX/macros/generic/pmat/
pmat.pdf.
8.14.3 Case structures with the cases package
We already know that case structures can be constructed either with the array envi-
ronment or the cases environment provided by the amsmath package. Here is another
really useful package—cases. Its general syntax goes like this:
\begin{numcases}{left_side}
case_1 & explanation_1 \\
case_2 & explanation_2 \\
...
case_n & explanation_n
\end{numcases}
,
8.15 Dress your letters! 79
\begin{numcases}{|x|=}
x, & for $x \geq 0$\\
x, for x ≥ 0 (8.19)
-x, & for $x < 0$ |x| =
−x, for x < 0 (8.20)
\end{numcases}
\begin{verbatim}
\begin{subnumcases}{\label{w} w\equiv}
0 & $c = d = 0$\label{wzero}\\
\sqrt{|c|}\,\sqrt{\frac{1 + \sqrt{1+(d/c)^2}}{2}} & $|c| \geq |d|$ \\
\sqrt{|d|}\,\sqrt{\frac{|c/d| + \sqrt{1+(c/d)^2}}{2}} & $|c| < |d|$
\end{subnumcases}
Then, using $w$ from equation~(\ref{w}), the square root is
\begin{subnumcases}{\sqrt{c+\ri d}=}
0 & $w=0$ (case \ref{wzero})\\
w+\ri\frac{d}{2w} & $w \neq 0$, $c \geq 0$ \\
\frac{|d|}{2w} + \ri w & $w \neq 0$, $c < 0$, $d \geq 0$ \\
\frac{|d|}{2w} - \ri w & $w \neq 0$, $c < 0$, $d < 0$
\end{subnumcases}
\end{verbatim}
à
80 When TEX Dates Math
There are two more commands there are really useful: \underbrace and \overbrace.
\begin{align*}
y&=x^2+bx+c\\ y = x2 + bx + c
&=x^2+2\cdot\frac{b}{2}x+c\\ b
= x2 + 2 · x + c
&=\underbrace{x^2+2\cdot\frac{b}{2}x+ 2
2 2
\left(\frac{b}{2}\right)^2}_{\left(x+ 2 b b b
(b/2)\right)^2} =x +2· x+ − +c
2 2 2
-\left(\frac{b}{2}\right)^2+c | {z }
(x+(b/2))2
\end{align*}
∗
$\accentset{*}{d}$\\ d∗
$\accentset{*}{h}$ h
If you look at the examples very carefully, you’ll find that the accents package even
takes the skewness of letters into consideration.
The accents package also allows you to dress your letters with “shoes”:
,
8.16 Constructing New Symbols 81
$\underaccent{\bar}{x}$\\ x
¯
$\underaccent{*}{x}$ x
∗
$\vec{\mathsf{\dotlessj}}$\\ ~
$\tilde{\bm{\dotlessi}}$ ı̃
\newcommand\eqdef{%
\stackrel{\mathrm{def}}{=}} def
a = b
$a\eqdef b$
\[
0\xleftarrow[\zeta]{} F\times
∂0 α(b)
\Delta(n-1) − F × ∆(n − 1) −−−−→ E ∂0 b
0←
ζ
\xrightarrow{\partial_0\alpha(b)}
E^{\partial_0 b}\]
à
82 When TEX Dates Math
2 Examples
Examples are listed in table 8.6.
we love to love
\xlongequal: A =========== Z (1)
sub
we love to love
\xLongleftarrow: A ⇐========= Z (2)
sub
we love to love
\xLongrightarrow: A =========⇒ Z (3)
sub
we love to love
\xLongleftrightarrow: A ⇐========⇒ Z (4)
sub
we love to love
\xLeftrightarrow: A ⇐========⇒ Z (5)
sub
we love to love
\xlongleftrightarrow: A ←−−−−−−−−→ Z (6)
sub
we love to love
\xlongrightarrow: A −−−−−−−−−→ Z (7)
sub
we love to love
\xleftrightarrow: A ←−−−−−−−−→ Z (8)
sub
we love to love
\xlongleftarrow: A ←−−−−−−−−− Z (9)
sub
we love to love
(amsmath) \xleftarrow: A ←−−−−−−−−− Z (10)
sub
we love to love
(amsmath) \xrightarrow: A −−−−−−−−−→ Z (11)
sub
\xlongleftarrow: A ←−
−Z (12)
\xlongrightarrow: A −→ Z (13)
(amsmath) \xleftarrow: A←−Z (14)
(amsmath) \xrightarrow: A−→Z (15)
Let’s talk a bit more about the notation for directed line segments. Some people do not
−−→
like the notation AB and want a change. The harpoon package is a good choice.
1
,
8.18 Framed Math 83
$\overrightharp{AB}$, $\overleftharp{AB}$,
$\overrightharpdown{AB}$,
$\overleftharpdown{AB}$,
$\underrightharp{AB}$, *
AB, (
+ )
AB, AB, AB, AB, AB, AB, AB
$\underleftharp{AB}$,
* ( + )
$\underrightharpdown{AB}$,
$\underleftharpdown{AB}$
√
Let’s frame \fbox{$f(x)=\sqrt{x}$}! Let’s frame f (x) = x !
\fboxsep=1mm \fboxrule=1mm √
Let’s frame f (x) = x !
Let’s frame \fbox{$f(x)=\sqrt{x}$}!
After loading the color package, we can even frame an inline math formula in a
colored box:
√
\colorbox{yellow}{ $f(x)=\sqrt{x}$}! f (x) = x !
Now let’s do the same thing with displayed equation. Some good news for you: the
\fbox command still works.
\fbox{\parbox{0.9\linewidth}{% √
\begin{equation} f (x) = x (8.23)
f(x)=\sqrt{x}\end{equation}}}
\colorbox{yellow}{\parbox{0.9\linewidth}{% √
\begin{equation} f (x) = x (8.24)
f(x)=\sqrt{x}\end{equation}}}
If you don’t want to frame the equation number, try the \boxed command provided
by the amsmath package:
à
84 When TEX Dates Math
\begin{equation}
\boxed{W_t-F\subseteq V(P_i)\subseteq W_t} Wt − F ⊆ V (Pi ) ⊆ Wt (8.25)
\end{equation}
What if you want the box to be colored as well? We can try the empheq package.
It supports different frames for math environments of the amsmath package.
\begin{empheq}[box=\fbox]{align}
f(x)=\int_1^\infty \frac{1}{x^2}\,\rd t=1
\end{empheq} Z ∞
\begin{empheq}[box={\fboxsep=10pt 1
f (x) = dt = 1 (8.26)
\colorbox{yellow}}]{align} 1 x2
f(x)=\int_1^\infty \frac{1}{x^2}\,\rd t=1
\end{empheq} Z ∞
\begin{subequations} 1
f (x) = dt = 1 (8.27)
\begin{empheq}[box={ 1 x2
\fboxsep=1pt\colorbox{cyan}}]{align}
f(x)&=\int_1^\infty Z ∞
1
\frac{1}{x^2}\,\rd f (x) = dt = 1 (8.28a)
x2
t=1\\ Z1 ∞
1
f(x)&=\int_2^\infty \frac{1}{x^2}\,\rd f (x) = dt = 0.25 (8.28b)
t=0.25 2 x2
\end{empheq}
\end{subequations}
\begin{flalign}
x&=y & X&=Y & a&=b+c\\ x=y X=Y a = b + c (8.29)
x’&=y’ & X’&=Y’ & a’&=b x0 = y 0 X0 = Y 0 a0 = b (8.30)
\end{flalign}
Isn’t that smart? You can set the space between “column-pairs” by changing \minalignsep,
whose default value is 10pt.
\renewcommand\minalignsep{25pt}
\begin{flalign}
x=y X=Y a = b + c (8.31)
x&=y & X&=Y & a&=b+c\\
x’&=y’ & X’&=Y’ & a’&=b x0 = y 0 X0 = Y 0 a0 = b (8.32)
\end{flalign}
\begin{flalign}
x&=y && \text{by hypothesis}\tag{1}\\ x=y by hypothesis (1)
x’&=y’&&\text{by definition}\tag{*}\\ x0 = y 0 by definition (*)
x+x’&=y+y’&&\text{by Axiom 1}\tag{$*$} x + x0 = y + y 0 by Axiom 1 (∗)
\end{flalign}
,
8.20 Footnotes in Math Mode 85
\begin{verbatim}
\begin{displaymath}
a+b=c+d\footnotemark
\end{displaymath}
\footnotetext{Here comes the footnote
in math mode. Hooray!!!}
\end{verbatim}
a + b = c + d2
The first “crazy” thing you might want to do is to put the equation number on the
left side of your document. To do this is easy—you just turn “on” the leqno option
of your document class, e.g., \documentclass[leqno]{article}. The premise is that
the document class in question provides the leqno option. If not, you can achieve this
by giving options to your amsmath package. To place equation numbers on the left,
say ‘\usepackage[leqno]{amsmath}’. To place equation numbers on the right, say
‘\usepackage[reqno]{amsmath}’, which is the default value.
Going on, let’s talk about the style of equation numbers. This book is prepared
with the standard LATEX book class. Equation numbers take the form “chapter num-
ber + equation number within the chapter.” You can change this by redefining the
\theequation command. For example,
\renewcommand\theequation{
\thesection-\roman{equation}}
\begin{equation} a+b=c+d (8.21-xxxiii)
a+b=c+d
\end{equation}
If you want to make the equation numbers to go like “chapter number + equation
number within section,” the amsmath package provides a useful command:
\numberwithin{equation}{section}.
Another topic: sub-equations. The amsmath package provides some useful com-
mands:
à
86 When TEX Dates Math
\begin{subequations}
\begin{align}
y&=d\\ y=d (8.34a)
y&=cx+d\\ y = cx + d (8.34b)
y&=bx^2+cx+d\\
y = bx2 + cx + d (8.34c)
y&=ax^3+bx^2+cx+d
3 2
\end{align} y = ax + bx + cx + d (8.34d)
\end{subequations}
OK, now let’s try modifying the equation numbers of the sub-equations:
\renewcommand\theequation{%
\theparentequation{}-\arabic{equation}}
\begin{subequations}
\begin{align} y=d (34-35a)
y&=d\\ y = cx + d (34-35b)
y&=cx+d\\
y = bx2 + cx + d (34-35c)
y&=bx^2+cx+d\\
3 2
y&=ax^3+bx^2+cx+d y = ax + bx + cx + d (34-35d)
\end{align}
\end{subequations}
First an equation.
\begin{equation}\label{e:previous}
A=B First an equation.
\end{equation}
A=B (8.36)
That was equation \eqref{e:previous}.
That was equation (8.36).
Then the same, with a prime on the number.
\begin{equation} Then the same, with a prime on the number.
\tag{\ref{e:previous}$’$}
C=D (8.360 )
\label{e:prevprime}
C=D And that was equation (8.360 ).
\end{equation}
And that was equation \eqref{e:prevprime}.
Notice, by the way, that when a \ref occurs inside a \tag, and that \tag is
then \label’d, a \ref for the the second \label requires three runs of LATEX in order
to get the proper value. (If you run through the logic of LATEX’s cross-referencing
mechanisms as they apply in this case, you will see that this is necessary.) Note the use
of \eqref: instead of simply giving the “number,” it also enclose the equation number
in parentheses.
I don’t know why anyone wants to do this, but here is the solution just in case.3
3 Provided by mytex of the CTEX Community.
,
8.22 A List of Options of the amsmath Package 87
\makeatletter
\def\xlabel#1#2{%
{\@bsphack\protected@write\@auxout{}%
{\string\newlabel{#2}{{#1}{\thepage}}}%
\@esphack}{\mathrm(#1)}}
\makeatother
(H1) x=y+z (1)
\begin{flalign} (H2) a = b2 + c2 − a (2)
\xlabel{H1}{eq:refL}&&x=y+z&&
\label{eq:ee1}\\
\xlabel{H2}{eq:xxy}&&a=b^2+c^2-a&&
\label{eq:ee2}
\end{flalign}
\begin{subeqnarray}
\label{eqw} \slabel{eq0}
x & = & a \times b \\
\slabel{eq1} x = a×b (8.37a)
& = & z + t\\ = z+t (8.37b)
\slabel{eq2}
= z+t (8.37c)
& = & z + t
\end{subeqnarray} The first equation is number (8.37a), the last
The first equation is number~\eqref{eq0}, is (8.37c). The equation as a whole can be
the last is~\eqref{eq2}. The referred to as equation (8.37).
equation as a whole can be referred to as
equation~\eqref{eqw}.
0 Exercise
• centertags
(default) Place equation numbers vertically centered on the total height of the
equation when using the split environment.
à
88 When TEX Dates Math
• tbtags
If the equation numbers are on the right, place equation numbers level with the
last line. If the equation numbers are on the left, place equation numbers level with
the first line.
• sumlimimts
(default) Place the subscripts and superscripts of summation symbols above and
below,
Q N in displayed equations. It also affects other symbols of the same type, e.g.,
, . However, it doesn’t affect integrals.
• nosumlimits
Place the subscripts and superscripts of summation-type symbols to the side, even
in displayed equations.
• intlimits
It is just like sumlimits, but it works for integral symbols.
• nointlimits
(default) Opposite of intlimits.
• namelimits
(default) It is just like sumlimits, but it works for functions, e.g., det, lim, etc.,
which traditionally have subscripts placed underneath when they occur in a dis-
played equation.
• nonamelimits
You can guess its function, can’t you?
Some commands for producing simple commutative diagrams based on arrays are
available in the amscd package. It provides some useful shorthand forms for specifying
the decorated arrows and other connectors.
In the CD environment the notations @>>>, @<<<, @VVV, and @AAA give right, left,
down, and up arrows, respectively. For example,
Decorations on the arrows are specified as follows. For the horizontal arrows,
material between the first and second > or < symbols will be typeset as a superscript,
and material between the second and third will be typeset as a subscript. Similarly,
material between the first and second, or second and third, As or Vs of vertical arrows
will be typeset as left or right “side-scripts”.
The notations @= and @| give horizontal and vertical double lines.
A “null arrow” (produced by @) can be used instead of a visible arrow to fill out
an array where needed.
,
8.24 Coloring Your Math—The color Package 89
\[\begin{CD}
j
S^{W_\Lambda}\otimes T @>j>> S WΛ ⊗ T −−−−→ T
T \\
@VVV @VV{\mathop{\rm End} P}V\\ y yEnd P
(S\otimes T)/I @= (Z\otimes T)/J (S ⊗ T )/I (Z ⊗ T )/J
\end{CD}\]
\begin{equation}
\textcolor{blue}{f(x)}=\int_1^\infty Z ∞
1
\textcolor{red}{\frac{1}{x^2}}\,\rd x=1 f (x) = dx = 1 (8.38)
1 x2
\end{equation}
Here comes a package that is better at math than I am. An example should shed some
light on its usage:
x2 + 2x + 2
x−1 x3 + x2 −1
− x3 + x2
2x2
\polylongdiv{x^3+x^2-1}{x-1}
− 2x2 + 2x
2x − 1
− 2x + 2
1
1 1 0 −1
\polyhornerscheme[x=1]{x^3+x^2-1} 1 1 2 2
1 2 2 1
√ √
1 1 13 1 13
\polyfactorize{2x^3+x^2-7x+3} 2 x− 2 x+ 2 + 2 x+ 2 − 2
à
90 When TEX Dates Math
6x2 − 4x − 2 = 49 x − 94 · 27 9
2 x+ 2 +0
15707
2 31415
20000
11415
10000
\longdiv{31415}{2}
1415
1400
15
14
1
\mathlig{->}{\rightarrow}
\mathlig{<-}{\leftarrow} →, ←, ↔
\mathlig{<->}{\leftrightarrow}
$->$, $<-$, $<->$
8.27 Miscellaneous
8.27.1 Canceling out—The cancel Package
Another short section. (Happy?) After loading the cancel package, you can do this:
,
8.27 Miscellaneous 91
the number and the unit. You should remember that I have said that a thin space is
preferable! (3) The nicefrac package has two options, nice and ugly. We’ll talk a little
bit about them in a short while. (4) Options specified for the units package will be
passed on to the nicefrac package. (5) The nicefrac package can be used independently.
Let’s now take a look how this package can be used. Suppose no options are
specified; i.e., the options tight and nice are used, this is what you are going to get:
\unit[20]{cm}\\ 20 cm
\unitfrac[20]{m}{s}\\ 20 m/s
\nicefrac[\textsf]{m}{s} m/s
The maybemath package provides a set of commands for adjusting math mode typesetting
to match the context of the surrounding paragraph.
For context-sensitive boldness use \maybebm:
à
92 When TEX Dates Math
Normal $x^2+\maybebmsf{x^3}+\cdots$\\
Normal x2 + x3 + · · ·
\textbf{$x^2+\maybebmsf{x^3}+\cdots$}\\
x2 + x3 + · · ·
\textsf{$x^2+\maybebmsf{x^3}+\cdots$}\\
x2 + x3 + · · ·
\textbf{\textsf{$x^2+\maybebmsf{x^3}+
x2 + x3 + · · ·
\cdots$}}
The most important application of this package is to control the font in titles. If you
are using the default book or article class files, type things like ‘\section{... $\maybebm{...}$}’
to get the correct font.
The nccmath package extends the amsmath package. It also improves spacing control
before display equations and fixes a bug of ignoring the \displaybreak in the amsmath
version of the equation environment.
Its first feature is a modification to the \intertext command:
a + b = c + d.
\begin{align*}
a+b&=c+d.
\intertext[1cm]{Therefore,} Therefore,
e+f&=g+h.
\end{align*}
e + f = g + h.
As you can see, the additional option can specify a vertical space inserted before
and after the text. If it is omitted, standard TEX’s skips are inserted.
It also allows you to create a series of medium-sized mathematics:
\[\medmath{\cfrac{1}{\sqrt 2 + 1
1
\cfrac{1}{\sqrt 2 +\dotsb}}}
√ 1 √ 1
\quad \cfrac{1}{\sqrt 2 +\cfrac{1} 2+ √ 2+ √
2 + ···
{\sqrt 2 +\dotsb}}\] 2 + ···
X XX
$\sum_{i=1}^n \medop\sum_{i=1}^n
\displaystyle\sum\nolimits_{i=1}^n$ Xn n n n
Pn n P
\quad $\sum\limits_{i=1}^n i=1 i=1 i=1 i=1 i=1 i=1
\displaystyle \medop\sum_{i=1}^n
\sum_{i=1}^n$
,
8.28 Two Powerful Packages Mentioned Merely in Passing 93
There are also commands for producing medium-sized integral, fractions, binomial
coefficient, and matrix.
$\int_a^b\medint\int_a^b
\displaystyle\int_a^b$\quad
Rb Z b
Z b RR b ZZ b
a a a a
$\iint_a^b\medint\iint_a^b$ a
$\frac{x+y}{a-b} \mfrac{x+y}{a-b}
\dfrac{x+y}{a-b}$\quad x+y x + y x+y n
n n
$\binom{n}{k} \mbinom{n}{k} a−b a − b a−b k k k
\dbinom{n}{k}$
$\bigl(\begin{smallmatrix} a&b\\c&d
\end{smallmatrix}\bigr)$
$\Bigl(\begin{mmatrix} a&b\\c&d a b
a b a b
\end{mmatrix}\Bigr)$ c d c d c d
$\begin{pmatrix} a&b\\c&d
\end{pmatrix}$
à
94 When TEX Dates Math
,
9
Tables and Graphics
Graphics are always a good thing—they are not miserable to look at, they increase the
length of your paper dramatically. . . . They are just great!
In Microsoft Word, you can insert a graphics by “drag-and-drop.” In LATEX, you
don’t even need to drag and drop. For example, if you have a photo named ColinLee.jpg,
you need to: 1) drag and picture into the folder where the TEX file you’re compiling
lives, 2) load the grahpicx package, and 3) now you could insert the picture into your
document like this:
\includegraphics[width=3cm]{ColinLee.jpg}
This book recommends that you use the PDF-LATEX typesetting engine which support
JPEG and PDF files pretty well. If you’re using the default LATEX engine, your best
choice is to use EPS files. If you use files that are not in the EPS format, you’ll have
to specify the bounding box yourself or create a .bb file to help LATEX decides the
bounding box of the image. On the contrary, PDF-LATEX does not support EPS files.
bb=10 20 100 200 sets
As you’ve seen in the example, the \includegraphics command could be followed the left bottom point of
by optional argument. width is one of them; there are also height, totalheight, scale the bounding box to be
(this should be a number), angle, origin (the point that the image rotates along) and (10, 20) and the top right
bb. point to be (100, 200).
We get started with a simple table that illustrates most of LATEX’s own commands for
constructing tables.
à
96 Tables and Graphics
\begin{tabular}{|r|c|r|}
\hline
\multicolumn{3}{|c|}{AT\&T Common Stock}\\ AT&T Common Stock
\hline
Year Price Dividend
Year & Price & \multicolumn{1}{c|}{Dividend}\\
1971 41–54 $2.60
\hline
2 41–54 2.70
1971 & 41--54 & \$2.60\\\hline
3 46–55 2.97
2 & 41--54 & 2.70\\\cline{2-3}
3 & 46--55 & 2.97\\\hline
\end{tabular}
As you can see, a table is created with the tabular environment. We set up the
general layout of the table by providing special argument right after \begin{tabular},
using a combination of c (centered), r (right-aligned), l (left-aligned), and p{width}
(a column with automatic line breaks to cater to the specified width). Vertical lines are
specified with ‘|’.
Columns are separated with & (You don’t need to put a & before the first column
though). In other words, a & indicates a jump to the next column. \\ simply starts a
new row and the \hline command produces a horizontal line. Of course, two \hline’s
produce two consecutive horizontal lines. Sometimes, you might want a horizontal line
for just a few of the columns; this is done with the \cline{a-b}” command, where
a is the index number of starting column, and b is the number of the ending column.
For instance, in our example, \cline{2-3} produces a partial horizontal line under the
second and the third columns.
We could “merge cells” with \multicolumn{number }{position}{text}. The number
parameter specifies the total number of cells to merge; the position parameter specifies
how to align the text in the cell; and of course, you need to provide what text to
be placed in the merged cell. You might be wondering why I “merged” one cell in
the example. The reason is that all the text in this column has been specified to be
right-aligned, and I want to center the text in this cell. The \multicolumn command
provides a perfect work around.
There’s one more thing that can be useful in specifying the general layout of the
table: @{...}. It eliminates the space between any two columns and replaces it with the
... that you provide. As you could imagine, if you say r@{}l, then the right-aligned
column will literally “kiss” the left-aligned column. Here’s a very good example from
The Not So Short Introduction to LATEX 2ε with some minor modification:
\begin{tabular}{c r @{.} l}
\hline
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 \\
\hline
\end{tabular}
A recent trend is that the design of tables is getting simpler—most modern tables
have no vertical lines and few horizontal lines (like the ones you’ve seen in this book).
LATEX is quite capable of producing these tables, but the booktabs provides a few
commands that is going to ease your work a lot!
,
9.3 Tables that travel a long way 97
1 2
Figure 9.1: Tables that travel a long way
\tiny
\def\figurespace{\phantom{0}}
\begin{tabular}{@{}crrrr@{}}
\toprule
&\multicolumn{2}{c}{Export contracts (\%)}
&\multicolumn{2}{c}{Import contracts (\%)}\\ Export contracts (%) Import contracts (%)
\begin{longtable}{@{}lll@{}}
\caption{The ISOGRK3 entity set}\\
\toprule
Entity & Unicode Name & Unicode \\ \midrule
\endfirsthead
\multicolumn{3}{r}{Continued from previous page}\\
\toprule
Entity & Unicode Name & Unicode \\ \midrule
à
98 Tables and Graphics
\endhead
\midrule
\multicolumn{3}{r}{Continued on next page}
\endfoot
\bottomrule
\endlastfoot
alpha & GREEK SMALL LETTER ALPHA & 03BA\\
alpha & GREEK SMALL LETTER ALPHA & 03BA\\
alpha & GREEK SMALL LETTER ALPHA & 03BA\\
alpha & GREEK SMALL LETTER ALPHA & 03BA\\
alpha & GREEK SMALL LETTER ALPHA & 03BA\\
alpha & GREEK SMALL LETTER ALPHA & 03BA\\
......
Using \begin{tabular} and \includegraphics orders LATEX to place the table and
image “here,” and without a caption. But most publications today require a more
flexible mechanism—tables and figures are hardly placed right after a paragraph, and it
is generally agreed that such statements as “Refer to the figure below:” are bad and
should be replaced with something similar to “Refer to figure 3.14.” Luckily, LATEX is
born with the support for such “floating bodies.”
A floating figure is created with the figure environment and a floating table is
constructed with table.
For example, figure 9.2 is created with
\begin{figure}[bt]
\includegraphics[width=3cm]{ColinLee.jpg}
\caption{A picture of Colin and his super friend, Lee.}
\label{samplefigure}
\end{figure}
\begin{table}[tbhp]
\centering
\caption{...}
\begin{tabular}
...
\end{tabular}
\end{table}
,
9.5 Customizing your captions 99
You might have noticed that there are a few optional arguments immediately
following \begin{table} and \begin{figure}. There are actually give of them in
total and you can use a combination of any one of them. t stands for top, b for bottom,
p for page, h for here, and ! means to ignore most of the internal parameters (e.g., the
maximum number of floats allowed on a page). Then [tb] means that LATEXcould place
the figure at the top or at the bottom of a page. Note that h doesn’t necessarily mean
that LATEX will place the figure here, but that LATEX will try its best to put it here. If
the page doesn’t have enough space to hold the figure, a different parameter will be
chosen.
Table 9.1 lists some of the most important parameters for controlling the floating
environments.
\usepackage[textfont={rm,it},labelfont{sf}]{caption}
\captionsetup[type]{option-value-list}
The advantage is that you’ll be able to specify the “type” of caption that you want to
define. For example, if you say \captionsetup[figure], only the caption of figures
will be affected.
à
100 Tables and Graphics
The captions in this book are set up with the following code:
\DeclareCaptionFont{blue}{\color{blue}}
\captionsetup{justification=raggedright,
singlelinecheck=false,font={blue,sf,small}}