texpert2
Transcript of texpert2
![Page 1: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/1.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 1/21
L A TE X: from beginner to TE Xpert
John Gardner
This version: September 2008
Contents
1 Introduction 2
2 What is L A TE X? 3
3 How does L A TE X work? 3
4 Getting L A TE X 4
4.1 On Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4.2 On Mac OS X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4.3 On Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
5 L A TE X basics 6
5.1 L A TE X commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
5.2 The preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
5.3 The document body . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
5.4 Document structure . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
6 Environments 9
7 Modifying text styles 10
8 Packages 11
8.1 The graphicx package . . . . . . . . . . . . . . . . . . . . . . . . . . 128.2 The geometry package . . . . . . . . . . . . . . . . . . . . . . . . . . 12
8.3 The AMS packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
8.4 Other packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1
![Page 2: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/2.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 2/21
9 Figures and tables 13
9.1 Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139.2 Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
10 Annotations 16
10.1 Footnotes and endnotes . . . . . . . . . . . . . . . . . . . . . . . . . 16
10.2 Cross references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
10.3 Table of contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
10.4 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
11 Inserting mathematics 17
11.1 Inline math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
11.2 Display math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1811.3 Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
11.4 Align . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
11.5 Mathematical notation . . . . . . . . . . . . . . . . . . . . . . . . . . 19
12 For further reference 21
1 Introduction
This document introduces the L A TE X typesetting system. After digesting the in-
formation below, you’ll be able to:
• Download and install L A TE X on your PC or Mac
• Create basic documents using L A TE X
• Install new L A TE X packages
• Insert tables and figures into a L A TE X document
• Use L A TE X’s cross-referencing, footnote and basic bibliography features
• Insert equations into a L A TE X document
These topics cover the majority of tasks that most people need to do when
writing a document. However, please note that while the L A TE X system makes it
very easy to create professional-looking documents, it is both comprehensive
and extensible. There are many topics that are not covered by this basic tutorial.
2
![Page 3: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/3.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 3/21
Fortunately, L A TE X is very well documented. If you come across something that
you can’t figure out how to do, ask your old friend Google for help.
2 What is L A TE X?
At its core, L A TE X is a typesetting system that allows authors to create highly pol-
ished documents without having to worry about formatting, page breaks, ob-
ject positioning, or any other style concerns that distract them from focusing
on writing. L A TE X is pronounced “lay-tech,” as it is an extension of TE X (“tech”),
the original typesetting system. You can read all about the history of TE X and
L A TE X on Wikipedia.
L A TE X is used widely in a variety of professions. Mathematicians, physicists,economists, statisticians and other academics and professionals that regularly
use mathematical notation in their documents often use L A TE X because of the
ease with which it handles such notation. Many publishers use TE X-based sys-
tems for typesetting documents.
3 How does L A TE X work?
L A TE X differs from traditional word processors in two fundamental ways:
1. Generally, L A TE X documents are written using the easy-to-learn L A T
E X markup
language, rather than by using a graphical interface to apply styles 1
2. L A TE X processes your document after you have entered your text. So unlike
word processors, it can use information about the total length of your
document, number of tables, etc. to find the optimal places for tables,
figures, page breaks, etc. to format your text
The following is an example of a very basic L A TE X document:
\ d o c u m e n t c l a s s { a r t i c l e }
\ a u t h o r { Y o u r N a m e }
\ t i t l e { T e s t D o c u m e n t }
\ b e g i n { d o c u m e n t }
1Graphical editors, such as Scientific Word (a commercial application) and LyX (an open-
source application), are available; these applications are easier to use if you know how L A TE X
works, so it’s a good idea to learn it even if you don’t plan to write L A TE X markup by hand.
3
![Page 4: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/4.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 4/21
\ m a k e t i t l e
T h i s i s a t e s t d o c u m e n t
\ e n d { d o c u m e n t }
With any L A TE X distribution, saving the above text as a . t e x file and running
L A TE X on that file would produce the following:
Test Document
Your Name
April 21, 2006
This is a test document.
L A TE X is designed to create the same output on any system. As a result, if
you distributed the above text to anyone with a working L A TE X distribution, re-
gardless of their particular system, they would get the exact same result. L A TE X
outputs compiled documents in several formats, but the most popular is PDF.
4 Getting L A TE X
All you technically need to create L A TE X documents is a L A TE X engine – the binary
files and libraries that will convert plain text . t e x files to polished PDF files.
L A TE X can be run from the command line, so Linux and DOS aficionados will
feel right at home. However, using a frontend for L A TE X can make things much
easier. Most frontends are essentially text editors with functions to
• Compile documents with L A TE X without using the command line
• Facilitate writing in the L A TE X language (wizards for table creation, syntax
highlighting, code completion, etc.)
In this document, I assume that you’ll use both a L A TE X engine and a fron-
tend. There are many engines and frontends to choose from on every operat-
ing system. I’m going to describe how to install the most popular (and easy to
4
![Page 5: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/5.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 5/21
install) open-source tools for Windows and Mac OS X. Other L A TE X tools have dif-
ferent configuration requirements and operating instructions, but almost every working environment involves (i) editing raw t e x files using a frontend and (ii)
compiling the L A TE X document to a PDF, generally using buttons or menu com-
mands in the frontend rather than the command line.
4.1 On Windows
Engine MikTeX is a popular open-source distribution. To install, visith t t p :
/ / w w w . m i k t e x . o r g , download the executable, and follow the dialog. Addi-
tional installation instructions are on the download page.
Frontend TeXnic Center, available from h t t p : / / t o o l s c e n t e r . o r g , is an open-
source frontend with many helpful features. Installation is standard, just down-
load and open the executable, which opens a wizard.
TeXnic center is automatically configured to work with MikTeX. To test out
your setup, save the sample document above as a t e x file using TeXnic Cen-
ter and select B u i l d ⇒ C u r r e n t f i l e . If everything is set up properly, a new
PDF file (along with a log file) will be created in the directory where your docu-
ment is saved.
4.2 On Mac OS X
Engine gwTeX is a free and open-source L A TE X distribution for OS X that comes
with a graphical installer. To install, download the i-Installer application, select
a mirror, then select the TeX package. Additional installation instructions are
available at h t t p : / / i i 2 . s o u r c e f o r g e . n e t / t e x - i n d e x . h t m l . Once installa-
tion is complete, all you need is a frontend.
Frontend TeXShop (h t t p : / / w w w . u o r e g o n . e d u / ~ k o c h / t e x s h o p / ) is a very
popular L A TE X frontend for OS X. Installation requires a simple drag and drop
to the ˜/Applications folder. TeXShop is automatically configured to work with
gwTeX, so if that’s the engine that you’re using, you’re set.
To test out your distribution, try saving the sample document above as a
t e x file and running L A TE X on your document by pressing command-t. If ev-
erything is configured properly, a window will appear similar to the example
5
![Page 6: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/6.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 6/21
output above, and a new PDF file (as well as a log file) will appear in the direc-
tory where your file is saved.
4.3 On Linux
Different Linux systems have their own application management utilities (apt-
get or rpm, for example), and installation will depend on your particular Linux
distribution. Ubuntu users can use the Synaptic Package Manager. Kile is a
popular and easy-to-use frontend that works with both KDE and Gnome.
5 L A TE X basics
5.1 L A TE X commands
L A TE X commands generally begin with a backslash and take the form:
\ c o m m a n d [ o p t i o n s ] { a r g u m e n t }
For example,
\ s e c t i o n { I n t r o d u c t i o n }
would define a new section, named “Introduction.” The “%” character defines
a comment, and everything from that character to the end of the line is com-mented out and will be ignored by L A TE X. To insert the “%” character into a doc-
ument, escape it with a backslash: \ % . To insert a backslash, use $ \ b a c k s l a s h $ .
This is true of other characters as well; use \ & to produce &, \ $ to produce $, \ #
to produce #,\ _
to produce _ and\ {
to produce {.
Quotes work a bit differently in L A TE X. To insert quote marks, use the form
` ` t e x t ' ' . That is, the ̀ character (top left of the keyboard) twice, followed by
the single quote character, ' , twice.
5.2 The preamble
Everything before the line \ b e g i n { d o c u m e n t } is part of the preamble. A typical
preamble might look like this:
6
![Page 7: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/7.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 7/21
\ d o c u m e n t c l a s s { a r t i c l e }
\ u s e p a c k a g e { g r a p h i c x }
\ u s e p a c k a g e { a m s m a t h , a m s t h m , a m s f o n t s }
\ t i t l e { T e s t }
\ a u t h o r { T e s t }
\ d a t e { }
In the example above:
• \ d o c u m e n t c l a s s { a r t i c l e } tells L A TE X that the document is an article.
Other classes include book, letter and slides
• \ u s e p a c k a g e { g r a p h i c x } tells L A TE X to use the graphicx package, which
allows users to include many types of graphics in their documents. Pack-ages are covered later on. The \ u s e p a c k a g e { a m s m a t h , . . . } command
invokes packages from the American Mathematical Society that extend
the functionality of L A TE X
• \ t i t l e { } and \ a u t h o r { } obviously define the title and author
• \ d a t e { } tells L A TE X to leave the data blank. \ d a t e { A p r i l 2 0 0 8 } would
print “April 2008” as the date. Leaving the \ d a t e { } line out would cause
L A TE X to use today’s date
The \ d o c u m e n t c l a s s { } command has options. For example,
\ d o c u m e n t c l a s s [ 1 1 p t , t w o c o l u m n ] { a r t i c l e }
would organize body of the document into two columns. Note that options are
separated by a comma. Other options include:
• o n e s i d e or t w o s i d e : change the margins for a one or two-sided docu-
ment
• l a n d s c a p e : change the document from portrait to landscape
• t i t l e p a g e or n o t i t l e p a g e : define whether there is a separate title page,
or if the title, author and date are presented at the top of the article
There are document classes other than article. The book class, for example,
is useful for writing books. By installing the beamer package, you can use the
beamer document class to make impressive presentations in L A TE X. For infor-
mation on other document classes, consult Google.
7
![Page 8: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/8.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 8/21
5.3 The document body
Everything after the preamble and between \ b e g i n { d o c u m e n t } and \ e n d { d o c u m e n t }
is part of the document body. Most of a L A TE X document is simply plain text. To
start a new paragraph, insert two carriage returns (blank lines). L A TE X will ignore
one blank line. To force a line break, use \ \ .
5.4 Document structure
A document’s structure is defined using \ s e c t i o n { } commands. L A TE X is strongly
based on well-structured documents. The structure tags include:
• \ s e c t i o n { N a m e }
• \ s u b s e c t i o n { N a m e }
• \ s u b s u b s e c t i o n { N a m e }
• \ p a r a g r a p h { N a m e }
To insert an unnumbered section, use the command\ s e c t i o n * { N a m e }
.
The section numbering will continue as normal with the next section, subsec-
tion, etc.
The \ p a r a g r a p h { } command doesn’t need to be included unless you want
to insert a heading for a paragraph. The image below shows the different struc-
ture commands in use:
8
![Page 9: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/9.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 9/21
1 Section command
Section star command
This section is not numbered.
2 Section command
Text here. The numbering continues normally.
2.1 Subsection command
Text here.
2.1.1 Subsubsection
Paragraph command This paragraph has a title.
6 Environments
Environments are special blocks of text. For example, the itemize and enumer-
ate environments create bulleted and numbered lists, respectively. The follow-
ing markup:
\ b e g i n { i t e m i z e }
\ i t e m F i r s t t h i n g
\ i t e m S e c o n d t h i n g
\ i t e m T h i r d t h i n g
\ e n d { i t e m i z e }
\ b e g i n { e n u m e r a t e }
\ i t e m F i r s t n u m b e r e d t h i n g
\ i t e m S e c o n d n u m b e r e d t h i n g
\ e n d { e n u m e r a t e }
would produce a bulleted list followed by a numbered list.Note that environments always begin with
\ b e g i n { e n v i r o n m e n t n a m e } and
end with \ e n d { e n v i r o n m e n t n a m e } . They can be nested, so one item of a bul-
leted list might contain another bulleted list, or a numbered list, etc.
Other frequently used environments include:
9
![Page 10: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/10.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 10/21
Quote\ b e g i n { q u o t e } . . . \ e n d { q u o t e } creates a section of indented, quoted
text
Verbatim \ b e g i n { v e r b a t i m } . . . \ e n d { v e r b a t i m } is similar to < p r e > in HTML.
In the verbatim environment, text is printed in a monospace font and
special characters (such as \ and %) are ignored. Verbatim is useful for
typing code tips
Description Description lists are similar to bulleted lists, with a bold item name
followed by a description:
\ b e g i n { d e s c r i p t i o n }
\ i t e m [ F i r s t i t e m ] D e s c r i p t i o n o f i t e m
\ i t e m [ S e c o n d i t e m ] D e s c r i p t i o n o f i t e m
\ e n d { d e s c r i p t i o n }
This list is presented using the description environment; the code sam-
ples in this document are presented using the verbatim environment.
7 Modifying text styles
A nice feature of L A TE X is that it absolves the author of most formatting duties.
Nevertheless, it’s still occasionally necessary to manually enter certain text for-
matting.
• To insert bold text, use \ t e x t b f { t e x t h e r e }
• To insert italic text, use \ e m p h { t e x t h e r e }
• To insert monospace text, use \ t e x t t t { t e x t h e r e }
• To use verbatim text within a sentence, use\ v e r b | y o u r t e x t h e r e |
.
Note that anydelimiter can be used, for example \ v e r b + y o u r t e x t h e r e +
will produce the same result
• To center a line, you can use
\ b e g i n { c e n t e r }
Y o u r t e x t h e r e
\ e n d { c e n t e r }
10
![Page 11: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/11.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 11/21
8 Packages
Packages extend L A TE X’s functionality. Package installation essentially consists
of two steps (after downloading the package, that is):
1. Running L A TE X on the i n s file to produce s t y or c l s files
2. Copying the newly created files to an appropriate directory and updating
the L A TE X database
However, there are exceptions. The filetypes s t y and c l s stand for style and
class, respectively. If a package does not come as an i n s file, but rather a s t y or
c l s file, it does not need to be processed with L A TE X, and you can skip directly
to step two. Also, running L A TE X on an i n s file usually produces a d t x file. Thisfile can be processed with L A TE X to create a manual for the package.
Note To process a package file ( i n s or d t x ) with L A TE X, just open that file with
your frontend and process it like you would a normal t e x file.
Hopefully, you’ll never need to do any of this. Most L A TE X distributions in-
clude automatic, graphical methods for finding and installing packages (in-
cluding gwTeX and MikTeX).
Windows The easiest way to install a package on a PC using MikTeX is to use
the MikTeX package manager, which is available through the Start Menu. Justopen the package manager, select a mirror (the location from which you will
download files), and navigate to the package that you want to install. MikTeX
will take care of the rest. Another nice feature of MikTeX is that if you are pro-
cessing a t e x file that requires a package that isn’t installed on your machine, it
will prompt you to download it.
OS X Launch i-Installer to browse through the available packages. Almost ev-
ery popular package is installed by default with gwTeX, so you may never need
to do this. To install a package on your Mac that isn’t available using i-Installer,
process the files as described above, and move thec l s
,s t y
and other files to˜/Library/texmf. If this directory does not exist, create it.
Next, I discuss some popular packages. These packages are already installed
with gwTeX and MikTeX, so there is no need to download and install them.
11
![Page 12: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/12.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 12/21
8.1 The graphicx package
The graphicx package allows you to insert images into a L A TE X document. To useit, first use the command \ u s e p a c k a g e { g r a p h i c x } in your document pream-
ble. Then, to insert a graphic, use the command:
\ i n c l u d e g r a p h i c s [ o p t i o n s ] { f i l e n a m e . p n g }
The graphicx package supports many filetypes, including PDF, PNG and
JPG. The options include:
• width=Xin
• height=Xin
• scale=X (where x is between 0 and 1)
You can also use, for example, the command w i d t h = . 8 \ t e x t w i d t h to scale a
picture to 80% of the width of your text. If you only use, say, the w i d t h option,
the height will be scaled proportionally; if you want to skew your image, you
need to specify both the height and width.
8.2 The geometry package
While formatting documents using L A
TE X is easy, changing those default formatscan be fairly difficult. The geometry package can make changing certain as-
pects of your document, including the margins, much easier. To change the
margins to 1" all around, for example, use:
\ u s e p a c k a g e [ m a r g i n = 1 i n ] { g e o m e t r y }
in your document’s preamble.
8.3 The AMS packages
The American Mathematical Society provides packages to make typesetting math-ematical documents easier. To use these packages, include the command
\ u s e p a c k a g e { a m s t h m , a m s m a t h , a m s f o n t s }
12
![Page 13: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/13.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 13/21
in the preamble of your document. The a m s t h m package allows you to include
Theorems, Propositions, Proofs, etc. in your document. Thea m s f o n t s
pack-age includes symbols that are not available in standard L A TE X—such asR (black-
board bold)—which I inserted using the command $ \ m a t h b b { R } $ . The a m s m a t h
package includes several environments and commands for displaying mathe-
matics. These commands, which are introduced in a later section, make certain
mathematical constructs much easier to typeset.2
8.4 Other packages
For just about every modification that you might want to make to a standard
L A TE X document, there is a pre-made package to help you do so. For exam-
ple, in this document, I have used the f o u r i e r package to change the font,the
h y p e r r e f package to make links clickable, and the
u r l package to make
URLs pretty. To learn more about the packages described, or to download new
packages, visit the Comprehensive TeX Archive Network (CTAN).3
9 Figures and tables
Figures and tables are L A TE X environments with special attributes, such as the
\ c a p t i o n { } command, which gives them titles within the document. They are
called float elements because their position in the final compiled document
depends on L A TE X’s style algorithm.
9.1 Figures
To insert a figure, use
\ b e g i n { f i g u r e } [ h b t p ]
\ c a p t i o n { F i g u r e n a m e }
\ b e g i n { c e n t e r }
\ i n c l u d e g r a p h i c s { f i l e n a m e . p d f }
\ e n d { c e n t e r }
\ l a b e l { y o u r - r e f e r e n c e - k e y }
\ e n d { f i g u r e }
2See the AMS-LaTeX page ( h t t p : / / a m s . o r g / t e x / a m s l a t e x . h t m l ) for complete docu-
mentation.3
h t t p : / / c t a n . o r g .
13
![Page 14: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/14.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 14/21
In the above markup,
• \ b e g i n { f i g u r e } simply tells L A TE X that there is a figure environment
•[ h b t p ]
determines how L A TE X will place the figure (here (h), bottom (b),
top(t), page(p)). L A TE X will first attempt to insert the figure at its insertion
point in thet e x
file. If this is not possible due to space or other aesthetic
considerations, it will try to place it at the bottom of the page, then at the
top of the page, then on a special page reserved just for float elements.
The order in which h, b, t and p are specified determines where L A TE X tries
to place the float first. To force the graphic to appear in its original place,
for example, you could put \ b e g i n { f i g u r e } [ h ] , omitting b, p and t
• \ c a p t i o n { F i g u r e n a m e } specifies the name of the figure
• \ b e g i n { c e n t e r } simply tells L A TE X to center the figure on the page. Don’t
forget to end the centering environment before you end the figure envi-
ronment
• \ i n c l u d e g r a p h i c s { . . . } specifies the location of the file that is being
inserted as a figure
• \ l a b e l { y o u r - r e f e r e n c e - k e y } is a label that you can use to refer to the
figure in the text. For example, if you label your figure “fig1” then you can
reference it later on by typing \ r e f { f i g 1 }
9.2 Tables
A floated table in L A TE X consists of two environments: “table,” the actual floated
entity in the text, and “tabular,” the data contained in the table. For example,
\ b e g i n { t a b l e } [ h b t p ]
\ c a p t i o n { T h i s t a b l e i s a n e x a m p l e }
\ b e g i n { c e n t e r }
\ b e g i n { t a b u l a r } { c | c c }
F i r s t r o w , f i r s t c o l u m n &
F i r s t r o w s e c o n d c o l u m n &
F i r s t r o w , t h i r d c o l u m n \ \ \ h l i n e
S e c o n d r o w , f i r s t c o l u m n &
S e c o n d r o w , s e c o n d c o l u m n &
14
![Page 15: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/15.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 15/21
S e c o n d r o w , t h i r d c o l u m n \ \
T h i r d r o w , f i r s t c o l u m n &
T h i r d r o w , s e c o n d c o l u m n &
T h i r d r o w , t h i r d c o l u m n \ \
\ m u l t i c o l u m n { 3 } { c } { . . . }
\ e n d { t a b u l a r }
\ e n d { c e n t e r }
\ l a b e l { e x a m p l e t a b l e }
\ e n d { t a b l e }
would produce Table 1.
Table 1: This table is an example
First row, first column First row second column First row, third column
Second row, first column Second row, second column Second row, third column
Third row, first column Third row, second column Third row, third column
...
Everything except the code between \ b e g i n { t a b u l a r } . . . \ e n d { t a b u l a r }
is the same as the figure environment described above. Here’s how the tabular
environment works:
• \ b e g i n { t a b u l a r } { c | c c } tells L A TE X to start a new tabular environment
with three centered columns. The bar (“| ”) after the first “c”, tells L A TE X
that the first column has a vertical border. Using { l c r r }
would create
four columns, the first left aligned, the second centered, and the third
and fourth right aligned
• Table cells are separated by “&” and table rows are separated by “\ \ ”
• \ h l i n e creates a horizontal line
• \ m u l t i c o l u m n { 3 } { c } { T e x t h e r e } creates a row that spans all three columns,
is centered, and contains the text “Text here”
15
![Page 16: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/16.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 16/21
There are more complicated options for creating and inserting tables, but
the rules above cover the commands needed to create most basic to intermedi-ate tables.4
10 Annotations
L A TE X is capable of automatically creating important annotations, such as foot-
notes, cross references, tables of contents and bibliographies. Note that, since
the following commands require L A TE X to automatically number text elements,
L A TE X must be run on your document twice for proper display.
10.1 Footnotes and endnotes
To insert a footnote, simply type \ f o o t n o t e { t e x t h e r e } . L A TE X will automati-
cally insert the footnote number and text.5
To use endnotes, first invoke the endnotes package in the preamble:
\ u s e p a c k a g e { e n d n o t e }
and use the command\ e n d n o t e { T e x t }
to create new endnotes. At the point in
your document where you want the endnotes to appear, simply type \ t h e e n d n o t e s .
10.2 Cross referencesTo reference a labeled Equation, Table or Figure, use \ r e f { y o u r - r e f e r e n c e - k e y }
where “your-reference-key” is the argument to the \ l a b e l { y o u r - r e f e r e n c e - k e y }
command in the table or figure environments.
10.3 Table of contents
To insert a table of contents, simply put \ t a b l e o f c o n t e n t s at the beginning of
your document.
4MS Office users can try Excel2L A TE X ( h t t p : / / w w w . c t a n . o r g / t e x - a r c h i v e / s u p p o r t /
e x c e l 2 l a t e x / ), which does the same thing using Excel spreadsheets. OpenOffice users can
use Calc2L A TE X ( h t t p : / / c a l c 2 l a t e x . s o u r c e f o r g e . n e t ) to convert between Calc spread-
sheets and L A TE X tables. Both utilities are cross-platform.5To create an “attribution” footnote, where the first footnote is marked by an asterisk, use
the \thanks{text here} command.
16
![Page 17: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/17.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 17/21
10.4 Bibliography
To create a bibliography, insert a list of the citations at the end of your docu-ment, using the form:
\ b e g i n { t h e b i b l i o g r a p h y } { 9 9 }
. . .
\ b i b i t e m { k e y 1 } G a r d n e r , J o h n . 2 0 0 6 .
` ` \ L a T e X { } : f r o m b e g i n n e r t o \ T e X p e r t . ' '
\ e m p h { D a t a n i n j a } . A v a i l a b l e o n l i n e a t
\ t e x t t t { h t t p : / / g e n e r a l d i s a r r a y . w o r d p r e s s . c o m } .
. . .
\ e n d { t h e b i b l i o g r a p h y }
You must manually type the bibliography entries. To refer to an item within
the text, use\ c i t e { k e y }
[1]. The{ 9 9 }
tells L A TE X that there a maximum of 99
entries in the bibliography. L A TE X needs to know this so it can correctly justify
the bibliography entries with their numbering on the left.
A more efficient way to create bibliographies is to use BibTeX, which allows
you to maintain a database of citations and call them as needed in your bibliog-
raphy. There are also graphical tools for managing your reference databases, so
you don’t have to hard code the citations, and can easily change them to differ-
ent formats. However, BibTeX is too complicated to explain in this document.
For an introduction, see h t t p : / / b i b t e x . o r g .6
11 Inserting mathematics
There are several ways to include mathematical notation in L A TE X documents.
11.1 Inline math
To include some mathematical notation within a paragraph, without offsetting
from the rest of the text, enclose the notation between dollar signs. For exam-
ple,$ a ^ 2 + b ^ 2 = c ^ 2 $
would produce a 2
+b 2
=c 2.
6To insert references that look like Author (2008) or (Author 2008), use the natbib package.
17
![Page 18: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/18.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 18/21
11.2 Display math
The displaymath environment lets you offset some mathematical notation fromthe rest of the document. The code
\ [
a ^ 2 + b ^ 2 = c ^ 2
\ ]
would create a paragraph break and center the equation on the page, like this:
a 2+b 2 = c 2.
11.3 Equation
The equation environment can be used to place numbered equations in the
text. For example,
\ b e g i n { e q u a t i o n } \ l a b e l { p y t h a g }
a ^ 2 + b ^ 2 = c ^ 2
\ e n d { e q u a t i o n }
would offset the equation just like the displaymath version did, but it would
have a number in parenthesis on the right, and you would by able to call it in
the text by typing, for example, “as we see in equation\ r e f { p y t h a g } . . .
”
11.4 Align
The align environment allows you to align parts of equations at the equal sign.
For example,
\ b e g i n { a l i g n } \ l a b e l { m y e q n }
a & = b + c \ \
d & = e + f
\ e n d { a l i g n }
would produce
a = b +c (1)
d = e + f (2)
18
![Page 19: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/19.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 19/21
Notes You must have invoke the a m s m a t h package in order to use the align
environment. Also, it is possible to suppress the numbering by using the com-mands \ b e g i n { a l i g n * } and \ e n d { a l i g n * } . Labeling works the same for the
align and equation environments. A shortcut to referencing an equation is the
command \ e q r e f { l a b e l } . For example, \ e q r e f { m y e q n } produces (1).
11.5 Mathematical notation
There are many commands for inserting specific mathematical operators and
symbols into equations. They can all be found online, and as always, use Google
if you can’t figure out a specific command. The following are some common
operators and commands.
Greek letters Generally, just use the spelled-out letter. For example, \ b e t a
produces β and \ e p s i l o n produces . For upper case, capitalize the letter:
\ G a m m a produces Γ while \ g a m m a produces γ.
Misc. symbols L A TE X can produce almost any symbol; the following are just a
few examples. \ l e f t a r r o w produces ←. Use \ L e f t a r r o w for a double arrow:
⇐. Similarly, \ r i g h t a r r o w produces → and \ L e f t r i g h t a r r o w produces ⇔.
For≤, ≥, use \ l e q (less than or equal to), \ g e q (greater than or equal to).
Indexing and exponents Subscripts are denoted using the underscore (x _ i
)and superscripts use the ̂ key ( a ^ 2 ). To type “i j ,k ” you need to write i _ { j , k }
to tell L A TE X that the “j,k” comprises the entire subscript. The bracket characters
are generic grouping operators in L A TE X, and they won’t appear in your docu-
ment.
Some operators \ s u m { 1 / x } produces
1/x and \ s u m _ { i = 1 } ^ { \ i n f t y } { x _ i }
produces∞
i =1 x i . Other operators include \ p r o d (
), \ i n t (
), \ s i n , \ l o g ,
\ a r g , \ m a x (combine them as \ a r g \ m a x _ x f ( x ) to get argmax x f (x )), \ l i m ,
\ s q r t , etc. To produce, for example, a cube root, use the command \ s q r t [ 3 ] { x }
( 3
x ). Note that, for operators, L A TE X automatically chooses the appropriate lo-
cation for arguments and subscripts. For example, if \ i n t _ 0 ^ 1 f ( x ) d x is in-
line, it looks like1
0 f (x )d x , whereas if it is displayed math, it looks like1
0 f (x )d x .
19
![Page 20: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/20.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 20/21
Decorations\ h a t { x } puts a hat over x (x̂ ), as does \ h a t x (use the former if
there are multiple characters under the hat). Similarly,\ t i l d e { x }
produces x̃ ,\ b a r { x } produces x̄ , \ u n d e r l i n e { x } produces x , \ v e c x producesx , etc. You
can use the \ o v e r s e t and \ u n d e r s e t commands to place labels over symbols.
For example, x \ o v e r s e t { p } { \ r i g h t a r r o w } b produces x p → b .
Fractions Use \ f r a c { a } { b } to display ( a b ).
Brackets For brackets use “(”, “[” or \ { and \ } for “{” and “}”. However, if
you need stretched brackets, use \ l e f t ( . . . \ r i g h t ) or \ l e f t \ { < m a t h h e r e >
\ r i g h t \ } . For example,
\ l e f t [ \ f r a c { 1 } { 2 } \ r i g h t ]
produces 1
2
.
Matrices To insert a matrix with square brackets, use
\ [
\ b e g i n { b m a t r i x }
a & b & \ c d o t s & c \ \
\ v d o t s & \ v d o t s & \ d d o t s & \ v d o t s \ \
d & e & \ c d o t s & f
\ e n d { b m a t r i x } .
\ ]
Once again, you must invoke the a m s m a t h package The code shown above would
produce:
a b · · · c ...
.... . .
...
d e · · · f
.
Other matrix types include p m a t r i x for a matrix with parenthetical brackets
and c a s e s to define, for example, a piecewise function. Notice, in the above,the various “dots” commands. Another useful one is
\ l d o t s which inserts an
elipsis . . . The reason for the command, rather than simply typing three periods,
isthatL A TE X precisely controls the spacing of the elipsis according typographical
standards.
20
![Page 21: texpert2](https://reader030.fdocument.pub/reader030/viewer/2022021117/577d1f481a28ab4e1e9043d1/html5/thumbnails/21.jpg)
8/2/2019 texpert2
http://slidepdf.com/reader/full/texpert2 21/21
Other tips To insert a space within an equation, use \ q u a d for a space the
width of an “M” or\ q q u a d
for twice that much space. To put some ordinary text within a math environment, use \ t e x t { } . For example:
y _ i = \ a l p h a + \ b e t a x _ i + \ v a r e p s i l o n _ i \ q q u a d e _ i \ s i m N ( 0 , \ s i g m a ^ 2 )
\ q u a d \ t e x t { A b a s i c l i n e }
would produce:
y i =α+βx i +εi e i ∼N (0,σ2) A basic line
For help with other symbols and operators, see the American Mathematical
Society’s Short Math Guide for L A TE X .7
12 For further reference
The instructions above cover many of the basic functions of L A TE X, but there are
many more. A good, thorough introduction is The L A TE X Primer (PDF). I have
other tools and references on my data analysis weblog Dataninja.
References
[1] Gardner, John. 2006. “L A TE X: from beginner to TE Xpert.” Dataninja . Avail-able online at h t t p : / / d a t a n i n j a . w o r d p r e s s . c o m .
[2] Indian TE X Users Group. 2003. “L A TE X Tutorials: A primer.” Available on-
line at h t t p : / / s a r o v a r . o r g / f r s / d o w n l o a d . p h p / 1 2 0 / l t x p r i m e r - 1 .
0 . p d f .
7f t p : / / f t p . a m s . o r g / p u b / t e x / d o c / a m s m a t h / s h o r t - m a t h - g u i d e . p d f .
21