La Te X Manual 8 6
User Manual:
Open the PDF directly: View PDF
.
Page Count: 106
| Download | |
| Open PDF In Browser | View PDF |
The Art of LATEX
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
Helin Gai
Duke University
Coleen’s Workgroup
ii
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
,
Contents
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
1 The Grand History of TEX
1.1 How did LATEX come into existence? . . . .
1.2 I saw many people arguing over the pros
Microsoft Word. What is your attitude? . .
1.3 How hard is LATEX? . . . . . . . . . . . . .
1.4 How to study LATEX? . . . . . . . . . . . . .
. . . . . . . . . . .
and cons of LATEX
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
1
1
. . . . .
versus
. . . . .
. . . . .
. . . . .
2
3
3
2 LATEX Singing on Your Computer
2.1 What’s the easiest way to install LATEX on Microsoft Windows? . . . . .
2.2 What if I own a glorious Mac? . . . . . . . . . . . . . . . . . . . . . . .
2.3 How about us Linux users? . . . . . . . . . . . . . . . . . . . . . . . . .
5
5
5
6
3 Getting Started
3.1 The Basics: Control Sequence and Environment . . .
3.2 Your first masterpiece with LATEX . . . . . . . . . . .
3.3 Typesetting Chinese in LATEX . . . . . . . . . . . . .
3.4 A Short Summary . . . . . . . . . . . . . . . . . . .
3.5 Dividing your text into parts, chapters, and sections
3.6 Options of standard document classes . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
7
7
8
11
13
13
14
4 Playing with Text
4.1 International characters . . . . . . . . . . . . . .
4.2 Punctuation—what makes life/reading easier . .
4.2.1 Dash—your first lesson with punctuation
4.2.2 Quotation marks . . . . . . . . . . . . . .
4.2.3 Comma and Period . . . . . . . . . . . . .
4.2.4 Ellipsis . . . . . . . . . . . . . . . . . . .
4.3 Changing typefaces . . . . . . . . . . . . . . . . .
4.4 Controlling the size of your text . . . . . . . . . .
4.5 Is what you type what you get? . . . . . . . . . .
4.5.1 Special characters that make TEX scream
4.5.2 Ligatures . . . . . . . . . . . . . . . . . .
4.6 Manual kerning . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
17
17
18
18
18
19
19
20
21
22
22
22
23
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
5 Working with Paragraphs
25
5.1 Manual line and page breaks . . . . . . . . . . . . . . . . . . . . . . . . 25
5.2 Moving your text horizontally . . . . . . . . . . . . . . . . . . . . . . . . 26
5.3 Shaping a paragraph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
à
iv
CONTENTS
5.4
5.5
Reflowing the text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Hyphenation and Justification technology . . . . . . . . . . . . . . . . .
6 Elements of Your Document
6.1 Cross References . . . . . . . . . . .
6.2 Listing items . . . . . . . . . . . . .
6.3 Columns—story in the world of wide
6.4 Notes, notes, and notes . . . . . . .
6.4.1 When footnotes rule . . . . . .
6.4.2 Notes at the end of a chapter
6.4.3 Notes dancing in the margin
6.5 Programming codes . . . . . . . . .
6.6 Making boxes . . . . . . . . . . . . .
6.7 Index . . . . . . . . . . . . . . . . .
6.8 Bibliography . . . . . . . . . . . . .
29
31
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
35
35
35
37
38
38
39
39
39
40
41
41
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
43
43
44
46
47
48
48
49
49
8 When TEX Dates Math
8.1 Extremely simple formulas . . . . . . . . . . . . . .
8.2 Super
b scripts . . . . . . . . . . . . . . . . . . . . . .
8.2.1 The tensor Package . . . . . . . . . . . . . .
8.2.2 The vector Package . . . . . . . . . . . . . .
√
8.3
Roots . . . . . . . . . . . . . . . . . . . . . . . .
Fractions
8.4 Binomials
. . . . . . . . . . . . . . . . . . . . . . .
8.5 Sum and integration . . . . . . . . . . . . . . . . .
8.6 Functions . . . . . . . . . . . . . . . . . . . . . . .
8.7 Delimiters—never big enough . . . . . . . . . . . .
8.7.1 Larggggge Delimiters—The yhmath Package
8.8 Changing typefaces . . . . . . . . . . . . . . . . . .
8.9 Spacing . . . . . . . . . . . . . . . . . . . . . . . .
8.10 Punctuation . . . . . . . . . . . . . . . . . . . . . .
8.11 More about Displayed Equations . . . . . . . . . .
8.12 Breaking an Inline Equation . . . . . . . . . . . . .
8.13 Breaking a Displayed Equation . . . . . . . . . . .
8.14 Array . . . . . . . . . . . . . . . . . . . . . . . . .
8.14.1 The delarray Package . . . . . . . . . . . . .
8.14.2 Partitioned matrices . . . . . . . . . . . . .
8.14.3 Case structures with the cases package . . .
8.15 Dress your letters! . . . . . . . . . . . . . . . . . .
8.15.1 More Accents: The accents Package . . . . .
8.15.2 “ı” in Different Fonts—The dotlessi package
8.15.3 The undertilde Package . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
51
51
52
53
53
54
54
57
58
59
62
62
65
68
70
72
73
75
77
77
78
79
80
80
81
. . . . . . .
. . . . . . .
documents
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
7 LATEX with Designers
7.1 Balancing the elements that live on a page . .
7.2 Dressing the headings . . . . . . . . . . . . .
7.3 The flight of the navigator—headers . . . . .
7.4 A not so short short introduction to markers
7.5 The design of this book . . . . . . . . . . . .
7.5.1 Shaping the page . . . . . . . . . . . .
7.5.2 Designing headings . . . . . . . . . . .
7.5.3 Designing running headers . . . . . . .
,
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
CONTENTS
8.16 Constructing New Symbols . . . . . . . . . . . . . . . .
8.17 Extensible arrows . . . . . . . . . . . . . . . . . . . . . .
8.17.1 Extensible arrows with the extarrows package . .
8.17.2 The harpoon Package . . . . . . . . . . . . . . . .
8.18 Framed Math . . . . . . . . . . . . . . . . . . . . . . . .
8.19 Aligning Your Equations . . . . . . . . . . . . . . . . . .
8.20 Footnotes in Math Mode . . . . . . . . . . . . . . . . . .
8.21 Equation Numbers . . . . . . . . . . . . . . . . . . . . .
8.21.1 Prime Equation Numbers . . . . . . . . . . . . .
8.21.2 Equation Numbers on Both Sides . . . . . . . . .
8.21.3 Equation numbers with the subeqnarray package
8.22 A List of Options of the amsmath Package . . . . . . . .
8.23 Commutative Diagrams—The amscd Package . . . . . .
8.24 Coloring Your Math—The color Package . . . . . . . . .
8.25 Packages Smarter Than Me . . . . . . . . . . . . . . . .
8.25.1 The polynom package . . . . . . . . . . . . . . .
8.25.2 The longdiv package . . . . . . . . . . . . . . . .
8.26 The mathlig Package . . . . . . . . . . . . . . . . . . . .
8.27 Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . .
8.27.1 Canceling out—The cancel Package . . . . . . . .
8.27.2 The units and nicefrac Packages . . . . . . . . . .
8.27.3 Math in Titles—The maybemath Package . . . .
8.27.4 The nccmath Package . . . . . . . . . . . . . . .
8.28 Two Powerful Packages Mentioned Merely in Passing . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
81
81
81
81
82
84
84
85
86
86
86
87
88
88
88
88
89
90
90
90
90
90
91
92
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
95
95
95
97
98
99
v
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
9 Tables and Graphics
9.1 External graphics are a lot of fun .
9.2 Structuring a table . . . . . . . . .
9.3 Tables that travel a long way . . .
9.4 Floating tables and figures around
9.5 Customizing your captions . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
à
vi
CONTENTS
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
,
1
The Grand History of TEX
This chapter gives you a general overview of the history of TEX/LATEX and helps you evaluate
whether or not you actually need it. My personal attitude toward the comparison between
TEX and Microsoft Word is also discussed in detail. It’s a bit long and tedious, as I want
to include the information I really like. Feel free to skip this chapter—no harm will come,
except it might take longer for you to start appreciating the beauty of TEX.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
1.1 How did LATEX come into existence?
The journey begins with Donald Ervin Knuth and his TEX. Knuth (born January 10,
1938) is a renowned computer scientist and Professor Emeritus of the Art of Computer
Programming at Stanford University. He was the 1974 Turing Award winner and more
or less defined the field “Computer Science” as it is today.
In 1977, Knuth devoted most of his time writing The Art of Computer Programming.
After he got the proofs of the second volume on March 30, he felt greatly discouraged
and wrote in his diary:
Figure 1.1: Knuth (pronounced /knu:θ/) is the
father of TEX. [My special
thanks to Zhichu Chen for
helping me troubleshoot
the code for creating this
marginal figure.]
Galley proofs for vol. 2 finally arrive, they look awful (typographically) . . . I decide
I have to solve the problem myself.
And so he did. On May 5, he started his major design on TEX—a typesetting system
that he could use to create beautiful books.
Knuth planned to finish the project in 1978, but it eventually took him more than
a decade—it was not until 1989 that the language of TEX was frozen. Knuth invented
what he called “literate programming,” a way of producing compilable source code and
high quality cross-linked documentation (typeset in TEX) from the same original file.
The language used is called WEB and produces programs in Pascal.
Since version 3, TEX has used an idiosyncratic version numbering system, where
updates have been indicated by adding an extra digit at the end of the decimal, so
that the version number asymptotically approaches π. The current version of TEX is
3.141592; it was last updated in December 2002. Knuth has stated that the “absolutely
final change (to be made after [his] death)” will be to change the version number to π,
at which point all remaining bugs will become features.
Although TEX is powerful, many people find it too powerful to master, especially
when it comes to layout design. Based on the idea that authors should be able to
concentrate on writing within the logical structure of their document, rather than
spending their time on the details of formatting, Leslie Lamport implemented LATEX.
With LATEX, you are not supposed to be concerned about the style—everything
should be pre-defined and fully at your call. You enter your text and LATEX takes care
of the formatting. In this sense, LATEX is much easier to use than TEX. As a matter of
fact, you can literally learn to compose a paper including a table of contents and an
index within an hour or so.
à
TEX is pronounced /tεx/.
The current and the next
paragraphs use material
from Wikipedia.
LATEX is pronounced
/leitεx/ or /la:tεx/.
2
In Duke University, LATEX
is required of all students
in Pratt School of
Engineering.
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.
Today, LATEX is used by most scientists, and many presses and academic societies
require or prefer submission using LATEX.
1.2 I saw many people arguing over the pros and cons of LATEX
versus Microsoft Word. What is your attitude?
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
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
evidently looks
unprofessional.
• TEX uses a very sophisticated scheme for setting type. It understands concepts
that Word has so far ignored, e.g., ligature, kerning, and so forth.
• TEX formats the entire paragraph at a time, while Word formats the text on a
line-by-line basis. It is not rare for Word to produce a very tight line followed by a
loose one. But this hardly ever happens in TEX, because TEX always looks back
and forth to determine the best breakpoints possible.
kerning: Try “wolf” with
the quotation marks in
Word with Times New
Roman—how pathetic can
it be? To be fair, this is
the font’s fault, but to
tune it in Word is tedious.
• TEX has one of the most advanced hyphenation schemes. It could hyphenate
about 90% of permissible hyphen points in a dictionary. What’s more, professional
typesetting requires that no more than three hyphens should appear consecutively
at the end of lines, which is a breeze to accomplish in TEX. But you have to pray
that your soul is pure when using Word.
In my opinion, only Adobe
Indesign has a
hyphenation algorithm
that is comparable.
• TEX produces the most beautiful math equations in the world. A classic demo is
shown in figure 1.2.
!
p prime
f (p) =
"
t>1
f (t) dπ(t)
! f ( p) = "
p prime
t >1
f ( t ) d# ( t )
Figure 1.2: The equation on the left is produced with TEX, while the one on the right comes out
of Microsoft Office 2003.
In short, Word is not suitable for professional typesetting—it is merely a word
processor. I use it extensively for file exchange. Sometimes, I would even paste an entire
TEX source file into a Word document, so that my friend can mark on it with the
“Tracking” feature (figure 1.3). When I get the document back, it’s very easy for me to
see what changes are made and I can make my decision about whether or not to accept
these changes.
,
1.3 How hard is LATEX?
3
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
Figure 1.3: The Tracking feature in Microsoft Word is handy when a document is reviewed by
other people.
1.3 How hard is LATEX?
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.
The situation is quite different in China. Most authors in our country have far
exceeded the responsibility of an author—they have to create style files so as to typeset
their paper according to the specifications, and this is a task involving much expertise.
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.
CTEX has grown into a
full-fledged TEX society.
Its official website is
www.ctex.org.
1.4 How to study LATEX?
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.
To get started, read chapters 2 and 3, and work on the examples. You’ll understand
most of the basic concepts in LATEX. When you’ve completed these two chapters, you
à
An article telling my
personal story of getting
started with LATEX can be
accessed at http://bbs
.ctex.org/forums/
index.php?showtopic=
12955.
4
Actually, you probably
never ever have to master
LATEX.
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).
If you have a question and can’t find an answer in this book, you can post it in the
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.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
,
2
LATEX Singing on Your Computer
2.1 What’s the easiest way to install LATEX on Microsoft Windows?
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
The easiest way to set up LATEX on Windows is to use the CTEX Suite. The CTEX Suite
is based on MiKTEX, with various useful applications bundled. It provides complete
support for CCT and CJK, two leading Chinese processing system. The advantage of
the CTEX Suite is that it is foolproof—keep clicking “Next,” and everything will be
properly set up, including the difficult Chinese configuration. The current CTEX Suite
includes MiKTEX, WinEdt, GSview, Ghostscript, etc.
1. Go to http://www.ctex.org/CTeXDownload and download the latest CTEX Suite.
There are currently four choices available: the Full version, the Basic version, the
Full Update version, and the Basic update version.
I recommend the Basic version over Full. MiKTEX 2.4 and later supports “installation on-the-fly,” so when you use a package that isn’t installed yet, MiKTEX will
automatically download and install it.
The download might take a while. Be patient and God bless your Internet connection.
When it’s downloaded, double-click and follow the instruction on the screen.
2. On the same page, download CTEX-Fonts, and install it.
3. Register WinEdt if you’re annoyed by the pop-up windows appearing like a bomb.
4. Congratulations. You’re all set!
If you want more flexibility, you could also try the standalone MiKTEX. TEXLive
developed by the TUG is also a nice choice.
2.2 What if I own a glorious Mac?
The easiest way to install TEX on a Mac is to use MacTEX.
1. Go to http://www.tug.org/ftp/tex/mactex/ and download the latest MacTEX.
As of March 2006, MacTEX has been released as a universal binary and runs
natively on both PowerPC- and Intel-based Macs.
MacTEX will install TEX, XeTEX, Ghostscript, ConTEXt, MusixTEX, ImageMagick,
TeXShop, BibDesk, Excalibur, i-Installer, etc.
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
à
The CTEX Suite is
developed by Lingyun Wu.
6
LATEX Singing on Your Computer
everything in the localtexmf folder of CTEX Suite to /usr/local/teTeX/share/
texmf.local.
Then go to texmf.local/pdftex/config, make a copy of psfonts.map and rename it to pdftex.map. In Terminal, type “sudo mktexlsr,” and this should
work.
(Some people have reported that the map file in certain versions of the CTEX
Suite doesn’t work. If you followed the instruction I give here and didn’t solve the
problem, please send an email to me hg9@duke.edu and I’ll send you a map file
that proves to work.)
Other installation options include i-installer, Fink, TEXLive, etc., which give you more
flexibility.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
2.3 How about us Linux users?
The best TEX distribution on Linux is teTEX. The following installation procedure is
documented and maintained by lapackapi of the CTEX Society, and it works pretty well
on Fedora Core.
1. Go to http://www.tug.org/tetex/ and download teTEX. Install it according to
the instruction coming along with the distribution. If you are using Fedora Core,
you could easily install it from your system installation disk.
2. Install tetex-afm and fontforge:
yum install tetex-afm fontforge
3. Download CCT and CJK:
wget
wget
wget
wget
wget
wget
ftp://ftp.cc.ac.cn/pub/cct/Linux/cct-0.6180-3a.i386.rpm
ftp://ftp.cc.ac.cn/pub/cct/Linux/cct-fonts-1.2-0.i386.rpm
ftp://ftp.cc.ac.cn/pub/cct/CJK/CJK-GBKfonts-0.3-15.i386.rpm
ftp://ftp.cc.ac.cn/pub/cct/CJK/ctex-0.7-1.i386.rpm
ftp://ftp.cc.ac.cn/pub/cct/CJK/CJK-4.6.0-0.src.rpm
ftp://ftp.cc.ac.cn/pub/cct/CJK/dvipdfmx-20050307-3zlb.src.rpm
4. Compile the last two packages:
rpmbuild --rebuild *.src.rpm
A few rpm packages will be created in /usr/src/redhat/RPMS/i386/. We can
now safely remove the source packages:
rm *.src.rpm
5. Copy the rpm packages to the current working directory:
cp /usr/src/redhat/RPMS/i386/* .
6. Install the packages:
rpm -ivh *.rpm
7. Install Chinese fonts. Get the font files ready. Suppose you have a font file called
songti.ttf, then simply enter
gbkfont-inst songti.ttf song
,
3
Getting Started
3.1 The Basics: Control Sequence and Environment
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
One advantage/disadvantage of TEX is that it is not wysiwyg (what-you-see-is-whatyou-get), but wytiwyg (what-you-think-is-what-you-get). The general procedure is:
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.
3. Compile it with LATEX to obtain the final result.
We get started by introducing two fundamental concepts: control sequence and
environment.
A control sequence is a kind of command that starts with a backslash (\). There
are two kinds of control sequences. A control word consists of a backslash followed by
one or more letters. For example, the control word ‘\tableofcontents’ instructs LATEX
to automatically prepare, format, and output the table of contents. There are a few
more notes about control words:
• 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 declarations: 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.
à
“\” is called the escape
character.
8
Getting Started
The second kind of control sequence is a control symbol, consisting of a backslash
followed by a single nonletter. In this case, you don’t need a space to tell TEX where
it ends. (Why does this make sense?) For example, \, produces a “thin space” (e.g.,
1\,cm produces ‘1 cm’).
Example 3.1 What are the control sequences in ‘\’m \exercise3.1\\!’ ?
Answer There are three control sequences. \’ is a control symbol; \exercise is a
control word; and \\ is another control symbol.
Example 3.2 \LaTeX can be used to produce the logo “LATEX.” What do you think
the result of ‘\LaTeX is great’ be?
Answer The result would be ‘LATEXis great’.
Example 3.3 The command \input1 will input a file named 1.tex. What do you
think \input123 will do?
Answer The command \input123 will input a file named 1.tex and then outputs the
digits ‘23’. If you want to input a file named 123.tex, you should enter \input{123}.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
Example 3.4 Suppose you know that the control sequence \includegraphics can
be used to put an external figure into your TEX output. How do you think you could
include a figure lee.jpg with a width of 3 cm?
Answer We can imagine that \includegraphics definitely require a file name after it,
so the file name should be a required argument. Meanwhile, since LATEX is super-smart,
we have reason to believe that if we do not specify a width, LATEX can process that
automatically; therefore, the width should be optional. So we guess that we should be
entering \includegraphics[width=3cm]{lee.jpg}.
Another important concept I’m to introduce is environment. An environment takes
the form of the following:
\begin{environment_name}
The content ...
\end{environment_name}
Example 3.5 How do you center a paragraph of text?
Answer Here’s how:
\begin{center}
This line should be centered.
\end{center}
3.2 Your first masterpiece with LATEX
The first section in this
example is from The
Complete Manual of 1
Typography, and the 2
second is from The 3
TEXbook.
4
5
6
OK, let’s get down to typeset our first glorious document. By the end of this section,
you would have produced what is shown in figure 3.1.
Launch WinEdt or TeXShop. Then enter the following into the file:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\title{My First \LaTeX\ Exercise}
\author{Helin Gai}
\maketitle
,
3.2 Your first masterpiece with LATEX
My First LATEX Exercise
9
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
Helin Gai
May 5, 2006
Contents
1 Fonts
1
2 LATEX
1
1
The Changing Definition of Font
In the days of handset type, a font 1 comprised one or more drawers full of type
blocks in a single size. With the advent of the Monotype and Linotype machines,
a font then became a set of molds (or matrices) from which type could be cast
as it was needed, on the fly.
All of this type was destined for a specific kind of printing press, the letterpress. On a letterpress the printed impression is created by inking a raised
surface (which can be a photographic image as well as type) whose image is
transferred under pressure to the paper. Recessed areas—those below typehigh—receive no ink, do not come into contact with the paper, and so create
the “blank” areas of the page.
2
The Glorious LATEX
The first paragraph of a new section is not indented. TEX recognizes the end of
a paragraph when it comes to a blank line in your manuscript file.
Subsequent paragraphs are indented.2 (See?) The computer breaks a paragraph’s text into lines in an interesting way–and hyphenates words automatically
when necessary.
“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.”
try to avoid footnotes!
2 Oh,
1
Figure 3.1: The final result of your first masterpiece created with LATEX.
à
10
Getting Started
7
8
\tableofcontents
9
10
\section[Fonts]{The Changing Definition of Font}
11
12
13
14
15
16
17
In the days of handset type, a \emph{font}\footnote{A term that
comes from an early French word meaning ‘‘molding’’ or
‘‘casting.’’} comprised one or more drawers full of type blocks
in a single size. With the advent of the Monotype and Linotype
machines, a font then became a set of molds (or \emph{matrices})
from which type could be cast as it was needed, on the fly.
18
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
19
20
21
22
23
24
25
All of this type was destined for a specific kind of printing
press, the \emph{letterpress}. On a letterpress the printed
impression is created by inking a raised surface (which can be
a photographic image as well as type) whose image is transferred
under pressure to the paper. Recessed areas---those below
\emph{type-high}---receive no ink, do not come into contact with
the paper, and so create the ‘‘blank’’ areas of the page.
26
27
A class file is an actual
physical file with the
extension .cls.
A style file is also a
physical file with the
extension .sty.
\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.
Line 1: The control sequence \documentclass will appear in every single one of of
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.
Line 2: Every once in a while, you’ll want some features that are not built into
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
Line 8: \tableofcontents prepares the table of contents, as I’ve mentioned before.
Line 10: \section starts a new section, numbers it, and formats it. The section
title is “The Changing Definition of Font,” but we want it to be shown as “Font” in the
table of contents. (Remember what optional and required declarations are respectively?)
Line 12: We start our text on this line. Note that pressing the “enter” (or “return”)
key once to go to the next line is the same as pressing the space bar; i.e., one return =
one space. So you can end a line anywhere you want.
The \emph command tells LATEX to emphasize the part of the text (in italic by
default). \footnote creates a footnote and numbers it automatically.
Line 13: Note that “ is produced with ‘‘ (pressing the key on the left of ‘1’ twice),
and ” is produced with ’’.
Line 17: Remember what a ligature is? I used “fi” as an example in chapter 1. On
line 17, we meet the “fl” ligature. You don’t have to worry about it—TEX takes care of
it automatically.
Line 19: Two returns starts a new paragraph!
Line 23: --- is converted into —, what we call an em dash. (What do you think
the result of -- is?)
Now try to enter the remaining of the document yourself.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
3.3 Typesetting Chinese in LATEX
As I’ve mentioned before, there are two major Chinese typesetting system: CCT and
CJK, each of which has its own advantages. CCT is developed by Linbo Zhang, a
Chinese scholar, and has paid much attention to Chinese typographic conventions.
CJK lacks these typographic consideration but is more flexible and provides better
compatibility with LATEX.
A comprehensive solution, the ctex package, is developed by Lingyun Wu, President
of the CTEX Society. It uses CJK as its default formatting engine (although you could
easily specify that it uses CCT instead), and also provides commands specially designed
for typesetting Chinese (e.g., declaring Chinese fonts, setting up Chinese-style heading,
and so forth).
We’re going to typeset what is shown in figure 3.2 with the ctex package.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
11
\documentclass{article}
\usepackage{ctex}
\usepackage{amsmath}
\begin{document}
\title{·¥©öS}
\author{ä>}
\maketitle
\tableofcontents
\section{\£}
¥©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"¤±§
\TeX perts~¥m@´¬",§XJ\½@§
±Ñ\~\TeX\ perts"
à
12
Getting Started
·¥©öS
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
ä>
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Ú"
1
Figure 3.2: Typesetting Chinese in LATEX
,
3.4 A Short Summary
13
19
20
21
y3ëYUüg£§Òm© #ã"CTeX~¬gÄ\3c¡Ñü
Çiål"
Again, here’s some explanation:
Line 2: To load ctex, simply use the \usepackage control sequence. Note how the
style of section titles are different.
Lines 12–18 explain some weird phenomena you would come across in typesetting
Chinese. For example, spaces between Chinese characters will disappear. You would
also notice that I use a ~ (tilde) to connect Chinese and English—you don’t have to,
but for the purpose of perfect composition, I recommend that you start cultivating this
great habit.
Try to typeset section 2 yourself.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
3.4 A Short Summary
A lot of information has been presented in this chapter. And below is the most basic but
important “template” you should remember. Make sure you understand every single
command in the template.
\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}
--- produces an em dash. ‘‘ produces the left quote.
’’ produces the right quote.
\end{document}
3.5 Dividing your text into parts, chapters, and sections
Headers help your reader find his or her way through your work. As you’ve already
seen, the article class provides \section to fulfill this purpose. But there are more
commands provided by article:
\section{...}
\subsection{...}
\subsubsection{...}
\paragraph{...}
\subparagraph{...}
You should definitely try them out.
à
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}
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
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}
The \chapter command is also provided in report.
Note that these commands could be followed by an optional argument, as is
explained before. For example, a chapter title “Duke is one of the best universities in
the United States of America” is a bit too long to be placed in the table of contents,
and you decide that it be replaced with “Duke is one of the best universities in the U.S.”
in the TOC. What you should enter is the following:
\chapter[Duke is one of the best universities in the U.S.]
{Duke is one of the best universities in the United
States of America}
3.6 Options of standard document classes
This table is abstracted
from The Not So Short
Introduction to LATEX 2ε ,
with some modification.
I’ve already mentioned that a control sequence might be followed with an optional
argument, enclosed in brackets. \documentclass is just another one of the kind.
Table 3.1 lists all available options for the standard article, report, and book
classes.
The table should be studied carefully and the best way to study it is to try
everything out.
,
3.6 Options of standard document classes
15
Table 3.1: Options of standard document classes
Command
Meaning
10pt, 11pt, 12pt
Sets the size of the main font in the document.
If none is specified, 10 pt is assumed. Note that
when you change the option from 10pt to 12pt,
the sizes of section headings are adjusted automatically.
Defines the paper size. The default size is
letterpaper. Besides that, a5paper, b5paper,
executivepaper, and legalpaper can be specified.
By default, all the displayed math formulas are
centered. If you specify fleqn, they will left-align.
Places the numbering of formulas on the left hand
side instead of the right.
Specifies whether a new page should be started
after the document title or not; i.e., whether the
content before \maketitle should be placed on
a separate page or not. The article class does
not start a new page by default, while report
and book do.
Instructs LATEX to typeset the document in one
column or two columns.
Specifies whether double or single sided output
should be generated. The classes article and
report are single sided and the book class is
double sided by default. Note that this option
concerns the style of the document only. The
option twoside does not tell the printer you use
that it should actually make a two-sided printout.
Changes the layout of the document to print in
landscape mode.
Starts a new chapter on the right hand page or
on the next page. This does not work with the
article class, as it does not know about chapters.
The report class by default starts chapters on
the next page available and the book class starts
them on right hand pages.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
a4paper, letterpaper, . . .
fleqn
leqno
titlepage, notitlepage
onecolumn, twocolumn
twoside, oneside
landscape
openright, openany
à
16
Getting Started
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
,
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.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
4.1 International characters
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,
and when you press the key e again, it will be placed under the tilde:
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.
Table 4.1: Accents and special characters
Sample
ò
ō
ŏ
o
¯
œ
å
ø
ı
Command
\‘o
\=o
\u o
\b o
\oe
\aa
\o
\i
Sample
ó
ȯ
ǒ
o o
Œ
Å
Ø
Command
\’o
\.o
\v o
\t oo
\OE
\AA
\O
\j
Sample
Command
ô
ö
ő
o̧
æ
\^o
\"o
\H o
\c o
\ae
l
¡
\l
!‘
Sample
Command
õ
\~o
o.
\d o
Æ
\AE
L
¿
\L
?‘
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\\
\hspace*{10.5pt}R\i ght}
Buy
Rıght
à
Interestingly, if you press
Option + e + i, the dot of
“i” will disappear: [.
18
Playing with Text
4.2 Punctuation—what makes life/reading easier
4.2.1 Dash—your first lesson with punctuation
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
kind of dash), called a soft
hyphen, which is discussed
in section about
hyphenation.
• En dashes (obtained from --) are widely used instead of “to,” and for prefixing a
compound word; e.g., pages 10–20, London–Paris train, post–World War II.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
You will learn that all
“inline” math equations
are placed between dollar
signs.
• Em dashes (obtained from ---) are used for punctuating a sentence—they are
what we often call simply dashes.
• Minus signs (obtained from $-$) are used in math formulas a lot, e.g., −1.
In some Asian countries, number ranges are indicated with a tilde (∼) instead
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?\\
--- Of course.
— Will Colin attend your wedding?
— Of course.
4.2.2 Quotation marks
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
4.2.3 Comma and Period
TEX was designed a long time ago, and occasionally it does follow some old typographic
tradition. Take a look at the following result:
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:
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
\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:
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
The spirit of our American radicalism is
destructive and aimless\ldots. On the
other side, the conservative party
$\ldots$ is timid, and merely
defensive\ldots. It does not build, nor
write, nor cherish the arts, nor foster
religion, nor establish schools.
The spirit of our American radicalism is destructive and aimless. . . . On the other side,
the conservative party . . . is timid, and merely
defensive. . . . It does not build, nor write, nor
cherish the arts, nor foster religion, nor establish schools.
4.3 Changing typefaces
The two words “font” and
“typeface” are commonly
misused. “A typeface is a
collection of characters
that are designed to work
together like the parts of a
coordinated outfit. . . . A
font . . . is a physical thing,
the description of a
typeface. . . .” You can ask
questions like “What font
was used to set that
typeface?” But you can’t
say, “What font is that?”
The default typefaces used by TEX includes Computer Modern Roman, Computer
Modern Bold Face, Computer Modern Italics, Computer Modern Slanted, etc. The
commands for changing the typefaces are shown in table 4.2.
Table 4.2: Changing typefaces in LATEX
Command
Sample
Command
Sample
\textrm{roman}
\textbf{bold face}
\texttt{typewriter}
\textsf{sans serif}
roman
bold face
typewriter
sans serif
\textit{italic}
\textsl{slanted}
\textsc{Small Caps}
italic
slanted
Small Caps
Notice that there are two kinds of oblique typefaces listed in the table. Slanted
typeface could be considered skewed roman, while italic type is designed in a different
style. This will be clear if you see letters that are in an unslanted italic typeface.
You could easily combine these commands to obtain more typefaces (but try not
to abuse this power):
\textbf{\textit{bold italic}}\\
\textit{\texttt{italic typewriter}}
bold italic
italic typewriter
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
\textit{King Lear}; after his final
performance, he announced his retirement.
She is the author of \textit{Who Next?}
Smith played the title role in Hamlet, Macbeth, and King Lear ; after his final performance, he announced his retirement.
She is the author of Who Next?
Note: In what follows . . .
\textbf{Note}: In what follows \dots
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
4.4 Controlling the size of your text
We’ve already known that we can change the size of the main text by supplying the
optional arguments of \documentclass. Most submission require a 12-point font, we
can simply write something like \documentclass[12pt]{article} to achieve the effect.
You’ll realize that the section title is now bigger as well. The three pre-defined choices
are 10pt, 11pt, and 12pt.
But you could also change the size of your text within your main text. Table 4.3
tells you how. Note that these size changing commands are relative, e.g., tiny becomes
bigger as you change the main text from 10 pt to 12 pt. Table 4.4 tells you the absolute
size produced by these commands as your main font varies.
Table 4.3: Changing the size of the text in LATEX
Command
Sample
Command
Sample
\tiny
\footnotesize
\normalsize
footnotesize
scriptsize
normalsize
\scriptsize
\small
\large
\Large
larger
\LARGE
even larger
\huge
huge
\Huge
largest
tiny
small
large
The next question to ask is how you obtain a line of text that is exactly 15 pt big?
The answer is to use the \fontsize{size}{skip}. The {size} argument is the size of
the text, while the {skip} argument specifies the baseline skip adopted. Notice that
after the font size is chosen, you have to execute the font by using the \selectfont
command.
\fontsize{15}{17}\selectfont
Happy Birthday!
Happy Birthday!
4.5 Is what you type what you get?
4.5.1 Special characters that make TEX scream
There are a few characters that require your special attention:
à
22
Playing with Text
Table 4.4: Absolute point sizes in standard classes
Commands
10pt option
11pt option
12pt option
5 pt
7 pt
8 pt
9 pt
10 pt
12 pt
14 pt
17 pt
20 pt
25 pt
6 pt
8 pt
9 pt
10 pt
11 pt
12 pt
14 pt
17 pt
20 pt
25 pt
6 pt
8 pt
10 pt
11 pt
12 pt
14 pt
17 pt
20 pt
25 pt
25 pt
\tiny
\scriptsize
\footnotesize
\small
\normalsize
\large
\Large
\LARGE
\huge
\Huge
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
# $ % ^ & _ { } ~ \
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,
\textbf{fi,
\textit{fi,
\textsl{fi,
\textsf{fi,
\textsc{fi,
\texttt{fi,
fl,
fl,
fl,
fl,
fl,
fl,
fl,
ff,
ff,
ff,
ff,
ff,
ff,
ff,
ffi,
ffi,
ffi,
ffi,
ffi,
ffi,
ffi,
ffl}\\
ffl}\\
ffl}\\
ffl}\\
ffl}\\
ffl}\\
ffl}
fi, fl, ff, ffi, ffl
fi, fl, ff, ffi, ffl
fi, fl, ff, ffi, ffl
fi, fl, ff, ffi, ffl
fi, fl, ff, ffi, ffl
fi, fl, ff, ffi, ffl
fi, fl, ff, ffi, ffl
Evidently, Computer Modern Small Caps and Computer Modern Typewriter do
not have any ligatures at all. As a matter of fact, \texttt{---} produces ---, not an
em dash.
Some typographers think that ligatures should be turned off in headings. This
sometimes doesn’t produce the best result, so you should eyeball the result and make
,
4.6 Manual kerning
23
an informed decision. But the way to disable ligatures in LATEX is simply to divide the
letters up:
fi, f{}i, {f}i, f{i}
fi, fi, fi, fi
4.6 Manual kerning
“In setting type, it’s often the little things that count.” Kerning adjusts the spaces
between specific letter pairs to make the text look smooth and even. TEX automatically
kerns letter pairs according to the metric information that comes along with the font.
For example, letters A and V are automatically placed closer to show up as “AV.”
Without kerning, what you get is “AV,” which is horrible.
But in the domain of typography, it is the optical aspect that really counts. The
phrase “post–World War II” looks unpleasant—according to the metric files, TEX placed
the correct amount of space before and after the en dash, but optically it still looks
wrong. So we human have to interfere. Here’s how:
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
post--\kern-0.5pt World War II
post–World War II
à
24
Playing with Text
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
,
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.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
5.1 Manual line and page breaks
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 \\.
Sometimes, {\large I}\\
just want to break the line.
Sometimes, I
just want to break the line.
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:
Sometimes, {\large I}\linebreak
just want to break the line at
certain points to make \TeX\ unhappy.
Sometimes,
I
just want to break the line at certain
points to make TEX unhappy.
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
www.admissions\linebreak[0].duke.edu
for more information about applying to Duke.
You could visit the site www.admissions
.duke.edu for more information about applying to Duke.
Similarly, LATEX provides \newpage and \pagebreak[n] to create manual page
breaks. \newpage terminates the line, fills the remaining of the page with blank space,
and then goes onto the next page; \pagebreak justify the page so that the blank space
is scattered into the text flow where additional vertical spaces is allowed (typically
between paragraphs, before and after a heading, etc.).
5.2 Moving your text horizontally
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
The environments flushleft and flushright generate paragraphs that are either leftor right-aligned. The center environment generates centered text. If you do not issue
\\ to specify line breaks, LATEX will automatically determine line breaks.
\begin{flushleft}
This text is\\ left-aligned.
\LaTeX\ is not trying to make
each line the same length.
\end{flushleft}
This text is
left-aligned. LATEX is not trying to make each
line the same length.
\begin{flushright}
This text is right-\\aligned.
\LaTeX\ is not trying to make
each line the samelength.
\end{flushright}
This text is rightaligned. LATEX is not trying to make each
line the samelength.
\begin{center}
At the centre\\of the earth
\end{center}
At the centre
of the earth
5.3 Shaping a paragraph
Indentation is what controls the shape of a paragraph. And there are a couple of different
indents.
The most well-known indents are the first-line indents, which flag the beginnings
of new paragraphs. We’ve already known a great deal about first-line indents in LATEX:
1) The first paragraph after a section heading will not be indented; if you do want to
indent it, the indentfirst package will help; 2) Starting from the second paragraph, LATEX
will automatically inserts a first-line indents.
Paragraph indents are often measured in ems, and in LATEX the size is controlled
by \parindent, so \setlength{\parindent}{2em} (or simply \partindent=2em) sets
the depth of the indent to be 2 em. If for mysterious reasons you want to cancel the
indent of a specific paragraph, simply prefix it with \noindent.
There is no rule as to how big the first-line indent should be, but generally speaking,
wider measures will profit from deeper indents. In this book, the section number plus
,
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 specifies the depth of the indentation;
• \hangafter specifies the number of normal lines.
The following example demonstrates what you could achieve:
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
\hangindent=3em \hangafter=2
Duke University is a very young school. Our
history can be traced to as early as 1839,
when Brown’s school house was established.
But it was not until 1924 that Duke came
into existence.
Duke University is a very young school. Our
history can be traced to as early as 1839, when
Brown’s school house was established.
But it was not until 1924 that Duke
came 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
history could be traced to as early as 1839,
when Brown’s school house was established.
But it was not until 1924 that Duke came
into existence.
Duke University is a very young school. Our
history could be traced to as early as 1839,
when Brown’s school house was established. But it was not until 1924 that
Duke came into existence.
An interesting question to ask is whether or not the \hangafter could be negative.
The answer is positive:
\hangindent=-3em \hangafter=-2
Duke University is a very young school. Our
history could be traced to as early as 1839,
when Brown’s school house was established.
But it was not until 1924 that Duke came
into existence.
Duke University is a very young school.
Our history could be traced to as early
as 1839, when Brown’s school house was established. But it was not until 1924 that Duke
came 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
\begin{quote}
revolutions also break out when opposite
parties $\ldots$ are equally balanced\dots.
\end{quote}
In discussing the reasons for political
disturbances Aristotle observes that
\begin{quotation}
revolutions also break out when opposite
parties $\ldots$ are equally balanced\dots.
\end{quotation}
In discussing the reasons for political disturbances Aristotle observes that
revolutions also break out when opposite
parties . . . are equally balanced. . . .
In discussing the reasons for political disturbances Aristotle observes that
revolutions also break out when opposite parties . . . are equally balanced. . . .
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
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
\leavevmode\smash{\rlap{\hspace*{4.4cm}%
\lower1.2cm\hbox{%
\includegraphics[width=20mm]
{ColinLee.jpg}}}}%
Lee is my superfriend. He goes to Fudan
University and majors in Software
Engineering. He’s very smart and loves
playing World of Warcraft very much.
The shapepar is a pretty
cool package. Read
ftp://ftp.duke.edu/
pub/tex-archive/
macros/latex/contrib/
shapepar/shapepar.pdf
for more information.
Lee is my superfriend. He
goes to Fudan University and majors in Software Engineering. He’s
very smart and loves playing World of Warcraft very much.
By using \parshape, you could literally make your paragraph any shape you want.
But if you want your paragraph to be shaped a heart, there’s a package, shapepar, that
could ease your work. The package provides a few predefined shapes that you could call
up by using \diamondpar, \squarepar, and \heartpar.
,
5.4 Reflowing the text
\heartpar{A running indent draws the
margin of the type in from the right or
left edge of the text frame by a specified
distance. Typically page layout programs
refer to these as simply left and right
indents. Because it is construed as a
paragraph attribute, any left or right
indent will affect all lines in a paragraph.}
29
A running
indent
draws the mar- gin of the type
in from the right or left edge of the
text frame by a specified distance.
Typically page layout programs refer to these as simply left and right
indents. Because it is construed
as a paragraph attribute, any
left or right indent will
affect all lines in a
paragraph.
♥
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
5.4 Reflowing the text
TEX is well-programmed, but by no means can it replace the eyes of a good typographer.
Sometimes (although experience tells that this doesn’t happen a lot when setting type
in TEX), you’ll observe some discrepancy showing up in the automatic flowed text that
TEX cannot observe with its built-in mechanism. There are a few occasions on which
you will need to reflow the text:
• When very loose or tight lines exist. These are actually rare because of TEX’s
engine is designed to avoid these. But if verbatim or URLs are in the text flow,
they could cause trouble.
• The same word appear consecutively at the end of lines.
• “River” is another typographic “misbehavior” (figure 5.1). It occurs when word
spaces stack one above the other in successive lines.
• When text is not justified but ragged, the ragged margins might end up in distracting
shapes (e.g., a triangle).
• A very short word ending a paragraph is on an individual line and the paragraph
indent is bigger than the word.
There are many ways to reflow the text. The first way to do so is to use the
\linebreak command (section 5.1).
The example below contains a very loose line caused by a URL:
The website of the \ctex\ Society is
www.ctex.org.
The website of
www.ctex.org.
the
CTEX
Society
is
We could reflow the text by specifying a “potential” breakpoint with the \linebreak[0]
command:
The website of the \ctex\ Society is
www\linebreak[0].ctex.org.
The website of the CTEX Society is www
.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 packages. 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, contemplative meanders among aisles of staid aspens (with trout
leaping to slurp all the afternoon insects from its calm surface), and forbidding swamp land as formidable as any that
Humphrey Bogart muddled through in The African Queen.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
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
is www\linebreak[0].ctex.org.
The website of the Chinese TEX Society is
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
typesets your document awfully fast and
always tries to find the best breakpoints
ever.
The most amazing feature of TEX is that it
typesets your document awfully fast and always tries to find the best breakpoints ever.
However, sometimes, it does make mistakes.
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
typesets your document awfully fast and
always tries to find the best breakpoints
ever.
The most amazing feature of TEX is that
it typesets your document awfully fast and
always tries to find the best breakpoints ever.
However, sometimes, it does make
mistakes.
However, sometimes, it does make mistakes.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
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.)
Book printing differs significantly from
ordinary typing with respect to dashes,
hyphens, and minus signs. In good math
books, these symbols are all different;
in fact there usually are at least four
different symbols.
Book printing differs significantly from ordinary typing with respect to dashes, hyphens,
and minus signs. In good math books, these
symbols are all different; in fact there usually
are at least four different symbols.
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
ordinary typing with respect to dashes,
hyphens, and minus signs. In good math
books, these symbols are all different;
in fact there usually are at least four
different symbols.
Book printing differs significantly from ordinary typing with respect to dashes, hyphens,
and minus signs. In good math books, these
symbols are all different; in fact there usually
are at least four different symbols.
5.5 Hyphenation and Justification technology
Now let’s take a look at the detail of the H&J technology underlying TEX. We’ll get
started with hyphenation. Hyphenation is quite a difficult problem for a computer.
Knuth, in his The TEXbook, gives some excellent examples to demonstrate this point:
[T]he word ‘record’ is supposed to be broken as ‘rec-ord’ when it is a noun, but
‘re-cord’ when it is a verb. The word ‘hyphenation’ itself is somewhat exceptional;
if ‘hy-phen-a-tion’ is compared to similar words like ‘con-cat-e-na-tion’, it’s not
immediately clear why the ‘n’ should be attached to the ‘e’ in one case but not
the other. Examples like ‘dem-on-stra-tion’ vs. ‘de-mon-stra-tive’ show that the
alteration of two letters can actually affect hyphens that are nine positions away.
The current solution that is adopted by TEX is developed by Frank M. Liang.
There are a few advantages to these algorithm: 1) It could find about 90% of permissible
à
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}
So you should enter ga\discretionary{l-}{a}{la}xy. If the word appears a lot
in your document, write \hyphenation{gal-axy} at the beginning of your document,
and TEX will work hard on this word every time.
Now let’s turn to justification. To understand the H&J technology in TEX, we first
go through a couple of basic concepts.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
• 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?].
Now let’s take a look at how TEX formats a paragraph.
TEX starts by breaking a paragraph into lines without hyphenating any word. This
process succeeds if none of the resulting lines has a badness exceeding the value of
\pretolerance (100 by default). If that fails, TEX hyphenates every word and makes
,
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 consecutive 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).
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
à
34
Working with Paragraphs
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
,
6
Elements of Your Document
6.1 Cross References
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
You, probably like me, like such statements as “Please refer to section bla.” But here
comes the “problem”—all the section numbers are automatically generated by LATEX so
you don’t know what it is until you actually see the “final” result. (Well, how’s it final
without the “bla”?) LATEX provides a powerful cross-referencing mechanism to solve
this problem.
Put the command \label{bla} after the sectioning command, where bla can
be any text, ranging from the name of the section to the name of a cat. Then
Please refer to \ref{bla} gives you the correct output (the bla here should match
the bla in the \label definition).
You can use this mechanism with almost any number that is automatically generated
by LATEX. One thing to notice, do not give the same argument to two or more \label
commands—you’ll get LATEX confused.
6.2 Listing items
Admit it—you love making lists! Everywhere you go, you make lists: a mental lists of
the things you’re going to do between breakfast and lunch, a list of the pros and cons of
reading this book instead of playing basketball, and so on. Luckily, it’s no hard thing to
create a list in LATEX, with the enumerate, itemize, and description environments.
Here’s a demo:
\begin{enumerate}
\item Every item starts with \verb"\item":
\label{list}
\begin{itemize}
\item You can nest listings;
\item[-] You can easily change the symbol.
\end{itemize}
\item Oh, you do achieve more:
\begin{description}
\item[Colin] The author of the book;
\item[Lee]
Colin’s super friend.
\end{description}
\end{enumerate}
1. Every item starts with \item:
• You can nest listings;
- You can easily change the symbol.
2. Oh, you do achieve more:
Colin The author of the book;
Lee Colin’s super friend.
Refer to Item 1 in the list.
Refer to Item~\ref{list} in the list.
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
Table 6.1: Commands controlling a list environment
Levels in the List
Items
Counter
Representation
Default Definition
Label Field
Default Form
Numbering Example
Prefix
Default Definition
Reference Example
First Level
Second Level
Commands for controlling the enumerate environment
enumi
enumii
\theenumi
\theenumii
\arabic{enumi}
\alph{enumii}
\lebelenumi
\labelenumii
\theenumi.
(\theenumii)
1., 2.
(a), (b)
Third Level
Fourth Level
enumiii
\theenumiii
\roman{enumiii}
\labelenumiii
\theenumiii.
i., ii.,
enumiv
\theenumiv
\Alph{enumiv}
\labelenumiv
\theenumiv.
A., B.
Commands for controlling the reference representation of enumerate
\p@enumi
\p@enumii
\p@enumiii
{}
\theenumi
\theenumi(\theenumii)
1, 2
1a, 2b
1(a)i, 2(b)ii
\p@enumiv
\p@enumiii\theenumiii
1(a)iA, 2(b)iiB
Commands for controlling the itemize environment
\labelitemi
\labelitemii
\textbullet
\normalfont\bfseries\textendash
•
–
\labelitemiv
\textperiodcentered
·
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
Command
Default Definition
Representation
This table is abstracted
from The LATEX
Companion.
\labelitemiii
\textasteriskcentered
∗
The enumerate and itemize environment supports up to four levels of nesting.
Table 6.1 shows the default numbering the referencing scheme of the four levels, and
what commands are used to control them.
You can control the appearance of your list environment with the information
provided in the table. For example,
\renewcommand\labelenumi{\S\theenumi.}
\begin{enumerate}
\item Hello!
\item I’m a Mac!
\end{enumerate}
§1. Hello!
§2. I’m a Mac!
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}}}
\renewcommand\labelenumi{\theenumi}
\begin{enumerate}
\item Hello!
\item I’m a MacBook Pro!
\end{enumerate}
¬ Hello!
I’m a MacBook Pro!
6.3 Columns—story in the world of wide documents
Column is a powerful weapon prepared for wide documents, e.g., newspapers. The
Elements of Typographic Style states,
,
6.3 Columns—story in the world of wide documents
37
Anything from 45 to 75 characters is widely regarded as a satisfactory length of line
for a single-column page set in a serifed text face in a text size. The 66-character line
(counting both letters and spaces) is widely regarded as ideal. For multiple-column
work, a better average is 40 to 50 characters.
This should guide you to determine what measure to use and whether or not to divide
your documents into columns.
You could simply use the twocolumn option of the standard document class. But
a better solution is to use the multicol package, especially if you want more than two
columns.
\begin{multicols}{3}\raggedright
Anything from 45 to 75 characters is widely
regarded as a satisfactory length of line
for a single-column page set in a serifed
text face in a text size.
\end{multicols}
Anything
from 45 to 75
characters is
widely
regarded as a
satisfactory
length of line
for a singlecolumn page
set in a
serifed text
face in a text
size.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
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 75 characters is widely
regarded as a satisfactory length of line
for a single-column page set in a serifed
text face in a text size.
\end{multicols}
Anything from 45 to a single-column page
75 characters is widely set in a serifed text
regarded as a satisfac- face in a text size.
tory length of line for
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 to 75 characters is widely
regarded as a satisfactory length of line
for a single-column page set in a serifed
text face in a text size.
\end{multicols}
n{multicols}{2}
ounter{unbalance}{2}
ing from 45 to 75 characters is widely
ded as a satisfactory length of line
single-column page set in a serifed
face in a text size.
multicols}
Anything from 45 column page set in a
to 75 characters is serifed text face in a
widely regarded as text size.
a satisfactory length
of line for a single-
Anything from 45 serifed text face in a
to 75 characters is text size.
widely regarded as
a satisfactory length
of line for a singlecolumn page set in a
à
38
Elements of Your Document
6.4 Notes, notes, and notes
6.4.1 When footnotes rule . . .
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 example, if you want to use symbols instead of numbers, simply type
\renewcommand\thefootnote{\fnsymbol{footnote}}.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
• 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
every new page, especially
you’re cross referencing
them. Even if you’re not,
the reader might be. It’s
always nice to bear the
reader in mine when
writing and designing. . . .
• The article class numbers all footnotes throughout the entire document, while the
book and report classes resets the footnotes every time a new chapter is started. If
you want footnote numbers to be reset on every new page, try
\usepackage[perpage]{footnote}.
• If you want all footnotes to show up only in the right column in a two-column
document, you could use the ftnright package.
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
,
ple might even
t they don’t
layout at all!
6.5 Programming codes
39
6.4.2 Notes at the end of a chapter
Endnotes are getting more and more popular nowadays, because they don’t affect the
page layout as dramatically as footnotes. What you need is the endnotes package. Now
substitute \endnote{...} for \footnote{...}, and \theendnotes will now print out
the endnotes at the designated place. Note that you can use multiple \theendnotes in
a single document; e.g., you can use one at the end of every chapter.
\renewcommand\notesname{End NOTES}
\renewcommand\theendnote{\Roman{endnote}}
\renewcommand\makeenmark
{\textsuperscript{(\theenmark)\enspace}}
In a world of endnotes,%
\endnote{Endnotes are popular.}
we can’t resist the temptation.%
\endnote{Unless you have to.}
\theendnotes
In a world of endnotes,(I) we can’t resist the
temptation.(II)
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
End NOTES
(I)
(II)
Endnotes are popular.
Unless you have to.
6.4.3 Notes dancing in the margin
This book makes extensive use of marginal notes to accommodate tons of interesting, additional information that doesn’t quite fit into the main text. These marginal notes can be
generated with the \marginpar{...} command. For example, \marginpar{Colin rules!} Colin rules!
generates what you see in the right margin.
By default, text goes to the right margin for one-sided documents, to the outside
margin for the two-sided, and to the nearest margin for two-column formatting. The
placement can be reversed with \reversemarginpar.
Sometimes, you may want a marginal note to vary depending upon which margin
it’s in. For example, to make an arrow pointing to the text, you need a left-pointing
arrow in the right margin and a right-pointing one in the left margin. Here’s how:
\margipar[$\Rightarrow$]{$\Leftarrow$}
6.5 Programming codes
When you reach this section, you must have been using LATEX for at least 39 minutes
(assuming you spend one minute reading each page), you should very much appreciate
the capability and beauty of LATEX, and you might be considering writing something to
your friends about LATEX with LATEX. Here comes the problem, how can you tell them
the way to produce the LATEX logo? In LATEX, you use commands related to verbatim
to obtain such output:
\verb"Hello, \TeX!"
and \verb*"Hello, \TeX!"
Hello, \TeX! and 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.
a+b
\begin{math}a+b\end{math}
\end{alltt}
A more comprehensive solution for typesetting program codes is provided by the
listings package. Here’s a simple example to show you what it can do:
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
\lstset{numberstyle=\tiny,
numbers=left}
\begin{lstlisting}[language=Pascal]
for i:=1 to maxint do
begin
WrItE(’This is stupid’);
end.
\end{lstlisting}
1
2
3
4
f o r i :=1 to maxint do
begin
WrItE( ’ This i s s t u p i d ’ ) ;
end .
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!
6.6 Making boxes
\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}.
Test \raisebox{2pt}{Hello!}
\parbox[pos]{width}{text}
\begin{minipage}[pos]{width}
...
\end{minipage}
,
Some words . Test Hello!
6.7 Index
n{minipage}[b]{12mm}
A A A A A A A
minipage}\quad
n{minipage}[c]{12mm}
B B B B B B B
minipage}\quad
n{minipage}[t]{12mm}
C C C C C C C
minipage}
A A A
A A A
A A A
A
B B B
B B B
B B B
B
41
C C C
C C C
C C C
C
\rule[lift]{width}{height}
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
Hello. \rule[4pt]{2cm}{1mm}
Hello.
6.7 Index
page
page
page
page
page
page
vi:
5:
6:
7:
11:
17:
\index{animal}
\index{animal}
\index{animal}
\index{animal}
\index{animalism|see{animal}}
\index{animal@\emph{animal}}
\index{mammal|textbf}
page 26: \index{animal!mammal!cat}
page 32: \index{animal!insect}
animal, vi, 5–7
insect, 32
mammal
cat, 26
animal, 17
animalism, see animal
mammal, 17
6.8 Bibliography
à
42
END NOTES
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
,
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.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
7.1 Balancing the elements that live on a page
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.
Shaping a page is a definite art that I haven’t quote mastered. Robert Bringhurst’s
The Elements of Typographic Style provides much insight into the topic, ranging from
the history of different sizes of paper to the musical notation of them. My job is to
tell you how to create what you want to create. Your first task should be to decide
the size of the paper. Of course, you could simply provide an optional argument to
the \documentclass command, but using the geometry package works better most of
the time. The predefined paper size include a0paper to a6paper, b0paper to b6paper,
letterpaper, exectivepaper, and legalpaper. To specify the paper size that you
wanna use, simply say:
\usepackage[letterpaper]{geometry}
Sometimes, you may want to use a paper size that is not predefined. Here’s how:
\usepackage[paperwidth=, paperheight=]{geometry}
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}
à
Here is a quote from
Robert Bringhurst that I
really want to share, “A
book is a flexible mirror of
the mind and the body. Its
overall size and
proportions, the color and
texture of the paper, the
sound it makes as the
pages turn, and the smell
of the paper, adhesive and
ink, all blend with with
the size and form and
placement of the type to
reveal a little about the
world in which it was
made.”
44
LATEX with Designers
paper
6top
?
headheight
headsep
head
total body
total body
paperheight
height
body
textheight
- right
left
(inner)
(outer)
width
textwidth
foot
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
6bottom
?
footskip
paperwidth
Figure 1: Dimension names used in the geometry package. width=textwidth and
byin
default.
left, right,
top and bottom are margins. If margins on
Figure 7.1: height=textheight
Dimension names used
the geometry
package.
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 willand
automatically
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
default
includefoot
parameters (a)
you
might want to change is shown.(b)
A includehead
few missing and
ones
are listed here:
paper
paper
footnotesep changes the dimension \skip\footins, separation between the bottom
6top
of text body andhead
the top 6
oftop
footnote text.
?
?
total body
head
marginparwidth6changes the width of the marginal ntoes.
6 margin notes.
marginparsep textheight
changes the distance between body and
textheight
You might have to play with these parameters many times and prepare a few
different sample pages
layout. But there’s a pretty
bodybefore you find the satisfactorybody
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
6bottom
bottom
foot
\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.
In Equation
(3), width:=textwidth
by default, but marginparsep and marginparwidth are included
7.2 Dressing
the headings
in width if includemp option is set true. In Equation (4), height:=textheight by default. If
includehead
is setskip
to true,
headheight
and headsep
arestraight
considered
as study
a part of
ofthe
height
in the the
We will again
LATEX’s
built-in mechanism
and go
to the
titlesec
vertical
completion
calculation.
In the same
way, includefoot
includes
Note that
package.
There
are two control
sequences
to be introduced.
The footskip.
first one affects
the options
ignore*
just layout
excludeofthe
spaces from textheight, but do not change those lengths themgeneral
a corresponding
heading:
selves. Figure 2 shows how these options work. Each of the seven dimensions in the right-hand side of
Equations
(3) and (4) corresponds to the ordinary LATEX control sequence with the same name.
\titleformat{cmd}[shape]{format}
Figure 3 illustrates various
layouts with different layout modes. The dimensions for a header and a
{label}{sep}{before-code}[after-code]
footer can be controlled by nohead or nofoot mode, which sets each length to 0pt directly. On the other
hand,,options ignore* do not change the corresponding native dimensions.
3.2 Auto-Completion Scheme
Suppose that the paper size is pre-defined in Equation (1) or (2), if two dimensions out of the three dimensions in the right-hand side of each equation are specified, the rest of the dimensions can be determined by
the specified ones. However, when none or only one of the three dimensions is specified, the rest of the
7.2 Dressing the headings
45
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
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
Note
Footer
Lengths are to the nearest pt.
page height = 795pt
page width = 614pt
\hoffset = 0pt
\voffset = 0pt
\evensidemargin = 87pt
\topmargin = -20pt
\headheight = 12pt
\headsep = 15pt
\textheight = 614pt
\textwidth = 376pt
\footskip = 29pt
\marginparsep = 18pt
\marginparpush = 5pt
\columnsep = 10pt
\columnseprule = 0.0pt
Figure 7.2: The layout of the book you’re currently reading.
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]
generates a title like this:
§. The Title.
of one quad.
The heading is separated from the section text by a dot and a space
(This format is used a lot in legal documents.)
The second command deals with spacing issues related to headings:
\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
Table 7.1: The arguments of the titleformat command
Argument
Explanation
cmd
cmd is the command name of the heading. If you are modifying the
section heading, then you should enter \titleformat{\section}...
The shape argument, which is optional, defines the general layout of the
heading. There are nine predefined shapes:
hang, the default, produces a hanging label (like \section in standard
classes);
display puts label and heading text on separate lines (think about the
standard \chapter);
runin generates a run-in heading; i.e., there won’t be a line break after
the heading (like \paragraph);
frame is like display but the heading will be framed;
leftmargin simply puts the heading into the left margin;
rightmargin places the heading in the right margin (duh);
block is the general-purpose shape, which simply typesets the heading
as a single text block;
drop wraps the first paragraph around the heading, using a fixed width
for the heading;
wrap is like drop, but uses the width of the widest heading line.
This argument applies formatting command to the whole title, both
the label and the heading text; e.g., if you say {\normalfont\scshape},
then the heading will be typeset in the small cap typeface in the main
text size.
This command only specifies the format of the label. For example,
{SECTION \thesection.} will produce something like “SECTION n,”
where n is the current section number.
This parameter determines the distance between the label and title text.
The code entered here will be executed immediately preceding the heading
text. Its last command can take one argument, which will pick up the
heading text. For example, you can say \large\bfseries\filcenter to
make the heading printed out in a bold typeface and centered. Of course,
there are \filleft and \filright to do similar tasks.
Similar to before-code, this is executed after formatting the heading text.
shape
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
format
label
sep
before-code
after-code
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
If headings have given you much headache, I suggest that you take a nap before reading
on. Headers could be comparatively easier to deal with by using fancyhdr.
To illustrate its usage, I’ll use two examples. Here comes example number 1, which
demonstrates what you could do with a single-sided document. To create what is shown
,
7.3 The flight of the navigator—headers
47
LEFT
1
RIGHT
...................................................
Foot
on the left
Foot on the right
Figure 7.3: Headers in a single-sided document.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
in figure 7.3, the following code is used:
\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
1
TITLE
1 Chapter
1.1 Section
This is a piece of sample text. This is a piece of
sample text. This is a piece of sample text. This
is a piece of sample text. This is a piece of sample
text. This is a piece of sample text. This is a piece
of sample text. This is a piece of sample text. This
is a piece of sample text. This is a piece of sample
1.1. SECTION
2
TITLE
text. This is a piece of sample text. This is a piece
of sample text. This is a piece of sample text. This
is a piece of sample text. This is a piece of sample
text. This is a piece of sample text. This is a piece
of sample text. This is a piece of sample text. This
is a piece of sample text. This is a piece of sample
text. This is a piece of sample text. This is a piece
of sample text. This is a piece of sample text. This
is a piece of sample text. This is a piece of sample
text. This is a piece of sample text. This is a piece
of sample text. This is a piece of sample text.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
Figure 7.4: Headers in a double-sided document.
7.4 A not so short short introduction to markers
Introducing two commands to generate marks:
\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}}
You’ll see some examples or markers at work in section 7.5
7.5 The design of this book
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
7.5.1 Shaping the page
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
top. Although the generous margin at the bottom is deliberate, I found it too blank
to be pleasing to the eye. So I decided to put some decoration symbols at the foot,
which are 0.4 inches away from the text. (I could have put the page numbers here, but
I decided to put them at the topic, sticking out in the margin to illustrate some other
commands.) I made the marginal notes to be 1.4 inches wide and 0.25 inches away from
the right margin of the text. Now everything is well planned. To get these specifications
into LATEX, I put
The dimension of the text
block is chosen with the
golden mean in mind;
8.5/5.2 ≈ 1.63, which is
fairly close to the golden
mean, 1.618.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
\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}
into the style file.
7.5.2 Designing headings
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 evennumbered 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.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
\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
You might be surprised to
know that this chapter is
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 + 6f29603.
)
$-a+2b=3c-4d(5e+6f)$\\
When TEX dates math, math feels happy. The story of mathematics in LATEX is long and
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.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
$(x+y)/(x-y)$\\
$\{a,b,c,d,e\}$
(x + y)/(x − y)
{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,
$(x + y)/(x - z)$
(x + y)/(x − z)
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}
\begin{equation*}
\varphi-\rho\neq\kappa
\end{equation*}
δ×ε=θ
(8.1)
ϕ − ρ 6= κ
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.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
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$,\\
$x^2y^2$, $x ^2y ^2$\\
$x_12$, $x^12$
z 2 , bn ,
x2 y 2 , x2 y 2
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:
$x^{2y}$, $y_{3z}$\\
$x^{x^2}$, $y_{y_2}$, $y_{x^2}$
x2y , y3z
2
xx , yy2 , yx2
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
$x^{31415}_{92}+\pi$,
$x_{92}^{31415}+\pi$\\
$F_2^2$, $F{}_2^2$
53
x31415
+ π, x31415
+π
92
92
F22 , F 22
One more problem about this topic: primes. To get a prime, simply enter ‘’’:
$y_1’+y’’_2$
y10 + y200
8.2.1 The tensor Package
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
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:
$\tensor[^a_b^c_d]{M}{^a_b^c_d}$
a c
a c
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,
$\tensor*[^{14}_6]{\text{C}}{}$
14
6C
8.2.2 The vector Package
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:
\begin{gather*}
\uvec{p}=\left(\irvec{q}\right)\\
\uuvec{q}=\left(\!\!\icvec{q}\!\!\right)\\
\buvec{r}=\{\rvec{r}{1}{6}\}\\
\bvec{s}=\left[
\!\!\cvec{s}{0}{2}\!\!\right]
\end{gather*}
p = (q1 , . . . , qn )
q1
q̂ = ...
qn
r̂ = {r1 , r2 , r3 , r4 , r5 , r6 }
s0
s = s1
s2
à
54
When TEX Dates Math
√
8.3
Roots
Roots are produced by ‘\sqrt[...]{...}’:
√ √
√
2, 2y, 2y
√
√
3
2, n+1 x + y
$\sqrt2$, $\sqrt2y$, $\sqrt{2y}$\\
$\sqrt[3]{2}$, $\sqrt[n+1]{x+y}$
Some people might find the standard
of the index with the amsmath package.
√
β
$\sqrt[\leftroot{2}\uproot{4}\beta]{k}$,
$\sqrt[\leftroot{1}\uproot{3}\beta]{k}$
k,
√
β
√
β
k unacceptable. You can tune the position
k
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
√
√
√
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}$\\
$\sqrt{x}+\sqrt{\mathstrut y}+\sqrt{z}$\\
$\sqrt{x}+\sqrt{\smash[b]{y}}+\sqrt{z}$
8.4
Fractions
Binomials
√
√
√
x+ y+ z
p
√
√
√x + √ y + √ z
x+ y+ z
Let’s now turn to something more challenging—fractions. A fraction is obtained by
typing
\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}$,
\begin{equation*}
\frac{1}{2}
\end{equation*}
1
2,
1
2
LATEX does this for a good reason: an inline
can see here; a displayed
a+b
ruins the line spacing, as you
c+d
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
Binomials
8.4
This is an inline formula: $\dfrac{1}{2}$.
But avoid it! Replace it with
$\frac{1}{2}$ or $1/2$.
This is an inline formula:
place it with
Instead of \begin{equation*}
\dfrac{1}{2}(a+b),
\end{equation*}
you can try \begin{equation*}
\tfrac{1}{2}(a+b).
\end{equation*}
55
1
2
1
. But avoid it! Re2
or 1/2.
Instead of
1
(a + b),
2
you can try
1
2 (a
+ b).
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:
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
\begin{equation*}
a_0+\cfrac{b_1}{
a_1+\cfrac[l]{b_2}{
a_2+\cfrac[r]{b_3}{
a_3+\cdots}}}
\end{equation*}
b1
a0 +
a1 +
b2
a2 +
b3
a3 + · · ·
You may also use the alternative form:
\[a_0+\frac{b_1}{a_1+}
\frac{b_2}{a_2+}
\frac{b_3}{a_3+}\cdots\]
a0 +
b 1 b 2 b3
···
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: $\binom{k}{2}$.\\
In display mode:
\begin{equation*} \binom{k}{2}
\end{equation*}
In inline mode: k2 .
In display mode:
k
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}$,
which is horrible.\\
In display mode:
\begin{equation*} \tbinom{k}{2}.
\end{equation*}
k
, which is horrible.
2
In display mode:
k
2 .
In inline mode:
It might be helpful to introduce the concept of “styles.” In math mode, there are
four styles:
display For normal symbols in a displayed formula.
text For normal symbols in an in-text formula.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
script For subscripts and superscripts.
scriptscript For further levels of sub- and superscripting, such as subscripts of superscripts.
Take a look at the following examples:
Compare the small superscript in $a^{x}$
with the large one in $a^{\textstyle x}$.
Instead of using \verb"\dfrac", you can
do it this way: $\displaystyle\frac{1}{2}$.
And instead of using \verb"\tfrac", you
can try this:\begin{equation*}
\textstyle\frac{1}{2}.
\end{equation*}
Compare the small superscript in ax with the
large one in ax .
Instead of using \dfrac, you can do it this
1
way: .
2
And instead of using \tfrac, you can try this:
1
2.
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
things are much better:
This is a test. This is a test. This is a test. This is a test. This is a test.
This is a test. This is a test. This is a test. This is a test. This is a test.
,
1
2
8.5 Sum and integration
57
8.5 Sum and integration
Sum and integration are different in inline and display modes:
Inline: $\sum_{n=1}^k$, $\prod_{n=1}^k$,
$\int_a^b$\\
Display: \begin{equation*}
\sum_{n=1}^k,\qquad \prod_{n=1}^k,
\qquad\int_a^b.
\end{equation*}
Rb
Pk
Qk
Inline: n=1 , n=1 , a
Display:
k
X
k
Y
,
n=1
Z
b
.
,
a
n=1
This is actually pretty nice output. However, you might sometimes want to change
the position of the “limits.” Here’s how:
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
\begin{equation*}
\iint_A,\qquad \iint\limits_A
\end{equation*}
ZZ
ZZ
,
A
A
There are a few more commands for producing different integral signs:
\begin{equation*}
\iiint\limits_V,
\idotsint\limits_V, \oint_V
\end{equation*}
ZZZ Z
Z I
, ··· ,
V
V
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
\scriptscriptstyle{#1}}%
\!\int}
\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\]
Z b
− f (x) dx
a
Sometimes, you might have to produce limits of more than one line. The amsmath
package provides the command ‘\substack’ which is helpful:
\[\sum_{\substack{0\leq i\leq m\\
0>>, @<<<, @VVV, and @AAA give right, left,
down, and up arrows, respectively. For example,
\[\begin{CD}
\cov(L) @>>> \non(K) @>>> \cf(K)\\
@VVV @AAA @AAA \\
\add(L) @>>> \add(K) @>>> \cov(K)\\
\end{CD}\]
cov(L) −−−−→ non(K) −−−−→ cf(K)
x
x
y
add(L) −−−−→ add(K) −−−−→ cov(K)
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
gin{CD}
\Lambda}\otimes T @>j>>
\\
@VV{\mathop{\rm End} P}V\\
imes T)/I @= (Z\otimes T)/J
CD}\]
j
S WΛ ⊗ T −−−−→
y
(S ⊗ T )/I
89
T
yEnd P
(Z ⊗ T )/J
8.24 Coloring Your Math—The color Package
There is no difference in producing colored text and colored math expression. With the
color package, you can do this:
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
n{equation}
color{blue}{f(x)}=\int_1^\infty
xtcolor{red}{\frac{1}{x^2}}\,\rd x=1
equation}
Z
f (x) =
1
∞
1
dx = 1
x2
(8.38)
8.25 Packages Smarter Than Me
8.25.1 The polynom package
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
\polylongdiv{x^3+x^2-1}{x-1}
x3 + x2
−1
− x3 + x2
2x2
− 2x2 + 2x
2x − 1
− 2x + 2
1
Here are more examples:
1
\polyhornerscheme[x=1]{x^3+x^2-1}
1
1
\polyfactorize{2x^3+x^2-7x+3}
2 x−
1
2
1
0
−1
1
2
2
2
2
1
x+
1
2
√
+
13
2
Also, the output of \polylonggcd{(x-1)(x-1)(x^2+1)}{(x-1)(x+1)(x+1)} is:
à
x+
1
2
√
−
13
2
90
When TEX Dates Math
x4 − 2x3 + 2x2 − 2x + 1 = x3 + x2 − x − 1 · x − 3 + 6x2 − 4x − 2
5
x3 + x2 − x − 1 = 6x2 − 4x − 2 · 61 x + 18
+ 49 x − 49
9
+0
6x2 − 4x − 2 = 49 x − 94 · 27
2 x+ 2
8.25.2 The longdiv package
The longdiv is actually a TEX package. So you should load it with ‘\input longdiv.tex’.
Now take a look at what you can do with it:
15707
2 31415
20000
11415
10000
1415
1400
15
14
1
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
\longdiv{31415}{2}
8.26 The mathlig Package
The mathlig is a TEX package and should be loaded by ‘\input mathlig.tex’. It can
produce special “math ligatures,” like these:
\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:
\[f(x)=\frac{(x^2+1)\cancel{(x-1)}}
{\cancel{(x-1)}(x+1)}\]
f (x) =
(x2 + 1)
(x
−
1)
(x − 1)(x + 1)
8.27.2 The units and nicefrac Packages
About the loading of the packages: (1) When you load the units package, the nicefrac
package is loaded automatically; (2) The units package itself has two options, tight
and loose. The default value, tight, indicates a thin space will be added between
the number and the unit. The option loose will add a normal word spacing between
the number and the unit. You should remember that I have said that a thin space is
,
8.27 Miscellaneous
91
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:
20 cm
20 m/s
m/s
[20]{cm}\\
frac[20]{m}{s}\\
frac[\textsf]{m}{s}
However, if the \ugly option is specified, the command \unitfrac[20]{m}{s}
will produce 20 m/s.
My recommendation is to use \usepackage[ugly]{units} which would produce
the output I’ve been proposing in this book.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
8.27.3 Math in Titles—The maybemath Package
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:
l $x^2+\maybebm{x^3}+\cdots$\\
bf{$x^2+\maybebm{x^3}+\cdots$}
Normal x2 + x3 + · · ·
x2 + x3 + · · ·
For context-sensitive upright math typesetting use \mayberm:
Normal $x^2+\mayberm{x^3}+\cdots$\\
\textit{$x^2+\mayberm{x^3}+\cdots$}
Normal x2 + x3 + · · ·
x2 + x3 + · · ·
Alternatively, to force \mathit in italic contexts use \maybeit:
Normal $x^2+\maybeit{x^3}+\cdots$\\
\textit{$x^2+\maybeit{x^3}+\cdots$}
Normal x2 + x3 + · · ·
x2 + x 3 + · · ·
The functionality of both \mayberm and \maybeit is combined for convenience in
the command \maybeitrm:
Normal $x^2+\maybeitrm{x^3}+\cdots$\\
\textit{$x^2+\maybeitrm{x^3}+\cdots$}
Normal x2 + x3 + · · ·
x2 + x 3 + · · ·
For context-sensitive sans-serif math typesetting use \maybesf:
Normal $x^2+\maybesf{x^3}+\cdots$\\
\textit{$x^2+\maybesf{x^3}+\cdots$}
Normal x2 + x3 + · · ·
x2 + x3 + · · ·
à
92
When TEX Dates Math
For combined bold-and-sans-serif context handling, a \maybebmsf command is
provided:
Normal $x^2+\maybebmsf{x^3}+\cdots$\\
\textbf{$x^2+\maybebmsf{x^3}+\cdots$}\\
\textsf{$x^2+\maybebmsf{x^3}+\cdots$}\\
\textbf{\textsf{$x^2+\maybebmsf{x^3}+
\cdots$}}
Normal x2 + x3 + · · ·
x2 + x3 + · · ·
x2 + x3 + · · ·
x2 + x3 + · · ·
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.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
8.27.4 The nccmath Package
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,}
e+f&=g+h.
\end{align*}
Therefore,
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 +
\cfrac{1}{\sqrt 2 +\dotsb}}}
\quad \cfrac{1}{\sqrt 2 +\cfrac{1}
{\sqrt 2 +\dotsb}}\]
1
1
√
2+ √
1
√
2 + ···
2+ √
1
2 + ···
Now medium-sized operators:
$\sum_{i=1}^n \medop\sum_{i=1}^n
\displaystyle\sum\nolimits_{i=1}^n$
\quad $\sum\limits_{i=1}^n
\displaystyle \medop\sum_{i=1}^n
\sum_{i=1}^n$
Pn
i=1
X
n
i=1
Xn
i=1
n
P
XX
n
n
i=1 i=1 i=1
There are also commands for producing medium-sized integral, fractions, binomial
coefficient, and matrix.
,
8.28 Two Powerful Packages Mentioned Merely in Passing
_a^b\medint\int_a^b
playstyle\int_a^b$\quad
t_a^b\medint\iint_a^b$
c{x+y}{a-b} \mfrac{x+y}{a-b}
rac{x+y}{a-b}$\quad
om{n}{k} \mbinom{n}{k}
inom{n}{k}$
Rb
a
Z
b
a
b
Z
RR b
a
a
x+y x + y
a−b a − b
x+y
a−b
ZZ
93
b
a
n
k
n n
k
k
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
l(\begin{smallmatrix} a&b\\c&d
smallmatrix}\bigr)$
l(\begin{mmatrix} a&b\\c&d
mmatrix}\Bigr)$
in{pmatrix} a&b\\c&d
pmatrix}$
a b
c d
a
c
a b
c d
b
d
This package actually has more features. Please refer to ftp://ftp.sunsite.utk.
edu/pub/CTAN/macros/latex/contrib/ncctools/doc/nccmath.pdf.
8.28 Two Powerful Packages Mentioned Merely in Passing
There are two more amazing, brilliant packages I really want to show you. However, they
cause some compatibility issues which disturb the compilation of my book. What’s more,
they themselves come with easy-to-read and well-written documentations. Anyway, I’d
like to give you an overview.
The first package to mention is the nath package. Here is an excerpt from the
documentation of the package:
Nath is a LATEX style to separate presentation and content in mathematical
typography. The style delivers a particular context-dependent presentation on the
basis of a rather coarse context-independent notation. Although essentially backward compatible with LATEX, Nath aims at producing traditional math typography
even from sources devoid of aesthetic ambitions. Its name is derived from “natural
math notation.”
This description is quite accurate: The nath package has quite some compatibility
issues, but its functions are amazing! I strongly recommend that you read its marvelous documentation, which could be obtained at http://texcatalogue.sarovar.
org/entries/nath.html.
Another one is the mathenv package, which can ease your work to a large extent.
The documentation is available at ftp://ftp.sunsite.utk.edu/pub/CTAN/macros/
latex/contrib/bosisio/mathenv
.html.
à
94
When TEX Dates Math
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
,
9
Tables and Graphics
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
9.1 External graphics are a lot of fun
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.
As you’ve seen in the example, the \includegraphics command could be followed
by optional argument. width is one of them; there are also height, totalheight, scale
(this should be a number), angle, origin (the point that the image rotates along) and
bb.
9.2 Structuring a table
We get started with a simple table that illustrates most of LATEX’s own commands for
constructing tables.
à
bb=10 20 100 200 sets
the left bottom point of
the bounding box to be
(10, 20) and the top right
point to be (100, 200).
96
Tables and Graphics
\begin{tabular}{|r|c|r|}
\hline
\multicolumn{3}{|c|}{AT\&T Common Stock}\\
\hline
Year & Price & \multicolumn{1}{c|}{Dividend}\\
\hline
1971 & 41--54 & \$2.60\\\hline
2 & 41--54 & 2.70\\\cline{2-3}
3 & 46--55 & 2.97\\\hline
\end{tabular}
AT&T Common Stock
Year Price Dividend
1971 41–54
$2.60
2 41–54
2.70
3 46–55
2.97
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:
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
\begin{tabular}{c r @{.} l}
\hline
Pi expression &
\multicolumn{2}{c}{Value} \\
\hline
$\pi$ & 3&1416 \\
$\pi^{\pi}$ & 36&46 \\
$(\pi^{\pi})^{\pi}$ & 80662&7 \\
\hline
\end{tabular}
Pi expression
π
ππ
(π π )π
Value
3.1416
36.46
80662.7
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
Table 1: The ISOGRK3 entity set
Entity
Unicode Name
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
Unicode
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
Entity
Unicode Name
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
alpha
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
GREEK
97
Continued from previous page
Unicode
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
SMALL
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
LETTER
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
ALPHA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
03BA
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
Continued on next page
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 (\%)}\\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
Year & In yen & In dollars
& In yen & In dollars\\
\midrule
1970 & \figurespace0.9 & 90.4 & 0.3 & 80.0\\
1975 & 17.5 & 78.0 & 0.9 & 89.9\\
1980 & 28.9 & 66.3 & 2.4 & 93.1\\
\bottomrule
\end{tabular}
Export contracts (%)
Import contracts (%)
Year
In yen
In dollars
In yen
In dollars
1970
1975
1980
0.9
17.5
28.9
90.4
78.0
66.3
0.3
0.9
2.4
80.0
89.9
93.1
The commands \toprule, \midrule, and \bottomrule are self-explanatory. The
\cmidrule is like \cline, but you could use r and l put in parentheses to specify which
side of the line to truncate.
9.3 Tables that travel a long way
After loading the longtable package, the work is easy:
\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
Figure 9.2: A picture of Colin and his super friend, Lee.
\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\\
......
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
9.4 Floating tables and figures around
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}
Similarly, you can create a floating table with something like:
\begin{table}[tbhp]
\centering
\caption{...}
\begin{tabular}
...
\end{tabular}
\end{table}
,
9.5 Customizing your captions
99
Table 9.1: Parameters for controlling the float bodies.
topnumber
bottomnumber
totalnumber
\topfraction
\bottomfraction
The maximum number of floats allowed at the top of the page
(default to 2). It can be changed with \setcounter.
The maximum number of floats allowed at the bottom of the page
(default to 1). It can be changed with \setcounter.
The maximum number of floats allowed on a page (default to 3).
It can be changed with \setcounter.
Maximum fraction of the page that can be occupied by floats
at the top of the page (default to 0.7). It can be changed with
\renewcommand.
Maximum fraction of the page that can be occupied by floats at
the bottom of the page (default to 0.3). It can be changed with
\renewcommand.
Rubber length specifying the vertical space added between floats
(default to 12pt plus 2pt minus 2pt for 10 pt and 11 pt documents, and 14pt plus 2pt minus 4pt for 12 pt documents). This
can be changed with \setlength.
Rubber length specifying the vertical space added between floats
and the text (default to 20pt plus 2pt minus 4pt).
Rubber length specifying the vertical space added below and above
a float that is positioned in the middle of the text.
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
\floatsep
\textfloatsep
\intextsep
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.
9.5 Customizing your captions
Captions can be easily customized with the caption package.
All the most useful parameters are listed in table ??.
You could pass these options to the package itself, like what you do with the
geometry package. For example, the following code is legitimate:
\usepackage[textfont={rm,it},labelfont{sf}]{caption}
An alternative is to use the \captionsetup command:
\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.
à
caption2 used to be my
choice, but it is not
obsolete. Sigh . . .
100
Tables and Graphics
Table 9.2: Parameters for changing captions.
Parameter
Explanation
singlelinecheck
Checks if the whole option fits on a single line. If so, it will be
centered.
The default format is the the standard LATEX format. The alternative is hang, which specifies that the caption be set with the
label to the left of the caption text; i.e., continuation lines are
indented by the width of the label.
Sets the width and the margin of the caption.
Sets the indentation of continuation lines.
Defines the font characteristics for the entire caption. It can take
a set of keywords values including rm, sf, tt, md, bf, up, it, sl,
sc, scriptsize, footnotesize, small, normalsize, large, or
Large. For example, font={sf,bf} sets the caption in the bold
sans serif typeface.
Sets the font of the label.
Sets the font of the text of the caption.
Sets the separation between the label and the text. Keywords
include colon, period, space, and newline.
Specifies how the paragraph should be justified. Available keywords
are raggedleft, raggedright, centerfirst, and centerlast.
Sets the space between paragraphs in multi-paragraph captions.
Sets the space between the caption and float body.
Space on the opposite side of the caption.
format
margin, width
indentation
font
i
a
y
t
i
G
s
r
n
i
e
l
v
e
i
H Un
e
k
u
D
labelfont
textfont
labelsep
justification
parskip
aboveskip
belowskip
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}}
,
Source Exif Data:
File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.6 Linearized : Yes Encryption : Standard V2.3 (128-bit) User Access : Print, Copy, Extract, Print high-res Page Mode : UseOutlines XMP Toolkit : 3.1-701 Create Date : 2006:08:06 21:21:32+08:00 Creator Tool : LaTeX with hyperref package Modify Date : 2006:08:06 21:25:49+08:00 Metadata Date : 2006:08:06 21:25:49+08:00 Format : application/pdf Description : Creator : Title : Keywords : Producer : pdfeTeX-1.304 PTEX Fullbanner : This is pdfeTeX, Version 3.141592-1.30.4-2.2 (Web2C 7.5.5) kpathsea version 3.5.5 Document ID : uuid:e9a067cb-254e-11db-9c0e-0016cb89ab52 Instance ID : uuid:13382899-254f-11db-9c0e-0016cb89ab52 Page Count : 106 Subject : Author : PTEX Fullbanner : This is pdfeTeX, Version 3.141592-1.30.4-2.2 (Web2C 7.5.5) kpathsea version 3.5.5EXIF Metadata provided by EXIF.tools