如同第 16 章所介绍的那样, LATEX 允许图形和
表格 ``浮动'' 以增强排版效果。不过,偶尔也会希望一幅图形不要浮动, 就放置在与它在 LATEX 源文件中相同的位置20.1。 \caption 命令可以在 figure 和 table 环境中
使用是因为这两个环境各自定义了内部命令 \@captype。这样,通过定义
\@captype 就可以在 figure 和 table 环境外
使用 \caption 命令。当然这时 \@captype 必须用 \makeatletter-\makeatother 命令对包围起来,使得可以在命令名中使用 @。
在每次使用时可用如下的命令:
\includegraphics{file.eps}
\makeatletter\def\@captype{figure}\makeatother
\caption{This is the caption}
在导言区中定义下面的命令会更加方便。
\makeatletter
\newcommand\figcaption{\def\@captype{figure}\caption}
\newcommand\tabcaption{\def\@captype{table}\caption}
\makeatother
这样在正文中无论是否在图形环境中,都可用 \figcaption 来得到图形标题。
同样地,无论是否在表格环境中,都可用 \tabcaption 来得到表格标题。
下面的命令
This is the text before the figure.
\\[\intextsep]
\begin{minipage}{\textwidth}
\centering
\includegraphics[width=2in]{graphic.eps}%
\figcaption{This is a non-floating figure}
\label{fig:non:float}
\end{minipage}
\\[\intextsep]
This is the text after the figure.
可得到一幅不浮动的图形。对于不浮动的图形,需要注意下面几点:
- 需要使用小页环境(minipage)来防止在图形中出现分页的情况。
- 命令 \\[\intextsep] 开始一新行并在图形的前后加上
垂直的空白。任意大小的空白都可以, \intextsep (见
第 18.1 节)被用来使不浮动的图形具有与浮动图形相同的上
下间距。
- 一般地,浮动图形是按照它们在 LATEX 源文件中的顺序一一被放置的。
而不浮动的图形是被立即放置到页面上,所以可能会出现图形顺序错误的 情况,图形出现的顺序被打乱 20.2。要避免这种顺序 错乱,可在不浮动的图形前用 \clearpage 或 \FloatBarrier 命令
清除未处理的浮动图形(见第 16.3 节)。
- \figcaption 和 \tabcaption 在生成边注图形(见
第 21 章)以及与图形并列的表格(见
第 29 章)时会很有用。
|