Top Banner
Biostatistics Student Seminar An Introduction To L A T E X Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School of Public Health University of Toronto
29

Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Mar 06, 2018

Download

Documents

vanhuong
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Biostatistics Student SeminarAn Introduction To LATEX

Josh MurrayOsvaldo Espin-Garcia (edition)

Dalla Lana School of Public HealthUniversity of Toronto

Page 2: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Introduction

There are four stages to creating a document:1 Text is entered and stored in the computer for corrections,

extensions, deletions, etc...2 The input text is formatted into lines of equal length and

pages of a certain size3 The output text is displayed on the computer screen4 The final output is sent to a printer

TEX, is a powerful computer programming language thatfocuses on step 2 above. LATEX, is an extension that allows theuser to create publication quality materials with TEXcommands.

Page 3: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

History

Computer scientist Donald Knuth was frustrated with theerrors that occurred when he sent his journal articles andbooks to be published.In 1978 wrote the typesetting program TEX so that anyonecould create publication quality documents.In 1985 mathematician Leslie Lamport created anextension of TEX, called LATEX, that focuses on documentstructure as opposed to the minute detail of TEX.

Page 4: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

How do you use LATEX?

There are three steps to creating a publication qualitydocument with LATEX:

1 Enter text with LATEX markup into a text editor and save itas a .tex file. (e.g. TeXworks, Tinn-R, TexnicCenter)

2 Send your .tex file to a program that can process LATEXinput. (MikTeX). This will create a file of your choice, PDF,DVI, or Postscript.

3 Open the file you created in a viewer (Adobe).

Page 5: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

A Basic Document

Every LATEXdocument must contain the following threecomponents.

\documentclass{article} %preamble\begin{document}%bodyHello World!%body\end{document}

The preamble. It tells LATEX what kind of document to process.In the example above I chose article, but I could have chosensomething else (e.g book, report, letter, or beamer). This iswhere you put all of the global commands that will appear inyour document. The document’s text is placed between thesecond and third item.

Page 6: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Sections

LATEX is very useful for breaking up your document intosections. Giving your document structure by adding logicalsections makes it easier to read. A well structured documentusually contains the following components:

A title pageA table of contentsAn AbstractSection headingsSubsection headingsBibliography

Page 7: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Sections (cont’d)

A section can be declared in one of two ways:

\section{section name}

\section*{section name}

Once you declare a section it is best to give it a label. This isdone by adding the command \label{label name}. Onceyou have done this, you can reference your section by addingthe command \ref{label name}.

Page 8: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Math Mode

There are two main modes for processing commands in Latex.

1 Paragraph mode, which is the normal processing mode.2 Math mode. Latex enters this mode when certain

commands are encountered, telling Latex that what followsis a formula. When Latex is in math mode, spaces andblanks are ignored.

Page 9: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Math Mode (cont’d)

There are two ways to enter math mode. The first is within aparagraph by enclosing your math symbol or formula betweentwo $’s. An example would be:

The short hand symbol forsummation is the

capital Greek lettersigma, $\Sigma$.

The short hand symbolfor summation is thecapital Greek lettersigma, Σ.

Page 10: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Math Mode (cont’d)

The second method way to enter math math is to place yourformula between two $$’s. This will place your formula in aparagraph of its own:

$$f(x)=\frac{1} { \sqrt{2\

pi\sigma^{2} } } e^{-\frac{(x-\mu)^{2}}{2\sigma^{2}}}

$$

f (x) =1√

2πσ2e−

(x−µ)2

2σ2

Page 11: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Constants and Variables

In Math Mode constants are typeset in Roman and variablesare in italics. Spaces are ignored.

z = 2a + 3y

y ′′ = c{f [y ′, y(x)] + g(x)}

M(s) < M(t) < |M| = m

Page 12: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Exponents and Indices

\pi^{2}→ π2

x^{5y + 3}→ x5y+3

x_i→ xi

a_{12}→ a12

x^n_i→ xni

A_{i,j,k}^{n!2}→ ?

? → Ax2i

j2nm.n

Page 13: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Fractions

Fractions can be displayed as

x/y→ x/y\frac{x}{y}→ x

y

Both, \frac{x/y - z/y}{u/v -s/t}→ ?

? →a

x−y +b

x+y

1+ a−ba+b

Page 14: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Roots

Roots can be displayed as

\sqrt{8}→√

8\sqrt[3]{8}=2→ 3

√8 = 2

\sqrt{x^2 + y^2 +2xy}→√

x2 + y2 + 2xy\sqrt[3]{-q + \sqrt{q^2 +p^3}}→ ?

? → SE(∆̂) =√

1n11

+ 1n12

+ 1n21

+ 1n22

Page 15: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Sums and Integrals

Summation and integration formulas are made with thecommands \sum and \int:∑n

i=1∫ ban∑

x=1ax

2n∑

i=1ai

b∫a

fi(x)gi(x) dx4

More complex equations can be made by following the simplerules. \int\frac{\sqrt{(ax+b)^3}}{x} produces:∫ √

(ax + b)3

x

Page 16: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Arrays

Arrays are used to create matrices, determinants, systems ofequations and so on.

An array begins with the command\begin{array}{justification} and ends with\end{array}. The justification consists of entering l for left, cfor center, or r for right. You need to include a justification rulefor every column that you include.

The entries in each array are separated by an & and each lineends with \\.

Page 17: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Examples of arrays

$$\ l e f t ( \ begin { a r ray } { r c l }1 & 0 & 0 \ \0 & 1 & 0 \ \0& 0 & 1 \ \\ end { a r ray } \ r ight )$$

1 0 00 1 00 0 1

$$\ l e f t ( \ begin { a r ray } { c }\ l e f t | \ begin { a r ray } { c c }x _{11} & x _{12} \ \x _{21} & x _{22} \ end { a r ray } \

r ight | \ \x \ \ y\ end { a r ray } \ r ight )$$

∣∣∣∣ x11 x12

x21 x22

∣∣∣∣xy

Page 18: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

What code produces the following?

F (x , y) = 0 and

∣∣∣∣∣∣F′′xx F

′′xy F

′x

F′′yx F

′′yy F

′y

F′x F

′y 0

∣∣∣∣∣∣ = 0

Page 19: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Multiple Line Equations

Equation deployed over several lines of code. They have thesame form as an array.

\begin{eqnarray}(x+y)(x-y) & = & x^2 - xy - y^2 \\

& = & x^2 - y^2 \\(x+y)^2 & = & x^2 + 2xy + y^2

\end{eqnarray}

xnu1 + · · ·+ xn+t−1ut = xnu1 + (axn + c)u2 + · · ·

+(

at−1xn + c(at−2 + · · ·+ 1))

ut

= (u1 + au2 + · · ·+ at−1ut )xn + h(u1, . . . ,ut )

Page 20: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Tables

Tables are created in Latex using the tabular environment. Thebasic syntax for a table in Latex is:

\begin{tabular}{justification}r1c1 & r1c2 & ... \\... \\

rnc1 & rnc2 & ...\end{tabular}

The justification is either l for left, c for center, or r for right. Eachcolumn entry is separated by an & and each row ends with \.

Page 21: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Example of a table

The following code:

\ begin { t ab l e }\ begin { t a b u l a r } { c | | c | c | | c }\ hl ine \ hl ineB i r t h & \ multicolumn { 2 } { c | | } { Smoking Status } & \ \ \

cl ine {2−3} Weight & No & Yes & Tota l \ \\ hl ineNormal & $n_{11}$ & $n_{12}$ & $n _ { 1 . } $ \ \\ hl ineLow & $n_{21}$ & $n_{22}$ & $n _ { 2 . } $ \ \\ hl ine \ hl ineTo ta l & $n _ { . 1 } $ & $n _ { . 2 } $ & $n _ { . . } $ \ \\ hl ine \ hl ine\ end { t a b u l a r } \ caption { $2 \ times2$ cont ingency tab l e

}\ end { t ab l e }

Page 22: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Example of a table (cont’d)

Produces the table:

Birth Smoking StatusWeight No Yes TotalNormal n11 n12 n1.

Low n21 n22 n2.

Total n.1 n.2 n..

Table: 2× 2 contingency table

Page 23: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Table: Summary of Categorical variables

Distribution of GenderGender n (%)Females 296 (58.04%)Males 214 (41.96%)

Distribution of AgeSpread n (%)Age grp 1 1 (0.21%)Age grp 2 92 (19.53%)Age grp 3 159 (33.76%)Age grp 4 219 (46.50%)

Page 24: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Special Characters

List of Special Characters:

$ = \$& = \&% = \%# = \#_ =\_{ = \{} = \}

Page 25: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Lists

There are three types of lists available in LATEX.

\begin{itemize} list text \end{itemize}

\begin{enumerate} list text \end{enumerate}

\begin{description} list text \end{description}

To add a new bullet/number/description you call the command\item.

Page 26: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Example itemize

The individual entries are indicated with a black dot, aso-called bullet, as the labelThe text in the entries may be of any length. The labelappears at the beginning of the first line of text.Successive entries are separated from one another byadditional vertical spaces.

Page 27: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Example of enumerate

1 The labels consists of sequential numbers2 the numbering starts at 1 with every call to the enumerate

environment

Page 28: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Sample description

purpose This environment is appropriate when a number ofwords or expressions are to be defined

example A keyword is used as the label and the entrycontains a clarification or explanation

other uses It may also be used as an author list in abibliography

Page 29: Biostatistics Student Seminar An Introduction To LaTeX · PDF fileBiostatistics Student Seminar An Introduction To LATEX Josh Murray Osvaldo Espin-Garcia (edition) Dalla Lana School

Online resources

1 http://en.wikibooks.org/wiki/LaTeX

2 http://latex.wikia.com/wiki/Main_Page

3 http://www.ctan.org/tex-archive/info/lshort/english/

4 http://tex.stackexchange.com/