Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
1
How to get started in LATEX
Florence Bouvet
2
Introduction
LATEX is a document preparation system for high-qualitytypesetting.LATEX is not a word processor! Instead, LATEX encourages authorsnot to worry too much about the appearance of their documents,but to concentrate on getting the right content.
3
Disadvantages
I One can’t see the final result straight away.
I One needs to know the necessary commands for LaTeXmarkup.
I It can sometimes be difficult to obtain a certain ’look’.
4
Advantages
On the other hand, there are certain advantages to the markuplanguage approach:
I The document looks professional. The layout, fonts, tables,etc. is consistent throughout.
I Mathematical formulae can be easily typeset.
I Indexes, footnotes, references, etc., are generated easily.
I It encourages correctly structured documents.
I It is available (and transportable) across many platforms(Windows, Mac, Unix and Linux are all supported).
5
I Typesetting journal articles, technical reports, books, and slidepresentations.
I Control over large documents containing sectioning,cross-references, tables and figures.
I Typesetting of complex mathematical formulae.
I Advanced typesetting of mathematics with AMS-LATEX.
I Automatic generation of bibliographies and indexes.
I Multi-lingual typesetting.
I Inclusion of artwork, and process or spot color.
I Using PostScript or Metafont fonts.
6
Some very Basics
What you need to get started:
I MikTex (http://www.miktex.org/)
I an Editor, such as WinEdt. (http://www.winedt.com/)
7
Document StructureLatex practically forces you to declare structure within yourdocuments. Let’s take the example of the structure of an article.Preamble This is everything from the start of the Latex file to the\begin{document} command.It contains commands and packages that affect the entiredocument.Here is for example what I wrote to start this introduction to LATEX.
\documentclass[12pt, letterpaper]{article}\setlength{\topmargin}{-0.8in}\setlength{\textwidth}{6.6in}\usepackage{hyperref}\usepackage{indentfirst}\renewcommand{\baselinestretch}{1.24}
8
The class is given by the \documentclass{...} command. ValidLaTeX document classes include:
I articleI reportI letterI bookI slides
Top Matter At the beginning of most documents will beinformation about the document itself, such as the title and date,and also information about the authors, such as name, address,email etc.
\title {How to get started in LATEX}\author {Florence Bouvet, based onhttp://en.wikibooks.org/wiki/LATEX}\date{today } \maketitle
9
Abstract Here is what the command looks like:
\begin {abstract}blablabla..... \end {abstract }
10
Main body and Sectioning Commands The commands forinserting sections are quite intuitive.
Command Level\part{a title without number} -1\chapter{a title without number} 0\section{a title without number} 1\subsection{a title without number} 2\subsubsection{a title without number} 3\paragraph{a title without number} 4\subparagraph{a title without number} 5
Numbering will be done automatically. LATEX has a command thatmakes it easy to manage references (for sections, tables, figures).To allow cross-referencing, you should assign a “key” to theelement you want to refer to and then use that key to refer to thatelement.
11
For example, at the end of the introduction:
\section{Literature Review} \label{Litreview}Then in the introduction you would write:“Section \ref{Litreview}summarizes the recent literature on European integration....”
12
Bibliography Bibtex allows you to store all your references in anexternal, flat-file database. A Bibtex database is stored as a .bibfile. The structure of the file is also quite simple. An example of aBibtex entry:
@article{greenwade93,author = ”George D. Greenwade”,title = ”The Comprehensive Tex Archive Network (CTAN)”,year = ”1993”,journal = ”TUGBoat”,volume = ”14”,number = ”3”,pages = ”342–351”}
13
If there are several authors:
@book{goossens93,author = ”Michel Goossens and Frank Mittlebachand Alexander Samarin”,title = ”The Latex Companion”,year = ”1993”,publisher = ”Addison-Wesley”,address = ”Reading, Massachusetts”}
14
Getting current Latex document to use your .bib file . At the endof your Latex file (that is, after the content, but before\end{document}), you need to place the following commands:
\bibliographystyle{plain}\bibliography {sample}
If you want your citation to have a different style, you should usethe Natbib package. In fact, it can supersede Latex’s own citationcommands, as Natbib allows the user to easily switch betweenHarvard or numeric.The first job is to add the following to your preamble in order toget Latex to use the Natbib package:\usepackage{natbib}
15
Also, you need to change the bibliography style file to be used.Let’s say we want to use AER style. We need to edit theappropriate line at the bottom of the file so that it reads:\bibliographystyle{aer}.Once done, it is basically a matter of altering the existing \citecommands to display the type of citation you want:
Citation command Natbib output\citet{goossens93} Goossens et al. (1993)\citep{goossens93} (Goossens et al., 1993)\citet*{goossens93} Goossens, Mittlebach, and Samarin (1993)\citep*{goossens93} (Goossens, Mittlebach, and Samarin, 1993)
16
FormattingText FormattingIf you use an editor such as WinEdt, it’s quiteeasy to find accents (in the “international” tool folder), mathssymbols, Greek letters, etc...Getting the right font size is also quite easy:
Command Output\tiny Size
\scriptsize Size\footnotesize Size\small Size\normalsize Size\large Size\Large Size\LARGE Size\huge Size\HUGE Size
17
Paragraph Formatting Here are the commands:
Alignment Environment CommandLeft justified flushleft \raggedrightRight justified flushright \raggedleftCenter center \centering
18
There are two ways to change the line spacing:I Add \usepackage{setspace} to the document preamble. This
then provides the following environments to use within yourdocument:
I doublespace - all lines are double spaced.I onehalfspace - line spacing set to one-and-half spacing.I singlespace - normal linespacing.
I Add \renewcommand{\baselinestretch}{number} to thedocument preamble.
Spacing 10pt 11pt 12ptone and one-half 1.25 1.21 1.24double 1.67 1.62 1.66
19
List Structure Lists often appear in documents, especiallyacademic, as their purpose is often to present information in aclear and concise fashion. List structures in Latex are simplyenvironments which essentially come in three flavors: itemize,enumerate and description.All lists follow the basic format:
\begin {list type}\item The first item\item The second item\item The third item, etc . . .\end {list type}
20
Footnotes The footnote facility is easy to use. The commandyou need is: \footnote{text}. Do not leave a space between thecommand the word where you wish the footnote marker to appear,otherwise Latex will process that space and will leave the outputnot looking as intended.
21
Page Layout
Geometrical Dimension of the Layout Here are someparameters controlling the page layout that I use for thisdocument. They should be put in the preamble of the document:
\setlength{\topmargin}{-0.8in} extra vertical space added at the top of the header\setlength{\textwidth}{6.6in} width of the text body\setlength{\textheight}{9.35in} height of the text body
22
Pages Styles There are two commands at your disposal forchanging the page style. \pagestyle{style} will apply the specifiedstyle to the current and all subsequent pages. \thispagestyle{style}will only affect the current page. The possible styles are:
empty Both header and footer are clearplain Header is clear, but the footer contains the page numberheadings Header displays page number and other information which the document class
deems important, e.g., section headersmyheadings Similar to above, however, is possible to control the information in the header
23
An issue to look out for is that the major sectioning commands(\part, \chapter or \maketitle) specify a \thispagestyle{plain}. So,if you wish to suppress all styles by inserting a \pagestyle{empty}at the beginning of your document, then the style command ateach section will override your initial rule, for those pages only. Toachieve your intended result, you will have to follow the offendingcommands with \thispagestyle{empty}.
24
Customizing with fancyhdr To begin, add the following lines toyour preamble:\usepackage{fancyhdr} \pagestyle{fancy}Both the header and footer are comprised of three elements eachaccording to its horizontal position (left, center or right). To settheir values, the following commands are available:\lhead[lh-even]lh-odd \foot[lf-even]lf-odd\chead[ch-even]ch-odd \cfoot[cf-even]cf-odd\rhead[rh-even]rh-odd \rfoot[rf-even]rf-oddHere is an example of what I used in my dissertation
\thispagestyle{plain} \chead{} \lfoot{} \cfoot{} \rfoot{} \rhead[\fancyplain{}{}]{\fancyplain{\thepage}{\thepage}}\lhead[]{\em Chapter \thechapter: Introduction}
25
Manual Page Formatting Latex offers the following:
\newline Breaks the line at the point of the command.\linebreak Breaks the line at the point of the command,
but also stretches the line to the margin.\newpage Ends the current page\pagebreak Breaks the current page at the point of the command.\nopagebreak Stops the page being broken at the point of the command.\clearpage Ends the current page and causes any floats encountered
in the input, but yet to appear, to be printed.
26
Tables
The tabular is an environment, designed for formatting your datainto nicely arranged tables. The following symbols are available todescribe the table columns:
l left-justified columnc centered columnr right-justifiedcolumn pwidth paragraph column with text vertically aligned at the topmwidth paragraph column with text vertically aligned in the middlebwidth paragraph column with text vertically aligned at the bottom| vertical line‖ double vertical lineOnce in the environment& column separator\\ start new row\hline horizontal line
27
OLS OLS OLS 2SLSERDF per capita 0.0005** 0.0002 0.0008** 0.0027**
(0.0002) (0.0002) (0.0003) (0.0012)Interaction Poor*ERDF 0.0005
(0.0005)Initial GVA per capita -0.032*** -0.032*** -0.211*** -0.0229in each period (0.004) (0.004) (0.024) (0.036)Lagged GVA per capita 0.01***
(0.003)Lagged Unemployment rate 0.009**
(0.004)Lagged Share of agriculture -0.021***in employment (0.003)regions dummies yes yes yes yesFirst Stage R-squared 0.671R-squared 0.426 0.431 0.768 0.4978Obs. 323 323 217 156
28
Here is the code to make this table
\begin{tabular}{ |lcccc|}\hline & OLS & OLS & OLS & 2SLS \\ERDF per capita & 0.0005** & 0.0002 & 0.0008** & 0.0027**\\& (0.0002) & (0.0002) & (0.0003) & (0.0012) \\Interaction Poor*ERDF & & 0.0005 & & \\& & (0.0005) & & \\Initial GVA per capita & -0.032*** & -0.032*** & -0.211*** & -0.0229 \\in each period & (0.004) & (0.004) & (0.024) & (0.036)\\Lagged GVA per capita & & & 0.01*** & \\& & & (0.003) & \\Lagged Unemployment rate & & & 0.009** &\\& & & (0.004) & \\Lagged Share of agriculture & & & -0.021*** &\\in employment & & & (0.003) &\\regions dummies & yes & yes & yes & yes\\First Stage R-squared & & & & 0.671\\R-squared & 0.426 & 0.431 & 0.768 & 0.4978 \\Obs. & 323 & 323 & 217 & 156 \\\hline\end{tabular}
Use the macro Excel2Latex in Excel to convert your Excel tableinto LATEX.
29
Importing Images and creating Figures
In many respects, importing images is easy, once you have theright format.The most common format is Encapsulated Postscript (EPS). Oncethe pictures are in EPS, you need to put \usepackage{graphicx} inthe preamble of your document. The syntax for using graphicx is:
\begin{figure}[H]\centerline{\includegraphics[scale=0.5]{latexKopka.eps}}\caption{A Guide to LATEX}\label{kopka}\end{figure}
This is what I wrote to add Figure 3. Need for to DVI the file andthen DVI to PDF.
30
One can also use PDF files for figures. Then, in the preamble, youneed to replace the command \usepackage{graphicx} by\usepackage[pdftex]{graphicx}.You can specify where in the text you want the figure to be.
Specifier Permissionh Place the float here, i.e.,
at the same point it occurs in the source text.t Position at the top of the page.b Position at the bottom of the page.p Put on a special page for floats only.! Override internal parameters Latex
uses for determining ‘good’ float positions.
31
Use \listoffigures to add a list of the figures in the beginning of thedocument.When a label is declared within a float environment (table orfigure), the \ref will return the respective fig/table number(although, it must occur after the caption). When declaredoutside, it will give the section number.
32
Mathematics
Latex needs to know beforehand that the subsequent text does infact contain mathematical elements. This is because Latextypesets maths notation differently than normal text.
Environment Latex shorthand Tex shorthand Text\begin{math}...\end{math} \(...\) $...$
33
To create a fraction, you must use the\frac{numerator}{denominator} command.Here is an example:
\frac{6xˆ{3}+36xˆ{2}}{(x+4)ˆ{2}} 6x3+36x2
(x+4)2
34
Powers and indices are mathematically equivalent to superscriptsand subscripts in normal text mode. The carat (ˆ) character isused to raise something, and the underscore ( ) is for lowering.How to use them is best shown by example:
xˆ{2n} x2n
n {i , j , t} ni ,j ,t
xˆ{2i} {3j} x2i3j
35
You might need to use another type of brackets with maths:
\frac{d}{dx}[\frac{f(x)}{g(x)}] ddx [ f (x)
g(x) ]
\bigg(\frac{Y}{L}\bigg)\frac{L}{pop}(
YL
)L
pop
\left(\frac{2x}{5y}\right)(
2x5y
)
36
If you have an equation that fits on one line:
d
dx[f (x)n] = n(f (x)n−1)f ′(x) (1)
this is the code you should use:
\begin {equation} \label{...}\frac{d}{dx}[f (x )̂{n}] = n(f (x )̂{n − 1})f ′(x)\end {equation}
37
If you have an equation that does not fit on one line, you shoulduse \multline instead of the \equation command:
lnERDFi ,t = βo + β1lnGVAi ,t−1 + β2 lnUnemploymenti ,t−1+
β3 lnAgriculturei ,t−1 + µt + εi ,t (2)
38
this is the code you should use:
\begin {multline} \label{ERDF}\ln ERDF {i,t} =\beta {0} + \beta {1}\ln GVA {i,t-1} + \beta {2}\ln Unemployment {i,t-1}+ \\\beta {3}\ln Agriculture {i,t-1} + \mu {t}+ \varepsilon {i,t}\end {multline}
39
Some References“A Guide to LATEX: Document Preparation for Beginners andAdvanced Users”, Helmut Kopka. This book is exactly what it says- geared for both beginners and advanced users; it is especiallyhelpful for bibtex. ISBN 0201398257.
Figure: A Guide to LATEX
40
“The Latex Companion” by Michel Goossens, Frank Mittelbachand Alexander Samarin. This one is also very good, but I foundthat it made more sense after I had been using Latex for a while.ISBN 0201541998.
Figure: Latex Companion Book
41
I “The Not So Short Introduction to LATEX2: Or LATEX2 in 90minutes” by Tobias Oetiker Hubert Partl, Irene Hyna andElisabeth Schlegl: this PDF file is available on my website.It’s a great reference, easy to read.
I http://en.wikibooks.org/wiki/LaTeX: this website gives youvery basic stuff, but it’s quite useful for true beginners
I http://www.ctan.org/: if you are looking for a package, acommand, a bibliography style, this website provides youaccess to the Comprehensive TEX Archive Network.