Love Latex Advanced Ps
Love Latex Advanced Ps
Tim Love
September 4, 1994
This document follows on from the Word processing using LATEX handout.
It describes the features of LATEX 2" that people at CUED are most likely
to use. Further information is in the online handouts and in the books
available for loan from the operators in the DPO. The Local LATEX handout
is a companion to this one. It describes some features especially suited
to writing theses (bibliography and index compilation, for example) and
includes a list of available packages.
Comments and bug reports to Tim Love ([email protected]).
Contents
1 LATEX Concepts 2
1.1 Environments and commands : : : : : : : : : : : : : : : : : : : : : 2
1.2 Classes and packages : : : : : : : : : : : : : : : : : : : : : : : : : : 3
1.3 Errors : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 3
1.4 Files created : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 4
1.5 How to use LATEX : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 4
Copyright c 1994 by T.P. Love. This document may be copied freely for the pur-
poses of education and non-commercial research. Cambridge University Engineer-
ing Department, Cambridge CB2 1PZ, England.
1
1 LATEX CONCEPTS
4 Environments 13
4.1 Alignments : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 13
4.2 Listing Items : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 13
4.3 Tabular : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 15
4.4 Array : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 15
4.5 Pictures : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 16
4.6 Maths : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 16
4.7 Figures : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 17
4.8 Tabbing : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 17
4.9 Verbatim : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 18
4.10 Quote, abstract : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 18
4.11 Letter : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 18
5 Customising 18
5.1 Macros : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 18
5.2 New Commands : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 19
5.3 Packages : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 19
5.4 An Example : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 19
6 More Information 20
1 LATEX Concepts
1.1 Environments and commands
LATEX is a macro-package for TEX which has many preset environments where much
of the setting up that TEX users have to do explicitly is done for you. An environ-
ment has the form
\begin{environment name}
.
\end{environment name}
LATEX also has commands which affect the formatting of the document. Their
arguments are given in braces. For example,
2
1 LATEX CONCEPTS 1.2 Classes and packages
\documentclass[12pt]{article}
which determines the font size and document class – the type of document you’re
writing. Each class has an associated *.cls file in the directory /export/latex2e/inputs/
which is read in at start-up time. Other options accepted by article include 10pt,
11pt and twocolumn.
Then you’ll probably need to load in extra macros. This is done using the \usepackage
command. Each package has an associated *.sty file in /export/latex2e/inputs/.
The packages inherit the options from the \documentclass line and can be given
others of their own. E.g.
\usepackage[dvips]{graphics}
\usepackage[dvips]{color}
tells LATEX that you want to use the extra graphics and color macros, and that
you are going to use dvips to convert the resulting file to postscript. You can shorten
this to
\usepackage[dvips]{graphics,color}
or even
\documentclass[dvips]{article}
\usepackage{graphics,color}
1.3 Errors
Errors can be reported either from the LATEX phase (in which case it is reported as
such) or the lower level TEX phase. Don’t be too put off by the half-digested text dis-
played. A line number is reported which usually helps to detect the error. Typing
‘h’ sometimes produces helpful diagnostics. The most common errors reported
are
a command misspelt
a mismatched brace
improper use of special characters
3
1 LATEX CONCEPTS 1.4 Files created
means that lines 285 to 288 are producing a text line about 15 pts (about 5cm)
too wide. \OT1/ppl/m/n/10 is the specification of the font used. When TEX
does right and left alignment, it works out how much space it needs to leave
between words and where to hypenate words if necessary. But the amount of
space it’s prepared to leave has to fall within a certain range and it will only
split words in certain places (shown in the error message by a hyphen). If
these restrictions mean that LATEX can’t produce a satisfactory line, it will pro-
duce as much of the line as it can. A re-phrasing of the offending sentence
will usually solve the problem. Another thing you might try is to control the
way a troublesome word is hyphenated using something like
\hypenation{furthermore fur-ther-more}
at the top of your file. If all else fails, use {\sloppy...} to enclose the of-
fending text.
LTEX issues a *.
A
This means LATEX needs more input. It probably means you’ve missed out an
\end{document}, but if not you may be able to get LATEX to continue pro-
cessing as best it can by typing <Return>.
! Argument of \label has an extra }
If you’re sure you haven’t left out a left brace, then maybe you need to protect
the inmost (fragile) command. For example, \label is fragile which causes a
problem in \caption{Picture\label{margin}}, so the safer construc-
tion \caption{Picture\protect\label{margin}} has to be used.
4
2 DOCUMENT ORGANISATION AND STRUCTURING 1.5 How to use L
AT X
E
latex doc
latex doc
dvips -t a4 doc.dvi -o doc.ps
ghostview doc.ps
lp -dljmr1 -opostscript doc.ps
Using xlatex – xlatex has buttons to process, preview and print your document
(or selected pages of it), and convert it to postscript. Just type latex filename.
Writing a LATEX document is rather like writing a program. This makes using
LATEX more difficult in some respects than using a word processor, but there are ad-
vantages too. For instance creating a table of contents is trivial. Beginners often use
unnecessary ‘\\’ sequences and write ‘{\large \textbf{2.1 Method}}\\’ when
‘\subsection{Method}’would be much better. Users who think they know more
about typesetting than LATEX (those who, for example, like underlining) will waste
a lot of time too.
Avoid repeating constructions. Instead, write your own macros and commands,
and familiarise yourself with the packages described in the Local LATEX guide.
\setcounter{page}{0}
\addtocounter{chapter}{2}
Length Parameters :- LTEX accepts the following units of length: in, cm,
A
mm, pt (there are 72.27 pts to an inch), em (width of an M), ex (height of an x).
These units can be used to set the values of length variables using \setlength.
For example,
\setlength{\parindent}{0in}
sets to zero the amount by which the first line of a paragraph is indented.
Other useful variables are:-
parskip:- determines the gap between paragraphs.
5
2 DOCUMENT ORGANISATION AND STRUCTURING
2.2 Document and page organisation
baselineskip:- determines the usual distance from the bottom of one line
to the bottom of the next. You can adjust this to produce double spa-
cing, but a better way, which takes a stretch factor as argument is to use
baselinestretch. For instance after \begin{document} you can
do
\renewcommand{\baselinestretch}{1.2}
but note: it won’t take effect until a font change so you might need to do
something like \small \normalsize.
\documentclass[dvips,12pt]{book}
\usepackage{a4,color,graphics,palatino,fancyheadings}
\begin{document}
\pagestyle{empty}
\tableofcontents
\listoffigures
\pagestyle{fancy}
\include{chapter1}
\include{chapter2}
\include{fig2}
\include{chapter3}
\include{chapter4}
\end{document}
on which you can run latex just as if the master file contained all the text
of chapter1.tex etc. The advantage of this is that once you have a chapter
correct, you can comment out the corresponding ‘include’ line and avoid un-
necessary processing. Remember to take out the \begin{document} and
\end{document} lines from the component files.
Page Size :- The default a4 style has wide margins. The a4 local version
uses more of the page. You can choose the margin sizes yourself by changing
the following dimensions before the \begin{document} line.
\setlength{\topmargin}{-0.4in}
\setlength{\topskip}{0.3in} % between header and text
\setlength{\textheight}{9.5in} % height of main text
\setlength{\textwidth}{6in}
\setlength{\oddsidemargin}{0.75in}
\setlength{\evensidemargin}{0.75in}
To see the current values of these dimensions, use the layout package, which
defines a \layout command.
6
2 DOCUMENT ORGANISATION AND STRUCTURING
2.3 Pagebreaks, footnotes, etc
Title Pages :- The title page of this document was created by the following
LATEX commands.
\title{Advanced \LaTeX}
\author{Tim Love}
\date{\today}
\maketitle
plain :- the page numbers are put at the bottom of the page. The top of the
page is empty. This is the default mode.
empty :- this suppresses page numbering altogether.
headings :- this puts the page numbers at the top and adds a header whose
contents depend on the document style.
\setcounter{tocdepth}{2}
\setcounter{secnumdepth}{3}
will cause section 1.4.3 to be numbered, but it won’t appear in the contents.
Space :-
You can create vertical space \vspace{.5cm} between lines
or horizontal space \hspace{1.5cm} between words.
The arguments to these commands can be negative.
7
3 COLOR AND FONTS
You can create vertical space between lines or horizontal space between
Do them like this1 The footnotes are numbered by default. If you want to use
symbols (stars, daggers etc) then you need to redefine how the footnote
counter is displayed.
\def\thefootnote{\fnsymbol{footnote}}
Margin notes :-
These are easy too. Do them like this\marginpar{margin note}
\usepackage[dvips]{color}
8
3 COLOR AND FONTS 3.2 Special characters
produces This is in red and this box is gold . Text color can be set using RGB values
(like so), or shades of grey.
+
p p
i \sqrt{i} 5 x iy \sqrt[5]{x+iy} ::: \ldots
.. ..
\cdots . \vdots . \ddots
\alpha \beta \gamma
\delta ! \omega ; \Gamma
\Theta \Omega \pm
\mp \times \div
\ast ? \star \circ
T \bullet \cdot S
\ \cap
\bigcap U \cup \bigcup
] \uplus F \biguplus u \sqcap
W
t \sqcup
\bigvee ^
\bigsqcup
\wedge
V
_ \vee
\bigwedge
n \setminus o \wr \diamond
4 \bigtriangleup 5 \bigtriangledown / \triangleleft
L
. \triangleright \oplus
N \bigoplus \ominus \otimes
J \bigotimes
\bigodot
\oslash
\bigcirc
q
\odot
\amalg
\leq \prec \preceq
\ll \subset \subseteq
2 \in ` \vdash
\geq ! \succ " \succeq
# \gg $ \supset % \supseteq
w \sqsupseteq 3 \ni a \dashv
' \equiv ( \sim ' \simeq
* \asymp + \approx =
( \cong
=
6 \neq =
:
\doteq / \propto
=
j \models ? \perp j \mid
k \parallel ./ \bowtie ^ \smile
_ \frown / \leftarrow ( \Leftarrow
! \rightarrow ) \Rightarrow $ \leftrightarrow
, \Leftrightarrow 7! \mapsto /- \hookleftarrow
9
3 COLOR AND FONTS 3.3 Font Sizes
( \leftharpoonup ) \leftharpoondown *
) \rightleftharpoons
/; \longleftarrow ( = \Longleftarrow ;! \longrightarrow
= ) \Longrightarrow /! \longleftrightarrow () \Longleftrightarrow
7;! \longmapsto ,! \hookrightarrow * \rightharpoonup
+ \rightharpoondown " \uparrow * \Uparrow
# \downarrow + \Downarrow l \updownarrow
% \nearrow & \searrow . \swarrow
- \nwarrow @ \aleph
h \hbar
{ \imath | \jmath ` \ell
} \wp < \Re = \Im
0 \prime \empty r \nabla
p
\surd > \top ? \bot
k \| 6
\angle 8 \forall
9 \exists : \neg \flat
\ \natural ] \sharp n \backslash
@ \partial 1 \infty 4 \triangle
| \clubsuit P
} \diamondsuit Q
~ \heartsuit
`
K \spadesuit
\coprod
R \sum
\int
H \prod
\oint
One locally produced font with only one character is called crest.
A
\font\crest=crest
‘‘This is the {\crest A} CUED crest’’
{\tiny ... }
If Huge isn’t big enough for you, you can scale a postscript font up using the
commands designed for graphics. \resizebox{!}{5cm}{BIG} produces
10
3 COLOR AND FONTS 3.4 Font Types
3.4
BIGFont Types
Independent of size, these font types are at your disposal :- \textrm (roman), textit(italic),
\textsc ( SMALL CAPS ), \emph (emphasis, but note that if you use emph within em-
phasized text, you will get roman text), \textsl (slanting), \texttt (teletype),
\textbf (boldface), \textsf (sans serif). As long as there’s no conflict, these
commands can be combined so that, for instance, this is bold sans serif can be
produced by \textsf{\textbf{this is bold sans serif}}.
\usepackage{palatino}
to your file. The pifont package has special commands for using the Zapf Ding-
bats font. \dingfill{40} completes the line with the specified symbol ✈ ✈
and \dingline{36} draws a whole line of symbols.
✄ ✄ ✄ ✄ ✄ ✄ ✄ ✄ ✄ ✄ ✄ ✄ ✄ ✄ ✄ ✄ ✄ ✄ ✄
It’s a good idea to use a font that’s installed in the printer you intend to use. See
the table on page 11 for information about the teaching system’s ljmr1 printer.
encoding This specifies the order that characters appear in the font. The most com-
mon values for the font encoding is OT1.
family The name for a collection of fonts, usually grouped under a common name
by the font foundry. For example, ‘Adobe Times’ and Knuth’s ‘Computer Mod-
ern Roman’ are font families. There are far too many font families to list them
all, but some common ones are:
11
3 COLOR AND FONTS 3.7 Selection commands
series How heavy or expanded a font is. For example, ‘medium weight’, ‘narrow’
and ‘bold extended’ are all series. The most common values for the font series
are:
m Medium
b Bold
bx Bold extended
sb Semi-bold
c Condensed
shape The form of the letters within a font family. For example, ‘italic’, ‘oblique’
and ‘upright’ are all font shapes. The most common values for the font shape
are:
12
4 ENVIRONMENTS
\usefont{encoding}{family}{series}{shape}
is short hand for the equivalent \font: : : commands followed by a call to \selectfont.
4 Environments
Some examples of how to use environments are given here.
4.1 Alignments
In these environments \\ starts a new line.
13
4 ENVIRONMENTS 4.2 Listing Items
\begin{flushleft}
Some people like to stay firmly\\ on the left whereas others
\end{flushleft}
\begin{flushright}
feel much more at home\\ on the right.\\
\end{flushright}
\begin{center}
but most of us prefer to stay\\ dead in the center.
\end{center}
\begin{itemize}
\item just by a bullet, using \texttt{itemize}
\begin{enumerate}
\item one
\item two
\item three
\end{enumerate}
\begin{description}
\item[itemize] bullets
\item[enumerate] automatic numbering
\item[description] labelling
\end{description}
\end{itemize}
just by a bullet
numbered
1. one
2. two
3. three
14
4 ENVIRONMENTS 4.3 Tabular
or with a label
itemize bullets
enumerate automatic numbering
description labelling
The pifont package includes a variant of the itemize command that will re-
place the usual ’bullet’ by a Zapf Dingbat symbol of your choice
\begin{dinglist}{43}
\item First
\item Second
\end{dinglist}
☞ First
☞ Second
and a variant of the enumerate command that given an initial Zapf Dingbat
symbol will increment the symbol for each item.
\begin{dingautolist}{172}
\item First
\item Second
\end{dingautolist}
① First
② Second
4.3 Tabular
Tabular output is supported. When you create the environment you specify how
many columns to have and how the contents are to be aligned (use l, c or r to
represent each column with either left, center or right alignment) and where you
want vertical lines (use |). The contents of the columns are separated by a ‘&’ and
rows by \\. To draw a full horizontal line, use \hline otherwise draw a line across
selected columns using \cline. The \multicolumn command allows items to
span columns. It takes as its first argument the number of columns to span. The
following, rather complicated example shows how to use most of these facilities.
\begin{tabular}{||l|lr||} \hline
\textbf{Veg} & \multicolumn{2}{|c||}{\textbf{Detail}}\\\hline
carrots & per pound & \pounds 0.75 \\ \cline{2-3}
& each & 20p \\ \hline
mushrooms & dozen & 86p \\ \cline{1-1} \cline{3-3}
toadstools & pick your own & free \\ \hline
\end{tabular}
Veg Detail
carrots per pound £0.75
each 20p
mushrooms dozen 86p
toadstools pick your own free
15
4 ENVIRONMENTS 4.4 Array
Tables won’t continue on the next page if they’re too long. The longtable
commands are needed to do this. Type handout latex2e_longtable for de-
tails and examples.
If the text in a column is too wide for the page, LATEX won’t automatically text-
wrap. Using p{5cm} instead of c, l or r in the tabular line will wrap-around the
text in a 5 cm wide column.
There are various packages to assist with table creation. The array package
adds some helpful features, including the ability to add formatting commands that
control a whole column at a time, like so
\begin{tabular}{>{\ttfamily}l>{\scshape}c>{\Large}r}
Text & More Text & Large Text\\
Left & Centred & Right
\end{tabular}
4.4 Array
The array environment is similar to the tabular but must be within a math en-
vironment. This
\begin{math}
\left(
\begin{array}{clrr}
a+b+c & uv & x-y & 27 \\
x+y & w & +z & 363
\end{array}
\right)
\end{math}
a+b+c uv x ;y 27
x+y +z 363
produces
w
4.5 Pictures
LATEX has some graphics capabilities. It’s much better to use xfig. See the appro-
priate document (LATEX Maths and Graphics) for more details.
\newcounter{cms}
\setlength{\unitlength}{1mm}
\begin{picture}(50,39)
\put(0,7){\makebox(0,0)[bl]{cm}}
\multiput(10,7)(10,0){5}{\addtocounter
{cms}{1}\makebox(0,0)[b]{\arabic{cms}}}
\put(15,20){\circle{6}}
\put(30,20){\circle{6}}
\put(15,20){\circle*{2}}
16
4 ENVIRONMENTS 4.6 Maths
\put(30,20){\circle*{2}}
\put(10,24){\framebox(25,8){a box}}
\put(10,32){\vector(-2,1){10}}
\multiput(1,0)(1,0){49}{\line(0,1){2,5}}
\multiput(5,0)(10,0){5}{\line(0,1){3,5}}
\thicklines
\put(0,0){\line(1,0){50}}
\multiput(0,0)(10,0){6}{\line(0,1){5}}
\end{picture}
YHHH
u
u
a box
cm 1 2 3 4 5
4.6 Maths
Maths is dealt with in a separate handout (LATEX maths and graphics). Here are some
examples
\begin{math}
\lim_{n \rightarrow \infty}x = 0 \\
xˆ{2y} \\
x_{2y} \\
xˆ{2y}_{1} \\
\frac{x+y}{1 + \frac{1}{n+1}} \\
\end{math}
produces limn!1 x = 0
x2y
x2y
2y
x1
x+y
1
1+ n+1
4.7 Figures
To leave a space for graphics, use the figure environment. The arguments to fig-
ure specify where the space will be made, preferentially
h here
t top of page
b bottom of page
p on a page with no text
\begin{figure}[htbp]
\vspace{1cm}
\caption{1 cm of space}
\end{figure}
17
4 ENVIRONMENTS 4.8 Tabbing
Figure 1: 1 cm of space
If you have a label defined in the caption, LATEX is likely to give an error message.
\label is a fragile command (see the LATEX book for details) so you’ll need to do
something like
...
\caption{1 cm of space\protect\label{EMPTY}}
or simply put the \label command after the caption. Note that if you put the
\label before the caption, the resulting reference will be the section number and
not the figure number.
4.8 Tabbing
Within this environment tabs can be set by \= and the next tab moved to by using
\>.
\begin{tabbing}
if \= it’s raining\\ % set tab here, after the ’if’
\> get an umbrella \=\\ % go to the defined tab and set a new one
else\\
\> get wet \> * next tab is here\\
endif
\end{tabbing}
if it’s raining
get an umbrella
else
get wet * next tab is here
endif
4.9 Verbatim
Within this environment things come out unformatted. It’s useful for showing ex-
amples of typed input and provides a way of printing characters that have a special
meaning for LATEX.
\begin{verbatim}
caret is ˆ, tilde is ˜ and backslash is \
\end{verbatim}
produces
If you just want to quote a few characters, use \verb|quoted text|. The characters
delimiting the quote can be anything as long as they are the same.
18
5 CUSTOMISING 4.10 Quote, abstract
4.11 Letter
See letter.tex in /export/Examples/LaTeX2e
5 Customising
5.1 Macros
At the top of the source of this file is
\def\xdt{$\cal X\!\!$\texttt{.desktop}}
X
which defines \xdt to be .desktop. Using such constructions can make your
document much tidier, and saves on typing.
\newenvironment{emlist}{\begin{itemize} \em}{\end{itemize}}
\begin{emlist}
\item first comment
\item second comment
\end{emlist}
The end of the environment ends the scope of the emphasis.
first comment
second comment
The end of the environment ends the scope of the emphasis.
19
5 CUSTOMISING 5.3 Packages
5.3 Packages
There are many features and options not mentioned in this handout. See the Local
LATEX Guide for more details. You can often find out what you want by looking at
the files in /export/latex2e/inputs. If your file begins
\documentclass[12pt]{article}
then various macro files are read when you run latex, namely (article.cls,
art12.sty and latex.tex). Some of these files are well-enough commented to
be useful documentation.
5.4 An Example
The following example uses features mentioned in latex.tex.
minipage creates a miniature page complete with its own footnotes etc. It can
be created of any set width. Footnotes within a minipage use a different counter to
other footnotes 2. This example ensures that all the numbers follow on in sequence.
The footnotes in minipages are marked by letters rather than numbers, so here the
type is changed to arabic.
\begin{minipage}{\textwidth}
% Set the minipage footnote counter
\setcounter{mpfootnote}{\value{footnote}}
% Redefine the command that produces the footnote number
\renewcommand{\thempfootnote}{\arabic{mpfootnote}}
\begin{tabular}{|ll|}\hline
one & two\footnote{A minipage footnote}\\\hline
\end{tabular}
\setcounter{footnote}{\value{mpfootnote}}
\end{minipage}
one two3
3 A minipage footnote
You might find this trick useful if you want footnotes in tables. They don’t come
out otherwise.4
Here’s an example of using a package. The multicol file lets one change the
number of columns easily. To switch into 3-column text use
\begin{multicols}{3}{
Put the text here. Maths, tables, pictures etc are all ok, but not
figures. But you have to remember to load in the \texttt{multicol}
package at the top of your document.
}
\end{multicols}
Put the text here. ures. But you have to top of your document.
Maths, tables, pictures remember to load in the
etc are all ok, but not fig- multicol package at the
20
6 MORE INFORMATION
LATEX uses the value of the environmental variable TEXINPUTS to decide where to
look for sty files. If you create a directory called (say) inputs, copy a system
*.sty file into it and do
export TEXINPUTS=inputs:/export/latex2e/inputs
then your copy will be read in preference to the system one and you can customise
easily.
6 More Information
See the uk.tex newsgroup.
Use the TEX Archive ftp.tex.ac.uk
Use gopher on club to access a database of TEX info. Select Services to
find the option. Suppose we wanted to find out how to put italian into LATEX.
Type latex italian in reply to the search prompt and relevant files will
be presented to you for viewing or copying.
The LTEX 2" handouts (with source) are online. Just type ‘handouts LaTeX2e’.
A
21