Professional Documents
Culture Documents
Te XIntro
Te XIntro
1
A Brief Introduction to LATEX February 2, 2019
2 Preliminaries
In this document, the text you type into your .tex file is shown on the left, and the formatted LATEX output is shown
on the right.
LaTeX ignores multiple spaces. One LaTeX ignores multiple spaces. One space is as good as
space is as good as two. LaTeX two. LaTeX also ignores single carriage returns, as you
also ignores single carriage returns, can see. To get a new paragraph, you need to insert a
as blank line.
you Like this...
can see. To get a new paragraph, you
need to insert a blank line.
Like this...
3 Math
One of the main reasons for using LaTeX is that it produces very high-quality mathematical output. It is significantly
better than that produced by Word’s Equation Editor, and much much better than that typically produced by a PH425
student. Here I’ll just touch on a few common math techniques. The template file shows a few more things.
To type symbols and equations inline, you need to bracket them with dollar signs $. . . $. Thus we have
Note that all symbols are math, and so should be bracketed with $. . . $.
...where $x$ is the particle’s position, ...where x is the particle’s position, v its velocity, and θ
$v$ its velocity, and $\theta$ its angle its angle of launch.
of launch.
Often you want to type display equations, that is, equations that are shown on their own line. A numbered display
equation is formatted using the equation environment. Note that no $...$ are needed.
\begin{equation}
E = mc^2 E = mc2 (1)
\label{eq:Einstein}
\end{equation}
Presumably, if you number an equation you’ll want to refer to it in the text. This is done using the \label
command. The text inside the brackets (eq:Einstein) is the label. It can be any text you like without spaces. I use
the eq: part to remind myself that this is a label for an equation (figures and tables are labeled similarly), but you
don’t need to do things this way. To refer to the equation in the text, you type Equation~\ref{eq:Einstein} at
the beginning of a sentence, or Eq.~\ref{eq:Einstein} within a sentence. This will show up in the output file as
“Equation 1” or “Eq. 1”, respectively. The hyphen ~ is a non-breaking space, so that the word “Equation” and the
number don’t appear on separate lines. A nice feature of this method is that all your equations and their references
are automatically numbered in sequence, and updated correctly if you insert a new equation in between two existing
ones.
2
A Brief Introduction to LATEX February 2, 2019
There are a very large number of LaTeX math symbols available. They are typed in your LaTeX file as a
backslash (\) command, always in math mode ($. . . $). Many of them have pretty obvious command names. Thus,
for instance, the Greek letter alpha is typed as \alpha. See the file “LaTeX Math Symbols” on Canvas for a
comprehensive list. Some of the common ones you might need in this course are
Note that there are special symbols for common function names such as \sin that result in the characters “sin”
being typeset in non-italic letters, which is how function names should be typeset. Compare
There are also a number of LaTeX structures you’ll commonly be using. These include:
• Superscripts and subscripts:
x^2 x2
x^{2 y} x2y
x_0 x0
x^2_0 x02
Superscripts and subscripts that represent symbols are typeset in math mode, but superscripts and subscripts that
are words (or abbreviations of words, such as “e” for “electron”) are in Roman font, using the \mathrm{} command:
The velocity $v_x$ The velocity vx
The applied field $B_\mathrm{magnet}$ The applied field Bmagnet [not Bmagnet ]
The electron neutrino $\nu_\mathrm{e}$ The electron neutrino νe [not νe ]
• Fractions:
y2
x = \frac{y^2}{z} x=
z
3
A Brief Introduction to LATEX February 2, 2019
• Square roots:
p
r = \sqrt{x^2 + y^2} r= x2 + y2
x â ū
\overline{x} \hat{a} \bar{u}
ẋ ẍ ~v
\dot{x} \ddot{x} \vec{v}
To place tall math such as fractions in parentheses or brackets, enclose the math in \left( and \right); the
brackets can be {}, [], (), ||, etc:
q = \frac{1}{2}
x3
\left(\frac{x^3}{b^2}\right) 1 sin(x)
q=
\left[\frac{\sin(x)}{\cos(x)}\right] 2 b2 cos(x)
4 Figures
Figures can be inserted using the \includegraphics command, inside a figure environment:
-9 19
16x10 2.0x10
14 RH
←
10
2 \centering 8 1.0
3 \includegraphics[scale=0.7]{myFigure.pdf} 6
4 \caption{This is the caption. It describes 4 n 0.5
→
5 what the figure is about.} 2
6 \label{fig:myFigure} 0 0.0
-8 -6 -4 -2 0 2 4 6 8
7 \end{figure} B (kG)
In line 1, the [h] tries to put the figure “here”, as close as possible to where the \includegraphics command
is. Other choices are [t] for the top of the page and [b] for the bottom of the page. Line 2 centers the figure on the
page. Line 3 actually places the graphic. Between the square brackets you can put a parameter to scale the figure, or
to set its absolute width ([width = 3.0 in]). If you omit the square brackets entirely, the figure will be placed at
its natural width.
The filename of your figure goes between the braces {...}. In both TeXShop and MiKTeX you can use .pdf,
.jpg, and .png files. Of course, .pdf files are preferred because they are resolution-independent, but if you have to
4
A Brief Introduction to LATEX February 2, 2019
use a bitmap format, .png is better than .jpg because the latter is a compressed format. You can put the graphics files
in the same folder as the .tex file. Or, you can put them in a folder (say, “myFigures”) in the folder that contains the
.tex file. Then (see Template.tex) you’ll need to include \graphicspath{{myFigures/}} at the top of your file.
Every figure needs a caption in braces, as shown in lines 4–5. Finally, because every figure needs to be referenced
in the text, you need some way to refer to it. To do so, use the \label command, as shown in line 6. The label in
the braces can be any text (without spaces) you like. I often use fig: to remind myself that this is a figure label.
You can then refer to the figure elsewhere in the text as Fig.~\ref{fig:myFigure}, which appears in the text as
“Fig. 1”.
Always refer to figures by their numbers, as shown above. Never refer to them in the form, “in the figure below
we see that. . . ” or something similar. Also, it’s common for a figure reference that starts a sentence to have the word
“Figure” written out in full, while a reference in the middle of a sentence uses the abbreviation “Fig.” Also note that
in each case the Figure or Fig. is capitalized.
Graphing and figure miscellany:
• Don’t insert gigantic figures into your report. Scale them appropriately so that they don’t overwhelm the page.
• Don’t use too large a font in figures; 8 or 9 point is plenty large. I often create my figures at about twice the
scale I want them to appear in my document, and use a 16 point or so font which looks about right when scaled
down by 2×.
• In Igor’s Modify Axis dialog (double click on an axis), under the Axis tab, turn off the Standoff checkbox. If
it’s checked, it adds an annoying little extra length to the axis.
5 Tables
Tables in LaTeX are somewhat tricky. There’s an example table in Template.tex that you can look at:
1 \begin{table}[h]
2 \centering
3 \begin{tabular}{ccccl}
4 \hline
5 ~$\rho $~ & $~~~~T_c~~~~$ &~~$\lambda(T/T_c = 0.9)$~~ & $\kappa$ &Source\\
6 ($\mu\Omega\cdot\mathrm{cm})$ & (K) & (nm) & & \\
7 \hline
8 10.8 & 1.64 & 510 & 2.6 & Ekin\\
9 20.8 & 1.81 & 675 & 5.0 & Ekin (interpolated)\\
10 35.0 & 2.0 & 830 & 8.4 & Daldini {\it et al.}\\
11 \hline
12 \end{tabular}
13 \caption{Properties of several granular aluminum films. $\kappa$ is the
14 Ginzburg-Landau parameter.}
15 \label{table:superconductors}
16 \end{table}
5
A Brief Introduction to LATEX February 2, 2019
which gives
Lines 1 and 2 are similar to their figure counterparts. Line 3 starts the table. In the brackets you need to
put one letter for each column of your table, either c for a centered column, l for a left-justified column, or r
for a right-justified column. Whenever you want a horizontal line in your column, use \hline. Each row of
the table contains the table data separated by ampersand (&) characters; the end of each row should have two
backslashes (\\). The caption and reference are handled similarly to a figure; refer to the table above using
Table~\ref{table:superconductors}.
In Table 1, I used a number of non-breaking spaces (~) in the header row to space out the columns a little. There
is a way to add space by using actual numerical spacing, but it’s so complicated as to not really be worth it.
is perhaps the. . .
Newton’s second law is: Wrong. You wouldn’t write, “Newton’s second
law is: force equals. . . ”
F = ma.
Two mistakes. First, the sentence after the equa-
tion shouldn’t be indented; it’s just a continuation
Newton’s second law is of the existing paragraph. To prevent this, don’t
leave a blank line after the equation. Second, the
F = ma, word “Which” should not be capitalized, as this
sentence fragment is again just a continuation of
Which is perhaps the most. . . an existing sentence.
7 References
It’s likely that your report will have some references. Here’s how to put them in. In the text, where you eventually
want the superscripted citation to appear (. . . as shown in 1978 by Smith23 ), you write ...by Smith\cite{Smith1978}.
The Smith1978 is your cite key, and it can be any text you like. The author’s last name followed by the year is a
good way to keep track of things. You can have more than one reference at a time:
6
A Brief Introduction to LATEX February 2, 2019