Skip to content

How to Fix LaTeX Figure Position — Controlling Image Placement

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix LaTeX Figure Position. We cover key concepts, practical examples, and best practices.

The Problem

Your figure appears in a different location than expected:

\begin{figure}[h]
\includegraphics{diagram.png}
\caption{My Diagram}
\end{figure}

The image shows up on the next page or at the end of the document. LaTeX's float algorithm places figures based on positioning specifiers, not their source location.

Quick Fix

Step 1: Use the right placement specifier

WRONG — using only [h]:

\begin{figure}[h]
\includegraphics{diagram.png}
\caption{My Diagram}
\end{figure}

RIGHT — use [htbp]:

\begin{figure}[htbp]
\includegraphics{diagram.png}
\caption{My Diagram}
\end{figure}

Step 2: Force placement with the float package

\usepackage{float}
...
\begin{figure}[H]
\includegraphics{diagram.png}
\caption{My Diagram}
\end{figure}

Step 3: Use centering and spacing

\usepackage{caption}
\captionsetup[figure]{skip=6pt}

\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{diagram.png}
\caption{My Diagram}
\end{figure}

Step 4: Use the placeins package

\usepackage{placeins}
...
\FloatBarrier
\begin{figure}[htbp]
\includegraphics{diagram.png}
\caption{My Diagram}
\end{figure}

Step 5: Adjust float parameters globally

\renewcommand{\topfraction}{0.9}
\renewcommand{\bottomfraction}{0.8}
\renewcommand{\textfraction}{0.1}
\setcounter{totalnumber}{3}

Prevention

  • Use [htbp] as your default placement specifier.
  • Avoid placing figures right after section headings.
  • Use \centering inside each figure environment.
  • Let LaTeX handle placement unless the position is critical.

Common Mistakes with figure position

  1. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  2. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  3. Using return to exit a function early instead of wrapping a pure value in the monad

These mistakes appear frequently in real-world LATEX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does [h] not work?

The h specifier is a suggestion, not a command. If there is not enough space, LaTeX moves the float. Use the float package with [H] for absolute placement.

How do I place two figures side by side?

Use \begin{minipage} inside a single figure environment with \hfill between them.

What is the difference between [h] and [H]?

[h] means "here, if possible". [H] (from the float package) means "exactly here" — it disables floating entirely.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro