Você está na página 1de 20

Quite Short L

A
T
E
X Introduction
Weijie Chen

Department of Economics
University of Helsinki
6 July, 2011
Contents
1 Buckle Your Seatbelt 3
2 Start! 7
3 Put It Nicely 9
3.1 Cross reference . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2 Footnote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3 Emphasize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.4 Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.5 Enumeration . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.6 Loading a picture . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.7 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4 Queen of Science 12
4.1 Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.2 Super- and Subscript . . . . . . . . . . . . . . . . . . . . . . . 13
4.3 Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5 Beamer 16
6 Miscellaneous 18
6.1 Your Command . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.2 Change Style . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.3 Some marks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
6.4 Spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
6.5 Umlaut . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

If you have any questions or comments, send email to weijie.chen@helsinki.


1
List of Figures
1 T
E
XnicCenter interface . . . . . . . . . . . . . . . . . . . . . . 4
2 LyX interface . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3 T
E
Xmaker interface . . . . . . . . . . . . . . . . . . . . . . . . 5
4 Lake Louise in Canada . . . . . . . . . . . . . . . . . . . . . . 11
5 Reserved picture . . . . . . . . . . . . . . . . . . . . . . . . . 12
6 Beamer Title Page . . . . . . . . . . . . . . . . . . . . . . . . 17
2
Abstract
This article is used for helping you quickly master some essential
L
A
T
E
X skills, especially used for writing your class exercise, nal paper
or graduation thesis. L
A
T
E
X can be very confusing for beginners, since
it is not WYSIWYG
1
at all. In the very beginning when you learn
L
A
T
E
X, you desperately watch bunches of L
A
T
E
X source codes on the
computer screen which distracts you away from your initial intention,
consuming most of your energy on handling with codes rather than
your thought. I undertand, I had been through this before. Thus I
write this article to extract all essential stu which might help you
learn as quickly as possible, and of most importance, at lowest pain.
Hence excuse my informal languages in this article, I have no intention
to make this article read like an academic paper which merely brings
you more pain.
1 Buckle Your Seatbelt
For those people who want to pursue an academic career, L
A
T
E
X is absolute
necessity. Dont anticipate that you could submit a Ph.D. dissertation writ-
ten by MS word. In a word, unprofessional. When you were in classroom,
watching teacher clicking folders in his/her USB, didnt you notice that most
of your teachers do not use Powerpoint to show you his/her course slides?
He/she usually opens a pdf le, then it becomes course slides, and it looks
rather neat and nice-looking. I can assure you, these slides were made by
L
A
T
E
X. You must have following experience when dealing with MS word,
although it is considerably straighforward, it seems always inconsistent in
everything, such as fonts change, line space diers, picture unproportionally
scales, messes of footnotes, chaos of bibliography. . . Well, I might have ex-
agerated a little bit, you might also turn fastidious with MS Oce after you
get to know L
A
T
E
X quite well. You even get a basic sense of how L
A
T
E
X out-
put look like from reading my article, since my article is compile by L
A
T
E
X,
I guess you will notice lots of dierences from MS Word.
L
A
T
E
X is not a word processor programme, it is a typesetting system.
From my perspective, it can be regarded as script programming
2
. But this
system is embedded into some window interface programme into which you
can type your articles. I recommend some programmes here, once you get
familiar with one, you can try others, but dont start with several together.
1. T
E
XnicCenter
This is my favourite, most of time I use this IDE
3
to typeset my article.
1
What you see is what you get. Microsoft Word and Powerpoint belongs to this
catagory.
2
If you do not know this terminolgy from computer programming, dont bother.
3
Integrated development environment, again, dont bother.
3
interface.png
Figure 1: T
E
XnicCenter interface
2. L
Y
X L
Y
X is designed to have word processor interface, which makes
it rather easy to get hands on, very suitable for absolute beginners.
But its output layout setting is dierent from standard thesis writing
setting, and if you dont know how to reset, it might be a problem.
Lots of universities privided on their computers.
3. T
E
Xmaker
A rather popular IDE among L
A
T
E
X users. Simple and neat interface,
wont make you feel lost.
They are all free to download from their website, just go to their website
and browse the instruction, it wont take more than 10 minutes. Before
installation of these programme, you should install MiKT
E
X rst, which is
the core of everything else, packages gather in it.
Now take a look at this,
\sum_{i=1}^k=\boldsymbol{X}_tu_t
This is how we compile mathematics in L
A
T
E
X, rather scary? Dont
worry, you will get used to it. The output of this line will be
k

i=1
= X
t
u
t
Here is more, you will get the basic sense how we work in L
A
T
E
X environment,
4
interface.png
Figure 2: LyX interface
interface.png
Figure 3: T
E
Xmaker interface
5
\begin{equation*}
\begin{bmatrix}
x_{11} & x_{12} & \cdots & x_{1k}\\
x_{21} & x_{22} & \cdots & x_{2k}\\
\vdots & \vdots & \ddots & \vdots\\
x_{n1} & x_{n2} & \cdots & x_{n3}
\end{bmatrix}
\begin{equation*}
I know you get a headache, but here is the output, quite nice, right?

x
11
x
12
x
1k
x
21
x
22
x
2k
.
.
.
.
.
.
.
.
.
.
.
.
x
n1
x
n2
x
n3

So I said it is very confusing in the very beginning, it seems you have to


remember endless meanless codes before you even start writing your thesis.
But this is the right path to walk, you work through some simple example
and develop your own style. The more you get in touch with L
A
T
E
X, the
more you will know its temper.
6
2 Start!
Now I want to you to try set up your rst L
A
T
E
X le, just follow all lines
below, put them into your L
A
T
E
X typesetting programme.
\documentclass[11pt,a4paper]{article}
\usepackage{amssymb,amsthm,amsmath,amsfonts}
\usepackage{mathrsfs,syntonly,graphicx,color,hyperref}
%\syntaxonly
\title{My first \{LaTeX} file}
\author{Your name here!}
\date{6 July, 2011}
\begin{document}
\maketitle
\section{My first section}
This is awesome! Haha!
\section{My second section}
I am hungry\ldots
\end{document}
Well, you have successfully make your rst step, now let me briey
explain what we did in those lines. There is a name for area between
\documentclass{article} and \begin{document}, it is called preamble.
The rst line \documentclass[11pt,a4paper]{article}, indicates what
kind of project you are working on, article, book, or slides, etc. And through-
out all le, font size will be set at 11 points, and A4 paper size.
Second and third line requires L
A
T
E
X distribution to load various package
to help you complete your project. Because initially L
A
T
E
X does not have so
much function, or we could say it is rather limited. So dierent institutes
provides their package to increase L
A
T
E
Xs exibility. American Mathemat-
ical Sociaty provides several packages, which makes L
A
T
E
X almost can deal
with any kinds of math notation you can imagine. I guess, you can guess
from the names of the package to some extent. syntonly is used as checking
syntax correction, if you load this package, and you have \syntaxonly on
next line, your L
A
T
E
X platform does not produce output, such as .pdf or .dvi,
it only check the syntax, which will save some time when you are running
some huge projects. graphicx is a must if you need to load picture into
your article. color package change the fonts colour as I did here.hyperref
will package is very useful, it makes all your reference in pdf le into hyper-
link, which could zap you to the point in the article you refer to by just
clicking it, try this 1, go to gure 1. After all these explanation, I would
rather suggest you no matter what you write, just load them all, put them
7
into your favourite template, since computer nowadays is so fast, loading
package time is almost neglectable.
Continue, title, author, date is straightforward, needless to explain,
help yourself.
\maketitle
\section{My first section}
This is awesome! Haha!
\section{My second section}
I am hungry\ldots
\end{document}
Note that this is the body of article, between \begin{document} and
\end{document}. is must, unless you dont want a title of your article.
Beside title, you might need contents, you also can use \tableofcontents,
\listoffigures and \listoftables, just put them there, you will see
the eect later on. \section{} is the rst structrual level of an article,
then \subsection{} and \subsubsection{}. If you are writing a book,
\documentclass{book}, \chapter{} will be the rst structrual level.
Now you have the basics of L
A
T
E
X, just go write some basic stu!
8
3 Put It Nicely
I present all most frequently used function here, I presume that almost every
thesis writing would need these basic skills.
3.1 Cross reference
When you want to refer to a sentence or a word, just put \label{} at the
end of that sentence or word, write anything you want in that bracket so
be the unique label. Next, you set up and hyperlink by using \ref{}, the
content in the curly braces should be exactly the same as in \label{}, which
you intend to refer to. If you are referring to an equation, you should use
\eqref{}, referring a page, you should use \pageref{}.
3.2 Footnote
This is an article teaching you\\
how to use {\LaTeX}.\footnote{ See? This is footnote.}
Follow the example above, \footnote{}, is the command you want to
write footnote. The same, write them in curly braces.
3.3 Emphasize
Let me put this straight, in a printed book or a thesis you do not em-
phasize a word by using boldfonts. You do this by either emphasize
them or emphasize them. The command accordingly are, \emph{} and
\underline{}. But underline is used very rarely and old-fashioned, I sug-
gest you use former one.
3.4 Environment
This is environment,
\begin{document}
\begin{abstract}
\end{abstract}
\begin{equation}
\begin{bmatrix}
\end{bmatrix}
\end{equation}
\end{document}
9
it always starts with \begin{}. Ends with \end{}. In the curly braces,
you write what environment you intend to get into. Within
\begin{document}
...
\end{document}
is the main body as I said before. Inside abstract environment,
\begin{abstract}
...
\end{abstract}
you write you abstract. Equation environment,
\begin{equation}
...
\end{equation}
brings you into math mode, where you start a seperate line to write your
mathematics. We will come back to \begin{bmatrix}...\end{bmatrix}
later.
3.5 Enumeration
Just follow commands below, you will get it, it is easy.
\begin{enumerate}
\item Microeconomics
\item Macroeconimics
\item Econometrics
\end{enumerate}
Last one is enumerate environment, it marks numbers in front of item,
if you do not need numbers, try this
\begin{itemize}
\item Microeconomics
\item Macroeconimics
\item Econometrics
\end{itemize}
10
As always, I also put output here for your comparsion,
1. Microeconomics
2. Macroeconimics
3. Econometrics
Microeconimics
Macroeconimics
Econometrics
3.6 Loading a picture
First you should prepare a picture in the same folder as you current com-
piling .tex le. Then we use gure environment.
\begin{figure}
\centering
\includegraphics[width=12.5cm]{name of your picture}
\caption{Enter your caption here} \label{fig1}
\end{figure}
\centering is used to put picture in the center, not left or right. Then
just put the exact same name of the picture under same folder into that
curly braces, then enter captions whatever you want. Here I load a picture
from my computer 4.
Sometimes you know you need to put picture right at some place, but
the problem is you havent drawn yet, you just keep writing, then you might
Lake.jpg
Figure 4: Lake Louise in Canada
11
really forget about this, if you thesis writing lasts long enough (which I
hope not!). So you probably should insert an empty box 5 here to reserve
the place for images, inorder to remind the truth-not yet.
This is where I reserved my picture!
Figure 5: My reserved place for picture
3.7 Bibliography
Do you ever wonder what is the dierence between bibliography and refer-
ence? I wondered it too, I even asked my teacher. However opinions varies.
But in L
A
T
E
X, bibliography is used in book environment, and reference is
used mainly in article environment.
\begin{thebibliography}{99}
\bibitem{spanos} Spanos A. (1986):
\emph{Statistical foundations
of econometric modelling.},
first edition,
Cambridge University Press
\end{thebibliography}
Above is the thebibliography environment, dont worry about whether it
is called bibliography or reference, L
A
T
E
X will choose for you. Just follow
them, put your own content in curly braces. Note that in \bibitem{dou},
dou is a marker, or label, it connects the place you mention the references
by a hyperlink. You just need to type in a \cite{dou} at the place you
refer.
4 Queen of Science
Yes, Guass said . . . . However, mathematics gives lots of student nightmare,
sometimes is due to wrongly presentation. When you open a book, full
of formulas and hard-reading sub- or superscripts, acompanied by endless
overwhelming paragraphs. Besides nausea, I cannot imagine other proper
reactions. If you deny that typesetting also disgust you from reading, just
imagine there is novel written on the wall which is 10 metres long, will you
be happy reading it?
In this section, I only teach you how to use these codes, but I do not
teach what codes are, it is meaningless for me to reproduce those math
symbos here, there are great bunch of table made for easy reference. You
can check other real references, such as The Not So Short Introduction to
12
L
A
T
E
X2

[1]. Remember, this is only scratching the surface of the surface,


but enough is good.
4.1 Equations
If you want to input mathematics within text, you use $...$, if seperatately,
use \begin{equation}...\begin{equation}. If we replace equation by
equation*, numbers are removed. But sometimes you need to have your
own mark on equations, rather than numbers, you can use \tag{} to change
any mark you like, put any word or number in the curly braces you like. See
below
\begin{equation*}
s^2=\frac{1}{n}\sum_{t=1}^n\hat{u}_t
\tag{ice_cream}
\end{equation*}.
And result is
s
2
=
1
n
n

t=1
u
t
. (ice cream)
I tag it as ice cream.
There is one situation when you have several equations, impossible to
put them in a single line, you align them by setting a reference point.
\begin{align*}
a-c+b-d&=x+y+z\\
&=e+f+g+h+i\\
&=j+k+l+m+n+o+p
\end{align*}
Notice that you put a & in front of the reference point, equations beneath
will follow at that point. Result is
a c + b d = x + y + z
= e + f + g + h + i
= j + k + l + m + n + o + p
4.2 Super- and Subscript
Easy, ^2 and _2 are super- and subscript respectively. Try these, x^7,
x^{abcde}, X^{abc}_{123}, X^{b^a}_{c_d}. Output are below,
x
7
x
abcde
X
abc
123
X
b
a
c
d
.
Besides, integration, summation and product operators, all can need super-
and subscript.
13
\begin{equation*}
\int_a^b{\frac{x^2}{\pi}} \,\mathrm{d}x
\qquad \prod_{t=1}^n\beta^tE(u_t)
\end{equation*}
Check your result,

b
a
x
2

dx
n

t=1

t
E(u
t
)
4.3 Matrix
Now I want you to look back 1. Try to gure out how it works, read slowly.
I present another kind of matrix notation here,
\begin{equation*}
\begin{pmatrix}
x_{11} & x_{12} & \cdots & x_{1k}\\
x_{21} & x_{22} & \cdots & x_{2k}\\
\vdots & \vdots & \ddots & \vdots\\
x_{n1} & x_{n2} & \cdots & x_{n3}
\end{pmatrix}
\begin{equation*}
Did you notice the dierence of our command, here I use
\begin{pmatrix}...\end{pmatrix}. It looks like,

x
11
x
12
x
1k
x
21
x
22
x
2k
.
.
.
.
.
.
.
.
.
.
.
.
x
n1
x
n2
x
n3

If you want to write a matrix multiplication, you just write several matrices
in a same equation environment.
\begin{equation*}
\begin{bmatrix}
x_{11} & x_{12} & \cdots & x_{1k}\\
x_{21} & x_{22} & \cdots & x_{2k}\\
\vdots & \vdots & \ddots & \vdots\\
x_{n1} & x_{n2} & \cdots & x_{n3}
\end{bmatrix}
\begin{bmatrix}
\beta_1\\
14
\beta_2\\
\vdots\\
\beta_3
\end{bmatrix}
=
\boldsymbol{X}\boldsymbol{\beta}
\end{equation*}
It is actually not that complicated as it seems, just put two matrices
together,

x
11
x
12
x
1k
x
21
x
22
x
2k
.
.
.
.
.
.
.
.
.
.
.
.
x
n1
x
n2
x
n3

2
.
.
.

= X
But here is one more situation it might end up like this, if you use code
above to compile this matrix, some number with a negative sign,

1 8 3 2 4
0 1 2 9 2
0 0 3 1 5
0 0 0 5 4
0 0 0 0 6

It looks really unprofessional and unserious. We have another environment


for this \begin{array}...\end{array}. Codes becomes
\begin{equation}
\left[
\begin{array}{rrrrr}
1 & 8 & 3 & -2 & 4\\
0 & -1 & -2 & 9 & 2\\
0 & 0 & 3 & 1 & 5\\
0 & 0 & 0 & 5 & -4\\
0 & 0 & 0 & 0 & 6
\end{array}
\right]
\end{equation}
Try this one by yourself. {rrrrr} means set every column right-aligned.
And this environment does not provide delimitor, such as brackets or paren-
theses, so it is your responsibility to put brackets on \left[...\right].
But there is another way to do this, \llap{} commmand, but you have
to load gauss package in preamble, we have another matrixas follow:
15
\begin{equation*}
\begin{bmatrix}
1 & 8 & 3 & \llap{-}2 & 4\\
0 & \llap{-}1 & \llap{-}2 & 9 & 2\\
0 & 0 & 3 & 1 & 5\\
0 & 0 & 0 & 5 & \llap{-}4\\
0 & 0 & 0 & 0 & 6
\end{bmatrix}
\end{equation*}
And corresponding ouput is:

1 8 3 -2 4
0 -1 -2 9 2
0 0 3 1 5
0 0 0 5 -4
0 0 0 0 6

5 Beamer
One of the most important documentclass is beamer, it is used to creat
you fancy slides, when you are on a presentation of your thesis to your
superviser and other defense opponents. The time of Powerpoint is gone. I
barely see any professors using Powerpoint, since it kind of degenerate the
rigourous level of your presentation. If you need to crush some slides to
give a course presentation tomorrow morning, you use Powerpoint to make
fast slides, no one will blame you. But be careful, when you present your
stu among academia, appearance matters as well as contents. Here is one
beamer sample,
\documentclass{beamer}
\mode<presentation>
\usepackage{amssymb,amsthm,amsmath,}
\usepackage{graphicx,verbatim,textcomp}
\usepackage{amsfonts,mathrsfs,syntonly}
\usepackage{color,hyperref}
\usetheme{Frankfurt}
%\usecolortheme{lily}
\title{How to Cook Instant Noodles}
%\subtitle{}
\author{Weijie Chen}
\institute{\scriptsize Department of Economics\\
16
noodle.pdf
Outline General overview of the project Last 6 months Next 6 months
How to Cook and Eat Instant Noodles
Weijie Chen
Universiteit van Amsterdam
11 July, 2010
Weijie Chen How to Cook and Eat Instant Noodles
Figure 6: Beamer Title Page
\vspace{.10cm}Universiteit van Amsterdam}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\section*{Outline}
\begin{frame}
\tableofcontents
\end{frame}
\section{What is Instant Noodle}
\subsection{Ingredients}
Instant noole is made of \cdots
\end{document}
17
\usetheme{Frankfurt} is a theme package named Frankfurt, almost
all theme package names are named after a city or town, for more detailed
information you should check The Beamer class User Guide[2]. However, as
you can see, it is no signicant dierence than compiling articles or books,
you just need to use \begin{frame}...\end{frame} to make a slide, ane
ll in it with your own content, such mathematics, pictures, etc. However if
you need far more function than this plain sample, you need to study The
Beamer class User Guide[2], it is a rather long manual.
6 Miscellaneous
Rest of things I put here, it might be more interesting to explore L
A
T
E
X by
yourself.
6.1 Your Command
Working on L
A
T
E
X can be very time consuming especially you have huge
bunches of math symbol to deal with. If you repeatedly use some com-
mands, and they are combination of several, you might consider to use a
new command to replace them, not really replace, just a self-made con-
densed version. Say you have to type in

X
1
thousands of times in your
le, it is rather boring. Now we set a new command for it. Put this
\newcommand{\bx}{\boldsymbol{\hat{X}}_{\!{1}}} at your preamble.
Then try this
\begin{equation*}
\bx
\end{equation*}
See? Quite convenient.
6.2 Change Style
Take look at this rst,

n
i=1
x
i

n
i=1
y
i

n
i=1
y
i

n
i=1
x
i
y
i

As you have already notice that summation operation does not display as its
usual form, because they are in a matrix. If summation, product, integral
operation will be displayed like this if you put them into matrix or fraction.
You might want to use \displaystyle{} to turn it back. Just put the
18
summation into its curly braces,

i=1
x
i
n

i=1
y
i
n

i=1
y
i
n

i=1
x
i
y
i

you have seem the modied output, it looks not so intensive as the rst one,
so I suggest you be careful when use some command to override L
A
T
E
Xs
preset command.
6.3 Some marks
Did you ever use yet? LaTeX usually does not display like, and it has
dierent input than it looks like, if you want to put quotation mark such as
Know thyself.
Note that the rst mark, is , is the button on the left of number 1 on
an American keyboard layout.
6.4 Spacing
From an aesthetic view, mathematics should present in a gentle way, not any
surpassingly spacing, not any exceedingly constringing. Put mathematics in
a readable, or attractive manner is an art! The appearance of an article is
should be decorated just like a room, put things in the right place, it shines.
Let me show you two examples,

b
a
sin

2
du

f(x, y, z)dxdydz
do you feel any uncomfortable when wathcing them? Spacing! The codes
are follows,
\begin{equation*}
\int_a^b\sin{\frac{\pi}{2}}\mathrm{d}u
\qquad \int\int\int{f(x)}\mathrm{d}x{d}y{d}z
\end{equation*}
When you are dealing with micro-distance between symbols within an
expression, you use \! to shrink, and \, to expand space. Now it becomes,

b
a
sin

2
du

f(x, y, z) dxdy dz.
Here is the codes,
19
\begin{equation*}
\int_a^b\sin{\frac{\pi}{2}}\,\mathrm{d}u
\qquad \int\!\!\int\!\!\int{f(x,y,z)}
\,\mathrm{d}x\,\mathrm{d}y\,\mathrm{d}z.
\end{equation*}
6.5 Umlaut
You probably would write your thesis in a languge other than English, maybe
German, Swedish, Finnish. You might need to use letters such as a, o, u.
In German, they are called umlaute. Here is a small table,
a o u a c o
\"a \"o \"u \aa \^c \c o
Table 1: Most frequent acute symbols
The End.
References
[1] Oetiker T.(2010): The Not So Short Introduction to L
A
T
E
X2

, version
4.31
[2] Wright J. and Miletic V. (2010): The Beamer Class User Guide
20

Você também pode gostar