-->
Previous Table of Contents Next


Putting Structure into a LaTeX Document

LaTeX has commands that make it easy to enhance your document structurally, thus making it easier for the reader to digest. For the article document class, the commands are as follows:

\section
\subsection
\subsubsection
\paragraph
\subparagraph, and
\appendix.

These commands, with the exception of \appendix, accept titles as arguments, and are declared before the body of text that they represent. LaTeX takes care of the rest; it sets the appropriate spacing between sections, section numbering, and title font. The \appendix command uses alphabetic increments in order to number succeeding appendix sections.

For the report and book classes, there are two additional commands: \part and \chapter. The \part command enables you to insert a section without affecting the numbering sequence of the chapters. You can suppress the appearance of a section in the table of contents by inserting a * character in the section command, as in the following:


\section*{I don’t want to know about it}

You probably want to add a title to your document. This is done by specifying the arguments to the title commands and then calling the \maketitle command:


...

\title{Confessions of a LaTeX Enthusiast}

\author{Me}

\date

\begin{document}

\maketitle

...

To insert a table of contents in your document, issue the \tableofcontents command (big surprise) at the point where you want the table to appear. When you process your document with LaTeX, it needs two passes: one to make note of all the section numbers, and the other to build the table of contents from the information it collected in the first pass.

Adding Other Structural Elements

You can add cross-references to your document, which tie associated elements such as text, figures, and tables to text in other parts of your document. Use the \label command to set a point that you want to refer to, and give it an argument that is any name you choose. This name can then be referred to by the \ref and \pageref commands to generate a cross-reference containing the section number and page number that the section title appears on.

You can easily add footnotes using the \footnote command, which accepts the text of the footnote as an argument.

The structure of a document can be enhanced by controlling the presentation of the text that appears between section titles. This can be easily managed by using LaTeX environments. Environments are specified by bounding a portion of text with \begin and \end commands, and passing an environment name to each command, as in the following:


\begin{hostileenvironment}

Looks like we’re surrounded, said Custer.

\end{hostileenvironment}

LaTeX has many predefined environments for practical applications, as described in Table 19.5.

Table 19.5. Predefined environments.

Environment Description
center Centers text.
description Used to present descriptive paragraphs.
enumerate Used for numbered or bulleted lists.
flushleft Paragraphs are left-aligned.
flushright Paragraphs are right-aligned.
itemize Used for simple lists.
quote Used to quote single paragraphs.
quotation Used for longer quotes that span several paragraphs.
tabular Typesets tables with optional row and column separators.
verbatim Produces typed text. Useful for representing programming code, for example.
verse Used to control the linebreaks in poems.

Working with Figures and Tables

LaTeX also supports the variable placement (or “floating”) of figures and tables in a document using the table and figure environments. A figure could be specified as follows:


\begin{figure}[!hbp]

\makebox[\textwidth]{\framebox[2in]{\rule{Opt}{2in}}}

\end{figure}

The options passed to the \begin{figure} command are placement specifiers that indicate your preferences for the location of the figure. LaTeX has to juggle the placement of floating figures and tables in a document by using these preferences, as well as internal guidelines such as the maximum number of floats allowed per page. In this example, you told LaTeX to keep the figure with its adjacent text (h), at the bottom of the next applicable page (b), or, failing that, on a special page with other floating figures (p). The ! character overrides LaTeX’s best intentions for placing the figure, which may not necessarily jibe with what you are saying with the other placement specifiers.

Tables and figures can be labeled using the \caption command, which must be issued within the table or figure environment.

These are just some of the basics for using LaTeX, but hopefully they are sufficient to give you a place to start on the road to making your documents more visually appealing. You have probably noticed that LaTeX is somewhat easier to work with than TeX itself, because it hides much detail from you as an author.

VirTeX and IniTeX

Two other TeX-related programs work together but perform slightly different roles. The IniTeX program is used to create a TeX format (.fmt) file containing font definitions and macros. The VirTeX program can then quickly load this precompiled format file, much more quickly than TeX can. The command to use a format file is as follows:


$ virtex \&myformat sometexfile

The & character is necessary for VirTeX to recognize that it is loading a format file first; the & must be escaped using the \ character so as not to confuse the shell. The difference between VirTeX and IniTeX is that VirTeX can’t be used to create TeX format files, but it executes much faster.


Previous Table of Contents Next