📌 「LaTeX极简入门」第12.7讲:figure图形环境精讲
——掌握图片插入、浮动体控制与多图排版技巧
📝 文章摘要
“本讲深入解析LaTeX的figure图形环境,详解其浮动体特性、placement位置参数、caption标题添加,以及如何通过graphicx宏包插入图片,助您实现专业级图文混排。”
文章目录
一、🔥 figure环境概述:浮动的图片相框
核心定义:
👉 就像给图片一个可移动的展示相框,figure
环境允许LaTeX自动调整图片位置(如页面顶部或底部),避免正文分页断裂,确保排版整洁。
1.1 核心特性
- 自动浮动:LaTeX智能放置图片,避免中间分页(如表格和图形)。
- 灵活定位:通过
placement
参数(如h、t、b、p)控制大致位置。 - 多栏支持:
figure*
环境用于双栏文档,跨栏显示图片。 - 标题与引用:支持添加编号标题(caption)和交叉引用(label)。
1.2 基本概念
- figure环境以
\begin{figure}[placement]
开始,以\end{figure}
结束。 - 必须包含图片内容(如通过
\includegraphics
插入),可选的\caption
和\label
。 - 默认宽度为
\textwidth
,内容在parbox中排版。
二、⭐ 基础三步操作指南
▶ 步骤1:创建基础figure环境并插入图片
\usepackage{graphicx} % 在导言区引入宏包
\begin{figure}[htbp] % 常用placement组合
\centering % 居中图片
\includegraphics[width=0.5\textwidth]{example-image.png}
\caption{示例图片标题}
\label{fig:example}
\end{figure}
输出效果:图片居中显示,带有编号标题(如“Figure 1: 示例图片标题”),可在文中通过\ref{fig:example}
引用。
▶ 步骤2:添加标题和标签用于引用
\begin{figure}[t] % 优先放在页面顶部
\includegraphics[width=0.8\textwidth]{CTANlion.png}
\caption{The CTAN lion, by Duane Bibby} % 标题文本
\label{fig:lion} % 标签用于引用
\end{figure}
在文本中引用:如图~\ref{fig:lion} 所示...
注意:\caption
和\label
的顺序很重要——通常\label
放在\caption
后以确保正确编号。
▶ 步骤3:使用figure*环境用于双栏模式
\begin{figure*}[t] % 跨双栏的顶部
\includegraphics[width=\textwidth]{wide-image.png}
\caption{跨栏图片示例}
\label{fig:wide}
\end{figure*}
应用场景:在\twocolumn
文档中,使图片横跨两栏。
三、🚫 新手易错点提醒
placement参数过度使用或误解:
- 错误:只使用
[h]
(here)可能导致图片无法放置(如果空间不足),LaTeX会忽略它并浮动到其他位置。 - 解决:使用组合参数如
[htbp]
增加灵活性,或避免严格限制位置。
% 可能问题:如果当前位置空间不足,[h] 可能无效
\begin{figure}[h]
\includegraphics{image.png}
\caption{图片}
\end{figure}
% 更好:使用 [htbp] 允许多种位置
\begin{figure}[htbp]
\includegraphics{image.png}
\caption{图片}
\end{figure}
其他常见错误:
- 忘记添加
\usepackage{graphicx}
宏包,导致\includegraphics
未定义。 \label
放在\caption
前,导致引用编号错误。
四、🔧 进阶技巧:深度自定义
4.1 精确控制图片位置和样式
% 自定义宽度和边框
\includegraphics[width=0.6\textwidth, frame]{image.png}
% 添加子图(需subcaption宏包)
\usepackage{subcaption}
\begin{figure}
\centering
\begin{subfigure}{0.45\textwidth}
\includegraphics[width=\textwidth]{image1.png}
\caption{子图1}
\end{subfigure}
\begin{subfigure}{0.45\textwidth}
\includegraphics[width=\textwidth]{image2.png}
\caption{子图2}
\end{subfigure}
\caption{多图示例}
\end{figure}
4.2 处理浮动体限制
% 强制放置在此处(可能影响排版,慎用)
\usepackage{float}
\begin{figure}[H] % 大写H强制当前位置
\includegraphics{image.png}
\caption{强制放置}
\end{figure}
4.3 列表中的图片引用
% 在列表中添加图片引用
\begin{itemize}
\item 参考图~\ref{fig:example} 细节
\end{itemize}
💎 总结卡片
功能 | 命令/方法 | 说明 |
---|---|---|
开始环境 | \begin{figure}[placement] | 启动浮动图形环境 |
结束环境 | \end{figure} | 关闭环境 |
插入图片 | \includegraphics[options]{file} | 需graphicx宏包 |
添加标题 | \caption{text} | 自动编号 |
添加标签 | \label{fig:label} | 用于交叉引用 |
双栏环境 | figure* | 跨双栏排版 |
▶️ 下期预告
「LaTeX极简入门」第12.8讲:itemize项目列表环境精讲
——掌握无序列表示、自定义符号与嵌套技巧
(点赞过100加速更新!👇)