latex-figure-table-layout について
LaTeX 文書で図表を配置するためのガイダンススキルです。フロートの位置やレイアウトを扱い、サイズや拡大縮小は対象外です。
主な機能
- 01フロートの配置指定
- 02サブ図・サブ表のレイアウト
- 03図と表の横並び配置
- 04段組みをまたぐフロート
- 05フロート配置の問題解決
活用シーン
- 01図が本文の参照箇所から離れる問題の解消
- 02図を2×2のグリッドに配置
- 03図と表を横並びに配置
- 04表を2段組みの両列に配置
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ dw-dengwei/ skills --skill latex-figure-table-layoutインストール後、Claude Code で/latex-figure-table-layoutを入力して読み込まれたか確認します。
同梱ファイルreferences/float-positioning.mdreferences/subfigure-layout.md
詳細
LaTeX の図表レイアウト
LaTeX 文書で図や表を配置するための専門的なガイダンスです。このスキルでは、フロートの配置、サブ図の配置、横並びのレイアウト、複数段組をまたぐ配置を扱います。
このスキルを使用する場面
次のような場合にこのスキルを使用します:
- 図や表の配置パラメーター(
[h]、[t]、[b]、[p])を調整する - 複数の図や表をサブ図として配置する
- 図同士、または図と表を横並びに配置する
- フロートの配置に関する問題(位置がずれる、ページに単独で表示されるなど)を解決する
- 複数段組をまたぐ図(
figure*、table*)を扱う
注:このスキルではサイズ、段組の幅、拡大縮小は変更しません。配置のみを扱います。
フロートの配置パラメーター
配置指定子
| パラメーター | 意味 | 優先度 |
|---|---|---|
[h] | ここ(正確な位置) | 最高 |
[t] | ページの上部 | 中 |
[b] | ページの下部 | 中 |
[p] | 独立したフロートページ | 最低 |
[!] | LaTeX の既定値を上書き | - |
推奨される順序
\begin{figure}[htbp] % Recommended: try here, then top, bottom, then float page
\end{figure}
強く推奨する設定
\begin{figure}[!htbp] % Force LaTeX to respect your order
\end{figure}
ベストプラクティス:ほとんどの場合は [htbp] または [!htbp] を使用してください。フロートの位置がずれる原因になることがあるため、[h] のみの指定は避けてください。
subcaption を使ったサブ図のレイアウト
基本的なサブ図(2 つを横並びに配置)
\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}
グリッド状に配置するサブ図(2x2)
\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}
サブ表
\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}
図と表の横並び配置
minipage を使用する場合
\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}
subcaptionbox を使用する場合
\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}
複数段組をまたぐ図(twocolumn)
複数段組をまたぐ図
\begin{figure*}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{wide-figure.pdf}
\caption{Wide figure spanning both columns}
\label{fig:wide}
\end{figure*}
複数段組をまたぐ表
\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*}
よくあるフロートの問題と解決策
問題:図が文書の最後に移動する
原因:[h] のみを使用している、または図が大きすぎます。
解決策:
% Before (problematic)
\begin{figure}[h]
% After (recommended)
\begin{figure}[htbp]
% Or force placement
\begin{figure}[!htbp]
問題:図だけでページ全体を占める
原因:[p] によってフロートページが作成される、または図が大きすぎます。
解決策:
% 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}
問題:図が本文中の参照箇所から離れて配置される
原因:フロートの配置規則です。
解決策:
[!htbp]を使用して、より早い位置に配置します- ソース内で図を参照箇所の近くに配置します
placeinsパッケージの\FloatBarrierを使用します:
\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
問題:サブ図の位置が揃わない
原因:高さが異なる、または配置オプションが指定されていません。
解決策:
% 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
問題:サブ図の下にあるキャプションが中央揃えにならない
原因:幅が指定されていません。
解決策:
\begin{subfigure}[t]{0.45\textwidth}
\centering
\includegraphics[width=\filename]{fig.pdf}
\caption{Caption text}
\end{subfigure}
ベストプラクティス
- 既定では
[htbp]を使用する - 順序を保ちながら、LaTeX に柔軟な配置を任せられます - 重要な図には
[!htbp]を使用する - フロートの制約の一部を上書きします - フロートを参照箇所の近くに置く - ソース内の順序で配置します。最終的な表示位置と同じである必要はありません
- 表には
booktabsを使用する - 見栄えがよくなりますが、このスキルでは書式設定を扱いません subcaptionパッケージを使用する -subfigに代わる最新のパッケージです\FloatBarrierの使用を検討する - 配置に注意が必要な場所でフロートを厳密に制御できます
必要なパッケージ
上記の例で参照しているパッケージは次のとおりです:
\usepackage{subcaption} % For subfigure/subtable
\usepackage{booktabs} % For professional tables (not positioning)
\usepackage{placeins} % For \FloatBarrier
タスクの例
| リクエスト | 対応方法 |
|---|---|
| 「図 1 がいつも次のページに移動する」 | [h] を [htbp] または [!htbp] に変更する |
| 「4 つの図を 2x2 のグリッドに配置する」 | 改行 \\ を使ってサブ図を配置する |
| 「図と表を横並びにする」 | minipage または subcaptionbox を使用する |
| 「図 2 がセクション 2.2 から離れている」 | [!htbp] を使用するか、\FloatBarrier を追加する |
| 「幅の広い表を両方の段にまたがって配置する」 | table の代わりに table* を使用する |
コメント
Markdown 対応