Floating tables and illustrations
10.4.3 Floating tables and illustrations
Many documents contain tables and illustrations. These must be treated in a special way since they cannot be broken across pages. If necessary, L A TEX moves—floats—
a table or an illustration to the top or bottom of the current or the next page if possible and further away if not. L A TEX provides the table and the figure environments for typesetting floats. The two are essentially identical except that the figure environments are named Fig- ure 1, Figure 2, and so on, whereas the table environments are numbered as Table 1, Table 2, and so on.
Tables
A table environment is set up as follows: \begin{table}
Place the table here \caption{title }\label{Ta:xxx } \end{table}
10.4 Main matter 259
The \caption command is optional and may also precede the table. The optional \label command must be placed between the command \caption and the command \end{table}. The label is used to reference the table’s number. A table environment can have more than one table, each with its own caption.
The table environment is primarily used for tables made with the tabular or similar environments (see Section 6.6). There are many examples of tables in this book, for instance, Section 5.4 has four.
If your document uses the twocolumn document class option, the table environ- ment produces tables that span only one column and the table* environment produces tables that span both columns. Such tables can be placed only at the top of a page.
Figures Illustrations, also called graphics or figures, include drawings, scanned images, digi-
tized photos, and so on. These can be inserted with a figure environment: \begin{figure}
Place the graphics here \caption{title }\label{Fi:xxx } \end{figure}
The above discussion of captions and labels for tables also applies to figures. Like the table environment, if your document uses the twocolumn document class option, the figure environment produces figures that span only one column, but the figure* environment produces figures that span both columns. However, these figures can be placed only at the top of a page.
The standard way of including a graphics file is with the commands provided by the graphicx package by David Carlisle and Sebastian Rahtz, which is part of the L A TEX distribution (see Section 12.3). Save your graphics in EPS (Encapsulated PostScript) or PDF (Portable Document Format) format. Your graphics can also be made within a picture environment, an approach that is neither encouraged nor dis- cussed in this book.
Using the graphicx package, a typical figure is specified as follows: \begin{figure}
\centering\includegraphics{file } \caption{title }\label{Fi:xxx }
\end{figure} The illustration circle.eps is included with the command \includegraphics{circle}
without the extension! L A TEX and the graphicx package assumes the eps extension. On the other hand, versions of L A TEX that produce a typeset file in PDF format assume the pdf extension.
260 Chapter 10 L A TEX documents If you have to scale the graphics image, say to 68% of its original size, use the
command \includegraphics[scale=.68]{file } For instance, the figure on page 526 is included with the commands \begin{figure}
\centering\includegraphics[scale=.8]{StrucLaT} \caption{The structure of \protect\LaTeX.} \label{Fi:StrucLaT}
\end{figure}
Float control The table and figure environments may have an optional argument, with which you
can influence L A TEX’s placement of the typeset table. The optional argument consists of one to four letters:
b, the bottom of the page
h, here (where the environment appears in the text) t, the top of the page p, a separate page
For instance, \begin{table}[ht]
requests L A TEX to place the table “here” or at the “top” of a page. The default is [tbp] and the order of the optional arguments is immaterial, for example, [th] is the same as [ht]. If h is specified, it takes precedence, followed by t and b.
L A TEX has more than a dozen internal parameters that control a complicated algo- rithm that determines the placement of tables and figures. If you want to override these parameters for one table or figure only, add an exclamation mark (!) to the optional argument. For instance, [!h] requests that this table or figure be placed where it is in the source file even if this placement violates the rules as set by some of the param-
eters. For a detailed discussion of the float mechanism, see Chapter 6 of The L A TEX Companion, 2nd edition [46]. The \suppressfloats command stops L A TEX from placing any more tables or figures on the page it appears on. An optional argument t or b (but not both) prohibits placement of floats at the top or bottom of the current page. The table or figure that is suppressed appears on the next page or later in the document, if necessary.
Your demands and L A TEX’s float mechanism may conflict with one another with the result that L A TEX may not place material where you want it. The default values
10.5 Back matter 261
of the float placement parameters are good only for documents with a small number of floating objects. Combining two tables or illustrations into one sometimes helps. The \clearpage command not only starts a new page with the \newpage command,
but also forces L A TEX to print all the tables and figures it has accumulated but not yet placed in the typeset document. See also some related commands discussed in Sec- tion 5.7.3.
For more information on graphics, see Chapter 10 of The L A TEX Companion, 2nd edition [46] and Chapter 2 of The L A TEX Graphics Companion [17]. See also the docu- mentation for the graphicx package in the L A TEX distribution (see Section 12.3).