Your figure does not appear where you wrote it; a table jumps several pages ahead. This is not a LaTeX bug — it is because figure and table are floats (floating objects). LaTeX detaches them from the run of text and lets them "float" to wherever the page layout comes out best. This page works through how much you can steer that: the placement specifiers in [htbp], the \FloatBarrier and \clearpage commands that dam the flow, the ways to set two figures side by side, and the wrapfig package for wrapping text around a figure.
What a float is
A figure or table that straddles a page break looks wrong — you cannot show half of it here and the rest overleaf. So LaTeX treats each one as a single box and, once a stretch of text has been set, chooses a place for it automatically: the top or bottom of a page, or a page given over to floats. That is a float. The two standard float environments are figure and table, one for each.
Floats have an upside and a puzzling side. The upside: a figure never splits across a page, and its numbering ("Figure 1," "Table 2") and cross-references via \caption, \label, and \ref all line up for free. The puzzling side: where you wrote it and where it prints diverge. The design rests on the idea that because you can write "see Figure 1" with \ref{fig:foo}, the figure itself need not sit right next to that sentence. So the rule is refer by number, not by position. Building images and multi-file projects belong on other pages; here we focus only on where a float lands.
The `[htbp]` placement specifiers
The figure and table environments take an optional argument called the placement specifier: square brackets, as in \begin{figure}[htbp], that tell LaTeX which positions it may use. You combine the following letters.
| Specifier | Means | Notes |
|---|---|---|
h | here | Near the current spot in the text. h alone is not allowed; LaTeX adds t automatically |
t | top | At the top of a text page |
b | bottom | At the bottom of a text page |
p | page | A separate float page — only floats, no text |
! | override | For this float only, ignore the limits on number and on the float/text ratio |
H | truly here (no floating) | Added by the float package; pins it in place, no floating |
Omit the specifier and classes such as article and book use the default **tbp** (note: no h). List several letters and LaTeX looks for any of those positions it can use. Two important traps. First, **h on its own is mostly ignored**: LaTeX does not permit bare h and quietly adds t, so [h] often jumps to the top anyway. When you truly need "right here," use [H] from the float package, described below.
Second, the order of the letters does not change the order in which LaTeX tries them. Whether you write [bt] or [tb], LaTeX tries its candidates in the same sequence (roughly here → top → bottom → float page). Think of the letters as the *set* of allowed positions, nothing more. LaTeX also processes floats in the order they appear in the source, so a later figure can overtake an earlier one. In practice, then, do not over-constrain: the wider you allow — [tbp] or [htbp] — the more readily LaTeX places the float nearby. Narrow it to a single letter (especially [h]) and it tends to drift further away.
\begin{figure}[htbp]
\centering
\includegraphics[width=0.6\textwidth]{plot}
\caption{実験結果}
\label{fig:result}
\end{figure}
図~\ref{fig:result} に結果を示す。Here [htbp] permits any of the current spot, top, bottom, or a float page, and LaTeX picks the best. \centering to center the image, \caption for a heading and number, and \label for referencing are the usual contents of a float. The body refers to it by number with 図~\ref{fig:result}, so the prose holds together even if the figure prints some distance away (the ~ is a non-breaking space that keeps the word and number from splitting across a line end).
Forcing it here — `[H]`
When you really must keep a float "exactly where I wrote it," load the float package in the preamble and use the capital **[H]**. [H] is not an ordinary placement letter: it switches off floating altogether and pins the figure or table in place. It behaves much like dropping a large box right there.
\usepackage{float}
% ...
\begin{figure}[H]
\centering
\includegraphics[width=0.6\textwidth]{diagram}
\caption{処理の流れ}
\end{figure}Treat [H] as a last resort, though. Pinning a float can leave a large gap when it will not fit at the foot of a page, or push the float to the top of the next page and empty the bottom of this one. Trusting LaTeX with a generous [htbp] usually yields a tidier result. [H] earns its keep only for small figures that genuinely must sit at one exact point in the text, such as a step-by-step diagram. You can make [H] the document-wide default with \floatplacement{figure}{H}, but for the reasons above that is not recommended.
Damming the flow — `\FloatBarrier` and `\clearpage`
The most vexing float problem is a figure that will not fit in its section and drifts into the next one (or the next chapter). When Figure 3 of Section 2 surfaces partway through Section 3, the reader is lost. To stop it, you set a barrier that floats may not cross.
That barrier is \FloatBarrier, from the placeins package. Where you place this command, all floats still pending are emitted before it, and later floats cannot cross it. To fence floats off by section, write \FloatBarrier before each \section, or load \usepackage[section]{placeins}, which inserts a barrier at the start of every \section for you.
\usepackage{placeins}
% ...
\section{実験}
% ... 図や表 ...
\FloatBarrier % ここより先へフロートを越えさせない
\section{考察}A close cousin is **\clearpage**, and the difference is the page break. \clearpage emits all pending floats and then starts a new page, whereas \FloatBarrier emits the floats but does not break the page. So reach for \FloatBarrier to dam floats within the same page, and \clearpage when a full page break (say at a chapter end) is fine. The [section] barrier is strict by default — it forbids a float from spilling even slightly outside its section — but the [above] and [below] options relax that.
Going a step deeper, LaTeX’s automatic placement obeys a set of float-placement parameters — internal numbers, expressed as fractions, that decide how much of a page floats may occupy. They are a last-ditch adjustment when nothing else works (though usually revisiting [htbp] should come first).
| Parameter | Default | Means |
|---|---|---|
\topfraction | 0.7 | Max fraction of a page top that floats may fill |
\bottomfraction | 0.3 | Max fraction of a page bottom that floats may fill |
\textfraction | 0.2 | Min fraction of a text page that must be text |
\floatpagefraction | 0.5 | Min fill before a separate float page is made |
topnumber | 2 | Max floats at the top of a page |
bottomnumber | 1 | Max floats at the bottom of a page |
totalnumber | 3 | Max floats on a single page |
Change the fractions with \renewcommand{\topfraction}{0.85} and the integer counters with \setcounter{totalnumber}{5}. Raising \topfraction and lowering \textfraction, for instance, lets more floats sit at a page top and reduces the "won’t fit, push to next page" evictions. The ! specifier from earlier is, in effect, the local version of this tuning: it tells LaTeX to ignore these limits for one float only.
Setting two side by side
You often want two figures (or tables) next to each other. Since a float can hold any content, the basic idea is to **put two side-by-side boxes inside a single figure.** The bare-LaTeX way is minipage; to give the sub-figures their own labels — (a), (b) — use the subcaption package.
A minipage is an environment that makes a "little page" of a width you choose. Place two of them side by side with \hfill (a stretchable horizontal space) between, and they spread to the left and right. The trick is to make each a little under half the text width — say 0.48\textwidth — so their total stays just below the full width.
\begin{figure}[htbp]
\centering
\begin{minipage}{0.48\textwidth}
\centering
\includegraphics[width=\linewidth]{left}
\caption{左の図}
\label{fig:left}
\end{minipage}
\hfill
\begin{minipage}{0.48\textwidth}
\centering
\includegraphics[width=\linewidth]{right}
\caption{右の図}
\label{fig:right}
\end{minipage}
\end{figure}Here two minipages of width 0.48\textwidth sit inside the figure, and the \hfill between them pushes the slack outward so they hug the margins. Inside each minipage, \linewidth refers to that minipage’s width, so \includegraphics[width=\linewidth] fills the box. Because each minipage has its own \caption, they get separate numbers — "Figure 1," "Figure 2." To treat the pair as one figure instead, put a single \caption directly under the figure.
To number the two as sub-figures of one figure — "Figure 2(a)," "Figure 2(b)" — use the subfigure environment from the subcaption package (written much like minipage, with \subcaption or \caption inside producing the (a)/(b) labels). Sub-figures and captions are covered in detail on the separate "Captions & subfigures" page. Two tables side by side follow the same idea: put a tabular inside each minipage.
Wrapping text around a figure — `wrapfig`
To let body text wrap around the side of a small figure — the magazine-style layout — use the wrapfigure environment (or wraptable for tables) from the wrapfig package. The syntax is:
\usepackage{wrapfig}
% ...
\begin{wrapfigure}[12]{r}[34pt]{0.4\textwidth}
\centering
\includegraphics[width=0.38\textwidth]{portrait}
\caption{人物像}
\end{wrapfigure}It takes four arguments, two of them required. {r} is the placement (which side), and the final {0.4\textwidth} is the figure’s width. The optional [12] is the number of lines to wrap, and the optional [34pt] is the overhang — how far the figure pokes into the margin. The placement letters come in pairs: lowercase pins it in place, uppercase lets it float.
| Letter | Side | Notes |
|---|---|---|
r / R | right | r = here, R = may float |
l / L | left | l = here, L = may float |
i / I | inner | Toward the binding; for twoside documents |
o / O | outer | Away from the binding; for twoside documents |
In the example, a figure 0.4\textwidth wide sits on the right of the text and the next 12 lines wrap around its left; the [34pt] lets it jut into the right margin. Omit the line count [12] and wrapfig estimates it from the figure’s height (give it explicitly when the estimate goes wrong and the wrap looks ragged). For two-sided printing where you want the figure away from the binding, use o (outer) and it alternates sides between left and right pages automatically.
For all its usefulness, wrapfig is temperamental, so keep its caveats in mind. The manual cautions, in essence:
- Do not use it inside, or immediately before or after, a list. Keep it out of
itemize,enumerate,description, and the like. - Do not let it straddle a page break. Place the environment so the wrap does not split across pages; avoid the neighborhood of a page boundary.
- Do not wrap headings or large equations around it. For looks, only plain text should wrap; section titles and displayed equations come out badly.
- Start it at a paragraph boundary rather than mid-paragraph for steadier results. And inside a
minipageorparbox, make sure the wrapping ends before the group does.
When the wrap misbehaves, narrowing the figure slightly, stating the line count, or nudging the start by one paragraph usually fixes it. If it still will not settle, dropping wrapfig for a plain float ([htbp] above or below the text) can read better in the end.