LaTeX2e reference manual (May 2013)

Table of Contents

Next: , Up: (dir)   [Contents][Index]

LaTeX2e

This document is an unofficial reference manual for LaTeX, a document preparation system, version as of May 2013. It is intended to cover LaTeX2e, which has been the standard version of LaTeX for many years.

Next: , Previous: Top, Up: Top   [Contents][Index]

1 About this document

The LaTeX document preparation system is implemented as a macro package for Donald E. Knuth’s TeX typesetting program. LaTeX was originally created by Leslie Lamport; it is now maintained by a group of volunteers (http://latex-project.org). The official documentation written by the LaTeX project is available from their web site.

The present document is completely unofficial and has not been reviewed by the LaTeX maintainers. Do not send bug reports or anything else about this document to them. Instead, please send all comments to latexrefman-discuss@gna.org.

The home page for this document is http://home.gna.org/latexrefman. That page has links to the current output in various formats, sources, mailing lists, and other infrastructure.

Of course, there are many, many other sources of information about LaTeX. Here are a few:

http://www.ctan.org/pkg/latex-doc-ptr

Two pages of recommended references to LaTeX documentation.

http://www.ctan.org/pkg/first-latex-doc

Writing your first document, with a bit of both text and math.

http://www.ctan.org/pkg/usrguide

The guide for document authors maintained as part of LaTeX; there are several others.

http://tug.org/begin.html

Introduction to the TeX system, including LaTeX.

Next: , Previous: About this document, Up: Top   [Contents][Index]

2 Overview of LaTeX

What is LaTeX?

LaTeX typesets a file of text using the TeX program and the LaTeX “macro package” for TeX. That is, it processes an input file containing the text of a document with interspersed commands that describe how the text should be formatted. LaTeX files are plain text that can be written in any reasonable editor. It produces at least three files as output:

  1. The main output file, which is one of:
    .dvi

    If invoked as latex, a “Device Independent” (.dvi) file is produced. This contains commands that can be translated into commands for virtually any output device. You can view such .dvi output of LaTeX by using a program such as xdvi (display directly), dvips (convert to PostScript), or dvipdfmx (convert to PDF).

    .pdf

    If invoked as pdflatex, a “Portable Document Format” (.pdf) file. Typically, this is a self-contained file, with all fonts and images embedded. This can be very useful, but it does make the output much larger than the .dvi produced from the same document.

    If invoked as lualatex, a .pdf file is created using the LuaTeX engine (http://luatex.org).

    If invoked as xelatex, a .pdf file is created using the XeTeX engine (http://tug.org/xetex).

    Many other less-common variants of LaTeX (and TeX) exist, which can produce HTML, XML, and other things.

  2. The “transcript” or .log file that contains summary information and diagnostic messages for any errors discovered in the input file.
  3. An “auxiliary” or .aux file. This is used by LaTeX itself, for things such as cross-references.

An open-ended list of other files might be created. We won’t try to list them all. Xxx components?

In the LaTeX input file, a command name starts with a \, followed by either (a) a string of letters or (b) a single non-letter. Arguments contained in square brackets, [], are optional while arguments contained in braces, {}, are required.

LaTeX is case sensitive. Enter all commands in lower case unless explicitly directed to do otherwise.

Next: , Previous: Overview, Up: Top   [Contents][Index]

3 Starting & ending

A minimal input file looks like the following:

\documentclass{class}
\begin{document}
your text
\end{document}

where the class is a valid document class for LaTeX. See Document classes, for details of the various document classes available locally.

You may include other LaTeX commands between the \documentclass and the \begin{document} commands (this area is called the preamble).

Next: , Previous: Starting & ending, Up: Top   [Contents][Index]

4 Document classes

The class of a given document is defined with the command:

\documentclass[options]{class}

The \documentclass command must be the first command in a LaTeX source file.

Built-in LaTeX document class names are (many other document classes are available as add-ons; see Overview):

article  report  book  letter  slides

Standard options are described below.

Up: Document classes   [Contents][Index]

4.1 Document class options

You can specify so-called global options or class options to the \documentclass command by enclosing them in square brackets as usual. To specify more than one option, separate them with a comma:

\documentclass[option1,option2,...]{class}

Here is the list of the standard class options.

All of the standard classes except slides accept the following options for selecting the typeface size (default is 10pt):

10pt  11pt  12pt

All of the standard classes accept these options for selecting the paper size (default is letterpaper):

a4paper a5paper b5paper executivepaper legalpaper letterpaper

Miscellaneous other options:

draft, final

mark/do not mark overfull boxes with a big black box; default is final.

fleqn

Put displayed formulas flush left; default is centered.

landscape

Selects landscape format; default is portrait.

leqno

Put equation numbers on the left side of equations; default is the right side.

openbib

Use “open” bibliography format.

titlepage, notitlepage

Specifies whether the title page is separate; default depends on the class.

These options are not available with the slides class:

onecolumn
twocolumn

Typeset in one or two columns; default is onecolumn.

oneside
twoside

Selects one- or two-sided layout; default is oneside, except for the book class.

The \evensidemargin (\oddsidemargin parameter determines the distance on even (odd) numbered pages between the left side of the page and the text’s left margin. The defaults vary with the paper size and whether one- or two-side layout is selected. For one-sided printing the text is centered, for two-sided, \oddsidemargin is 40% of the difference between \paperwidth and \textwidth, with \evensidemargin the remainder.

openright
openany

Determines if a chapter should start on a right-hand page; default is openright for book.

The slides class offers the option clock for printing the time at the bottom of each note.

Additional packages are loaded like this:

\usepackage[options]{pkg}

To specify more than one pkg, you can separate them with a comma, or use multiple \usepackage commands.

Any options given in the \documentclass command that are unknown by the selected document class are passed on to the packages loaded with \usepackage.

Next: , Previous: Document classes, Up: Top   [Contents][Index]

5 Typefaces

Two important aspects of selecting a font are specifying a size and a style. The LaTeX commands for doing this are described here.

Next: , Up: Typefaces   [Contents][Index]

5.1 Font styles

The following type style commands are supported by LaTeX.

This first group of commands is typically used like \textit{italic text}. The corresponding command in parenthesis is the “declaration form”, which takes no arguments. The scope of the declaration form lasts until the next type style command or the end of the current group.

The declaration forms are cumulative; i.e., you can say either \sffamily\bfseries or \bfseries\sffamily to get bold sans serif.

You can alternatively use an environment form of the declarations; for instance, \begin{ttfamily}...\end{ttfamily}.

These commands automatically supply an italic correction if the

\textrm (\rmfamily)

Roman.

\textit (\itshape)

Italics.

\emph

Emphasis (switches between \textit and \textrm).

\textmd (\mdseries)

Medium weight (default).

\textbf (\bfseries)

Boldface.

\textup (\upshape)

Upright (default). The opposite of slanted.

\textsl (\slshape)

Slanted.

\textsf (\sffamily)

Sans serif.

\textsc (\scshape)

Small caps.

\texttt (\ttfamily)

Typewriter.

\textnormal (\normalfont)

Main document font.

\mathrm

Roman, for use in math mode.

\mathbf

Boldface, for use in math mode.

\mathsf

Sans serif, for use in math mode.

\mathtt

Typewriter, for use in math mode.

\mathit
(\mit)

Italics, for use in math mode.

\mathnormal

For use in math mode, e.g. inside another type style declaration.

\mathcal

‘Calligraphic’ letters, for use in math mode.

In addition, the command \mathversion{bold} can be used for switching to bold letters and symbols in formulas. \mathversion{normal} restores the default.

Finally, the command \oldstylenums{numerals} will typeset so-called “old-style” numerals, which have differing heights and depths (and sometimes widths) from the standard “lining” numerals. LaTeX’s default fonts support this, and will respect \textbf (but not other styles; there are no italic old-style numerals in Computer Modern). Many other fonts have old-style numerals also; sometimes the textcomp package must be loaded, and sometimes package options are provided to make them the default. FAQ entry: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=osf.

LaTeX also provides these commands, which unconditionally switch to the given style, that is, are not cumulative. They are used differently than the above commands, too: {\cmd ...} instead of \cmd{...}. These are two very different things.

\bf

Switch to bold face.

\cal

Switch to calligraphic letters for math.

\em

Emphasis (italics within roman, roman within italics).

\it

Italics.

\rm

Roman.

\sc

Small caps.

\sf

Sans serif.

\sl

Slanted (oblique).

\tt

Typewriter (monospace, fixed-width).

Next: , Previous: Font styles, Up: Typefaces   [Contents][Index]

5.2 Font sizes

The following standard type size commands are supported by LaTeX. The table shows the command name and the corresponding actual font size used (in points) with the ‘10pt’, ‘11pt’, and ‘12pt’ document size options, respectively (see Document class options).

Command10pt11pt12pt
\tiny566
\scriptsize788
\footnotesize8910
\small91010.95
\normalsize (default)1010.9512
\large121214.4
\Large14.414.417.28
\LARGE17.2817.2820.74
\huge20.7420.7424.88
\Huge24.8824.8824.88

The commands as listed here are “declaration forms”. The scope of the declaration form lasts until the next type style command or the end of the current group. You can also use the environment form of these commands; for instance, \begin{tiny}...\end{tiny}.

Previous: Font sizes, Up: Typefaces   [Contents][Index]

5.3 Low-level font commands

These commands are primarily intended for writers of macros and packages. The commands listed here are only a subset of the available ones.

\fontencoding{enc}

Select font encoding. Valid encodings include OT1 and T1.

\fontfamily{family}

Select font family. Valid families include:

and numerous others.

\fontseries{series}

Select font series. Valid series include:

and various other combinations.

\fontshape{shape}

Select font shape. Valid shapes are:

The two last shapes are not available for most font families.

\fontsize{size}{skip}

Set font size. The first parameter is the font size to switch to and the second is the line spacing to use; this is stored in a parameter named \baselineskip. The unit of both parameters defaults to pt. The default \baselineskip for the Computer Modern typeface is 1.2 times the \fontsize.

The line spacing is also multiplied by the value of the \baselinestretch parameter when the type size changes; the default is 1. However, the best way to “double space” a document, if you should be unlucky enough to have to produce such, is to use the setspace package; see http://www.tex.ac.uk/cgi-bin/texfaq2html?label=linespace.

\linespread{factor}

Equivalent to \renewcommand{\baselinestretch}{factor}, and therefore must be followed by \selectfont to have any effect. Best specified in the preamble, or use the setspace package, as described just above.

The changes made by calling the font commands described above do not come into effect until \selectfont is called.

\usefont{enc}{family}{series}{shape}

The same as invoking \fontencoding, \fontfamily, \fontseries and \fontshape with the given parameters, followed by \selectfont.

Next: , Previous: Typefaces, Up: Top   [Contents][Index]

6 Layout

Miscellaneous commands for controlling the general layout of the page.

Next: , Up: Layout   [Contents][Index]

6.1 \onecolumn

The \onecolumn declaration starts a new page and produces single-column output. This is the default.

Next: , Previous: \onecolumn, Up: Layout   [Contents][Index]

6.2 \twocolumn

Synopsis:

\twocolumn[text1col]

The \twocolumn declaration starts a new page and produces two-column output. If the optional text1col argument is present, it is typeset in one-column mode before the two-column typesetting starts.

These parameters control typesetting in two-column output:

\columnsep

The distance between columns (35pt by default).

\columnseprule

The width of the rule between columns; the default is 0pt, so there is no rule.

\columnwidth

The width of the current column; this is equal to \textwidth in single-column text.

These parameters control float behavior in two-column output:

\dbltopfraction

Maximum fraction at the top of a two-column page that may be occupied by floats. Default ‘.7’, can be usefully redefined to (say) ‘.9’ to avoid going to float pages so soon.

\dblfloatpagefraction

The minimum fraction of a float page that must be occupied by floats, for a two-column float page. Default ‘.5’.

\dblfloatsep

Distance between floats at the top or bottom of a two-column float page. Default ‘12pt plus2pt minus2pt’ for ‘10pt’ and ‘11pt’ documents, ‘14pt plus2pt minus4pt’ for ‘12pt’.

\dbltextfloatsep

Distance between a multi-column float at the top or bottom of a page and the main text. Default ‘20pt plus2pt minus4pt’.

Next: , Previous: \twocolumn, Up: Layout   [Contents][Index]

6.3 \flushbottom

The \flushbottom declaration makes all text pages the same height, adding extra vertical space where necessary to fill out the page.

This is the default if twocolumn mode is selected (see Document class options).

Next: , Previous: \flushbottom, Up: Layout   [Contents][Index]

6.4 \raggedbottom

The \raggedbottom declaration makes all pages the natural height of the material on that page. No rubber lengths will be stretched.

Previous: \raggedbottom, Up: Layout   [Contents][Index]

6.5 Page layout parameters

\headheight

Height of the box that contains the running head. Default is ‘30pt’, except in the book class, where it varies with the type size.

\headsep

Vertical distance between the bottom of the header line and the top of the main text. Default is ‘25pt’, except in the book class, where it varies with the type size.

\footskip

Distance from the baseline of the last line of text to the baseline of the page footer. Default is ‘30pt’, except in the book class, where it varies with the type size.

\linewidth

Width of the current line, decreased for each nested list (see list). Specifically, it is smaller than \textwidth by the sum of \leftmargin and \rightmargin (see itemize). The default varies with the font size, paper width, two-column mode, etc. For an article document in ‘10pt’, it’s set to ‘345pt’; in two-column mode, that becomes ‘229.5pt’.

\textheight

The normal vertical height of the page body; the default varies with the font size, document class, etc. For an article or report document in ‘10pt’, it’s set to ‘43\baselineskip’; for book, it’s ‘41\baselineskip’. For ‘11pt’, it’s ‘38\baselineskip’ and for ‘12pt’, ‘36\baselineskip’.

\textwidth

The full horizontal width of the entire page body; the default varies as usual. For an article or report document, it’s ‘345pt’ at ‘10pt’, ‘360pt’ at ‘11pt’, and ‘390pt’ at ‘12pt’. For a book document, it’s ‘4.5in’ at ‘10pt’, and ‘5in’ at ‘11pt’ or ‘12pt’.

In multi-column output, \textwidth remains the width of the entire page body, while \columnwidth is the width of one column (see \twocolumn).

In lists (see list), \textwidth remains the width of the entire page body (and \columnwidth the width of the entire column), while \linewidth may decrease for nested lists.

Inside a minipage (see minipage) or \parbox (see \parbox), all the width-related parameters are set to the specified width, and revert to their normal values at the end of the minipage or \parbox.

For completeness: \hsize is the TeX primitive parameter used when text is broken into lines. It should not be used in normal LaTeX documents.

\topmargin

Space between the top of the TeX page (one inch from the top of the paper, by default) and the top of the header. The default is computed based on many other parameters: \paperheight - 2in - \headheight - \headsep - \textheight - \footskip, and then divided by two.

\topskip

Minimum distance between the top of the page body and the baseline of the first line of text. For the standard clases, the default is the same as the font size, e.g., ‘10pt’ at ‘10pt’.

Next: , Previous: Layout, Up: Top   [Contents][Index]

7 Sectioning

Sectioning commands provide the means to structure your text into units:

\part
\chapter

(report and book class only)

\section
\subsection
\subsubsection
\paragraph
\subparagraph

All sectioning commands take the same general form, e.g.,

\chapter[toctitle]{title}

In addition to providing the heading title in the main text, the section title can appear in two other places:

  1. The table of contents.
  2. The running head at the top of the page.

You may not want the same text in these places as in the main text. To handle this, the sectioning commands have an optional argument toctitle that, when given, specifies the text for these other places.

Also, all sectioning commands have *-forms that print title as usual, but do not include a number and do not make an entry in the table of contents. For instance:

\section*{Preamble}

The \appendix command changes the way following sectional units are numbered. The \appendix command itself generates no text and does not affect the numbering of parts. The normal use of this command is something like

\chapter{A Chapter}
…
\appendix
\chapter{The First Appendix}

The secnumdepth counter controls printing of section numbers. The setting

\setcounter{secnumdepth}{level}

suppresses heading numbers at any depth > level, where chapter is level zero. (See \setcounter.)

Next: , Previous: Sectioning, Up: Top   [Contents][Index]

8 Cross references

One reason for numbering things like figures and equations is to refer the reader to them, as in “See Figure 3 for more details.”

Next: , Up: Cross references   [Contents][Index]

8.1 \label

Synopsis:

\label{key}

A \label command appearing in ordinary text assigns to key the number of the current sectional unit; one appearing inside a numbered environment assigns that number to key.

A key name can consist of any sequence of letters, digits, or punctuation characters. Upper and lowercase letters are distinguished.

To avoid accidentally creating two labels with the same name, it is common to use labels consisting of a prefix and a suffix separated by a colon or period. Some conventionally-used prefixes:

ch

for chapters

sec

for lower-level sectioning commands

fig

for figures

tab

for tables

eq

for equations

Thus, a label for a figure would look like fig:snark or fig.snark.

Next: , Previous: \label, Up: Cross references   [Contents][Index]

8.2 \pageref{key}

Synopsis:

\pageref{key}

The \pageref{key} command produces the page number of the place in the text where the corresponding \label{key} command appears.

Previous: \pageref, Up: Cross references   [Contents][Index]

8.3 \ref{key}

Synopsis:

\ref{key}

The \ref command produces the number of the sectional unit, equation, footnote, figure, …, of the corresponding \label command (see \label). It does not produce any text, such as the word ‘Section’ or ‘Figure’, just the bare number itself.

Next: , Previous: Cross references, Up: Top   [Contents][Index]

9 Environments

LaTeX provides many environments for marking off certain text. Each environment begins and ends in the same manner:

\begin{envname}
...
\end{envname}

Next: , Up: Environments   [Contents][Index]

9.1 abstract

Synopsis:

\begin{abstract}
...
\end{abstract}

Environment for producing an abstract, possibly of multiple paragraphs.

Next: , Previous: abstract, Up: Environments   [Contents][Index]

9.2 array

Synopsis:

\begin{array}{template}
col1 text&col1 text&coln}\\
...
\end{array}

Math arrays are produced with the array environment, normally within an equation environment (see equation). It has a single mandatory template argument describing the number of columns and the alignment within them. Each column col is specified by a single letter that tells how items in that row should be formatted, as follows:

c

centered

l

flush left

r

flush right

Column entries are separated by &. Column entries may include other LaTeX commands. Each row of the array is terminated with \\.

In the template, the construct @{text} puts text between columns in each row.

Here’s an example:

\begin{equation}
  \begin{array}{lrc}
  left1 & right1 & centered1 \\
  left2 & right2 & centered2 \\
  \end{array}
\end{equation}

The \arraycolsep parameter defines half the width of the space separating columns; the default is ‘5pt’. See tabular, for other parameters which affect formatting in array environments, namely \arrayrulewidth and \arraystretch.

The array environment can only be used in math mode.

Next: , Previous: array, Up: Environments   [Contents][Index]

9.3 center

Synopsis:

\begin{center}
line1 \\
line2 \\
\end{center}

The center environment allows you to create a paragraph consisting of lines that are centered within the left and right margins on the current page. Each line is terminated with the string \\.

Up: center   [Contents][Index]

9.3.1 \centering

The \centering declaration corresponds to the center environment. This declaration can be used inside an environment such as quote or in a parbox. Thus, the text of a figure or table can be centered on the page by putting a \centering command at the beginning of the figure or table environment.

Unlike the center environment, the \centering command does not start a new paragraph; it simply changes how LaTeX formats paragraph units. To affect a paragraph unit’s format, the scope of the declaration must contain the blank line or \end command (of an environment such as quote) that ends the paragraph unit.

Here’s an example:

\begin{quote}
\centering
first line \\
second line \\
\end{quote}

Next: