latex-figure-table-layout
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLaTeX Figure and Table Layout
LaTeX 图表布局
Expert guidance for positioning figures and tables in LaTeX documents. This skill handles float placement, subfigure arrangements, side-by-side layouts, and cross-column positioning.
为LaTeX文档中的图表定位提供专业指导。本技能涵盖浮动元素放置、子图排列、并排布局以及跨栏定位。
When to Use This Skill
何时使用本技能
Use this skill when:
- Adjusting figure/table position parameters (,
[h],[t],[b])[p] - Arranging multiple figures/tables in subfigures
- Creating side-by-side figure or figure+table layouts
- Fixing float positioning issues (drifting, page alone)
- Working with cross-column figures (,
figure*)table*
NOTE: This skill does NOT modify sizes, column widths, or scaling. Only positioning.
在以下场景使用本技能:
- 调整图表位置参数(、
[h]、[t]、[b])[p] - 用子图排列多个图表
- 创建并排图表或图+表布局
- 修复浮动定位问题(漂移、单独占页)
- 处理跨栏图表(、
figure*)table*
注意:本技能不修改尺寸、列宽或缩放比例,仅处理定位。
Float Position Parameters
浮动元素位置参数
Position Specifiers
位置指定符
| Parameter | Meaning | Priority |
|---|---|---|
| Here (exact location) | Highest |
| Top of page | Medium |
| Bottom of page | Medium |
| Separate float page | Lowest |
| Override LaTeX defaults | - |
| 参数 | 含义 | 优先级 |
|---|---|---|
| 此处(精确位置) | 最高 |
| 页面顶部 | 中等 |
| 页面底部 | 中等 |
| 单独的浮动页 | 最低 |
| 覆盖LaTeX默认规则 | - |
Recommended Order
推荐顺序
latex
\begin{figure}[htbp] % Recommended: try here, then top, bottom, then float page
\end{figure}latex
\begin{figure}[htbp] % 推荐:优先此处,其次顶部、底部,最后浮动页
\end{figure}Strong Recommendations
强制推荐写法
latex
\begin{figure}[!htbp] % Force LaTeX to respect your order
\end{figure}Best Practice: Use or for most cases. Avoid single which can cause float to drift.
[htbp][!htbp][h]latex
\begin{figure}[!htbp] % 强制LaTeX遵循指定的位置顺序
\end{figure}最佳实践:大多数场景使用或。避免单独使用,这会导致浮动元素漂移。
[htbp][!htbp][h]Subfigure Layout with subcaption
使用subcaption实现子图布局
Basic Subfigures (2 side-by-side)
基础子图(2个并排)
latex
\usepackage{subcaption}
\begin{figure}[htbp]
\centering
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{figure1.pdf}
\caption{First figure}
\label{fig:first}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\filename]{figure2.pdf}
\caption{Second figure}
\label{fig:second}
\end{subfigure}
\caption{Main caption for both figures}
\label{fig:both}
\end{figure}latex
\usepackage{subcaption}
\begin{figure}[htbp]
\centering
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{figure1.pdf}
\caption{第一张图}
\label{fig:first}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\filename]{figure2.pdf}
\caption{第二张图}
\label{fig:second}
\end{subfigure}
\caption{两张图的主标题}
\label{fig:both}
\end{figure}Subfigures in Grid (2x2)
网格布局子图(2x2)
latex
\begin{figure}[htbp]
\centering
\begin{subfigure}[t]{0.45\textwidth}
\includegraphics[width=\filename]{fig1.pdf}
\caption{Caption A}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.45\textwidth}
\includegraphics[width=\filename]{fig2.pdf}
\caption{Caption B}
\end{bmatrix}
\\
\begin{subfigure}[t]{0.45\textwidth}
\includegraphics[width=\filename]{fig3.pdf}
\caption{Caption C}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.45\textwidth}
\includegraphics[width=\filename]{fig4.pdf}
\caption{Caption D}
\end{subfigure}
\caption{Main caption for all four}
\label{fig:grid}
\end{figure}latex
\begin{figure}[htbp]
\centering
\begin{subfigure}[t]{0.45\textwidth}
\includegraphics[width=\filename]{fig1.pdf}
\caption{标题A}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.45\textwidth}
\includegraphics[width=\filename]{fig2.pdf}
\caption{标题B}
\end{bmatrix}
\\
\begin{subfigure}[t]{0.45\textwidth}
\includegraphics[width=\filename]{fig3.pdf}
\caption{标题C}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.45\textwidth}
\includegraphics[width=\filename]{fig4.pdf}
\caption{标题D}
\end{subfigure}
\caption{四张图的主标题}
\label{fig:grid}
\end{figure}Subtables
子表
latex
\begin{table}[htbp]
\centering
\begin{subtable}[t]{0.45\textwidth}
\centering
\begin{tabular}{cc}
\toprule
A & B \\
\midrule
1 & 2 \\
\bottomrule
\end{tabular}
\caption{First table}
\label{tab:first}
\end{subtable}
\hfill
\begin{subtable}[t]{0.45\textwidth}
\centering
\begin{tabular}{cc}
\toprule
C & D \\
\midrule
3 & 4 \\
\bottomrule
\end{tabular}
\caption{Second table}
\label{tab:second}
\end{subtable}
\caption{Main caption}
\label{tab:both}
\end{table}latex
\begin{table}[htbp]
\centering
\begin{subtable}[t]{0.45\textwidth}
\centering
\begin{tabular}{cc}
\toprule
A & B \\
\midrule
1 & 2 \\
\bottomrule
\end{tabular}
\caption{第一张表}
\label{tab:first}
\end{subtable}
\hfill
\begin{subtable}[t]{0.45\textwidth}
\centering
\begin{tabular}{cc}
\toprule
C & D \\
\midrule
3 & 4 \\
\bottomrule
\end{tabular}
\caption{第二张表}
\label{tab:second}
\end{subtable}
\caption{主标题}
\label{tab:both}
\end{table}Side-by-Side: Figure + Table
并排布局:图 + 表
Using minipage
使用minipage
latex
\begin{figure}[htbp]
\centering
\begin{minipage}[c]{0.45\textwidth}
\centering
\includegraphics[width=\filename]{figure.pdf}
\caption{My figure}
\label{fig:minipage}
\end{minipage}
\hfill
\begin{minipage}[c]{0.45\textwidth}
\centering
\begin{tabular}{lc}
\toprule
Method & Acc \\
\midrule
A & 85.2 \\
B & 92.1 \\
\bottomrule
\end{tabular}
\caption{My table}
\label{tab:minipage}
\end{minipage}
\caption{Combined figure and table}
\label{fig+tab}
\end{figure}latex
\begin{figure}[htbp]
\centering
\begin{minipage}[c]{0.45\textwidth}
\centering
\includegraphics[width=\filename]{figure.pdf}
\caption{我的图}
\label{fig:minipage}
\end{minipage}
\hfill
\begin{minipage}[c]{0.45\textwidth}
\centering
\begin{tabular}{lc}
\toprule
Method & Acc \\
\midrule
A & 85.2 \\
B & 92.1 \\
\bottomrule
\end{tabular}
\caption{我的表}
\label{tab:minipage}
\end{minipage}
\caption{组合图和表}
\label{fig+tab}
\end{figure}Using subcaptionbox
使用subcaptionbox
latex
\begin{figure}[htbp]
\centering
\subcaptionbox{Figure label\label{fig:subcap}}
{\includegraphics[width=0.45\textwidth]{figure.pdf}}
\qquad
\subcaptionbox{Table label\label{tab:subcap}}
{\begin{tabular}{lc}
\toprule
A & B \\
\midrule
1 & 2 \\
\bottomrule
\end{tabular}}
\caption{Combined caption}
\label{fig:subcap:combined}
\end{figure}latex
\begin{figure}[htbp]
\centering
\subcaptionbox{图标签\label{fig:subcap}}
{\includegraphics[width=0.45\textwidth]{figure.pdf}}
\qquad
\subcaptionbox{表标签\label{tab:subcap}}
{\begin{tabular}{lc}
\toprule
A & B \\
\midrule
1 & 2 \\
\bottomrule
\end{tabular}}
\caption{组合标题}
\label{fig:subcap:combined}
\end{figure}Cross-Column Figures (twocolumn)
跨栏图表(twocolumn模式)
Cross-Column Figure
跨栏图
latex
\begin{figure*}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{wide-figure.pdf}
\caption{Wide figure spanning both columns}
\label{fig:wide}
\end{figure*}latex
\begin{figure*}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{wide-figure.pdf}
\caption{横跨两栏的宽图}
\label{fig:wide}
\end{figure*}Cross-Column Table
跨栏表
latex
\begin{table*}[htbp]
\centering
\begin{tabular}{lcccc}
\toprule
Method & A & B & C & D \\
\midrule
Baseline & 85.2 & 86.1 & 87.3 & 88.0 \\
Ours & \textbf{92.1} & \textbf{91.5} & \textbf{93.2} & \textbf{94.1} \\
\bottomrule
\end{tabular}
\caption{Wide table spanning both columns}
\label{tab:wide}
\end{table*}latex
\begin{table*}[htbp]
\centering
\begin{tabular}{lcccc}
\toprule
Method & A & B & C & D \\
\midrule
Baseline & 85.2 & 86.1 & 87.3 & 88.0 \\
Ours & \textbf{92.1} & \textbf{91.5} & \textbf{93.2} & \textbf{94.1} \\
\bottomrule
\end{tabular}
\caption{横跨两栏的宽表}
\label{tab:wide}
\end{table*}Common Float Issues and Solutions
常见浮动元素问题及解决方案
Issue: Figure drifts to end of document
问题:图漂移到文档末尾
Cause: Using alone or figure is too large
[h]Solution:
latex
% Before (problematic)
\begin{figure}[h]
% After (recommended)
\begin{figure}[htbp]
% Or force placement
\begin{figure}[!htbp]原因:单独使用或图尺寸过大
[h]解决方案:
latex
% 之前的写法(有问题)
\begin{figure}[h]
% 修改后的写法(推荐)
\begin{figure}[htbp]
% 或者强制放置
\begin{figure}[!htbp]Issue: Figure takes entire page alone
问题:图单独占满一页
Cause: triggers float page, or figure is large
[p]Solution:
latex
% Add stretch to push other content
\begin{figure}[htbp]
\centering
\includegraphics[width=0.7\textwidth]{figure.pdf}
\caption{Caption}
% Add space to encourage text to flow around
\end{figure}原因:触发了浮动页,或图尺寸过大
[p]解决方案:
latex
% 添加空间以推动其他内容
\begin{figure}[htbp]
\centering
\includegraphics[width=0.7\textwidth]{figure.pdf}
\caption{标题}
% 添加空间,促使文本环绕
\end{figure}Issue: Figure separated from text reference
问题:图与文本引用位置分离
Cause: Float placement rules
Solution:
- Use to force earlier placement
[!htbp] - Place figure closer to its reference in source
- Use from
\FloatBarrierpackage:placeins
latex
\usepackage{placeins}
\section{My Section}
Text reference to \figurename~\ref{fig:myfig}.
\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{figure.pdf}
\caption{My figure}
\label{fig:myfig}
\end{figure}
\FloatBarrier % Prevents floats from crossing this barrier原因:浮动元素放置规则限制
解决方案:
- 使用强制提前放置
[!htbp] - 在源码中将图放在靠近引用的位置
- 使用包中的
placeins:\FloatBarrier
latex
\usepackage{placeins}
\section{我的章节}
文本引用\figurename~\ref{fig:myfig}。
\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{figure.pdf}
\caption{我的图}
\label{fig:myfig}
\end{figure}
\FloatBarrier % 防止浮动元素跨越此屏障Issue: Subfigures not aligned
问题:子图未对齐
Cause: Different heights, missing alignment option
Solution:
latex
% Use [t], [b], or [c] for vertical alignment
\begin{subfigure}[t]{0.45\textwidth} % [t] = top alignment
\begin{subfigure}[b]{0.45\textwidth} % [b] = bottom alignment原因:高度不同或缺少对齐选项
解决方案:
latex
% 使用[t]、[b]或[c]进行垂直对齐
\begin{subfigure}[t]{0.45\textwidth} % [t] = 顶部对齐
\begin{subfigure}[b]{0.45\textwidth} % [b] = 底部对齐Issue: Captions not centered under subfigures
问题:子图标题未居中
Cause: Missing width specification
Solution:
latex
\begin{subfigure}[t]{0.45\textwidth}
\centering
\includegraphics[width=\filename]{fig.pdf}
\caption{Caption text}
\end{subfigure}原因:缺少宽度指定
解决方案:
latex
\begin{subfigure}[t]{0.45\textwidth}
\centering
\includegraphics[width=\filename]{fig.pdf}
\caption{标题文本}
\end{subfigure}Best Practices
最佳实践
- Use by default - gives LaTeX flexibility while respecting order
[htbp] - Use for important figures - overrides some float constraints
[!htbp] - Place floats near their reference - in source order, not necessarily final position
- Use for tables - professional look, but this skill doesn't handle formatting
booktabs - Use package - modern replacement for
subcaptionsubfig - Consider - for strict float control in sensitive locations
\FloatBarrier
- 默认使用- 给LaTeX灵活性的同时遵循指定顺序
[htbp] - 重要图表使用- 覆盖部分浮动元素约束
[!htbp] - 将浮动元素放在引用附近 - 按源码顺序放置,而非最终显示位置
- 表格使用- 获得专业外观,但本技能不处理格式
booktabs - 使用包 -
subcaption的现代替代方案subfig - 考虑使用- 在敏感位置严格控制浮动元素
\FloatBarrier
Required Packages
所需包
The following packages are referenced in the examples above:
latex
\usepackage{subcaption} % For subfigure/subtable
\usepackage{booktabs} % For professional tables (not positioning)
\usepackage{placeins} % For \FloatBarrier以下包在上述示例中被引用:
latex
\usepackage{subcaption} % 用于子图/子表
\usepackage{booktabs} % 用于专业表格(非定位相关)
\usepackage{placeins} % 用于\FloatBarrierExample Tasks
示例任务
| Request | Approach |
|---|---|
| "Figure 1 always goes to next page" | Change |
| "Arrange 4 figures in 2x2 grid" | Use subfigure with line break |
| "Put figure and table side by side" | Use minipage or subcaptionbox |
| "Figure 2 is far from Section 2.2" | Use |
| "Wide table spans both columns" | Use |
| 请求 | 解决方法 |
|---|---|
| "图1总是跳到下一页" | 将 |
| "将4张图排列成2x2网格" | 使用子图并添加换行符 |
| "将图和表并排放置" | 使用minipage或subcaptionbox |
| "图2与2.2节相距甚远" | 使用 |
| "宽表横跨两栏" | 使用 |