The placeins package

Provides \FloatBarrier, a point that no figure or table can float past, and an option that puts such a barrier before every \section.

Loading the package

\usepackage{placeins}

LaTeX may place a float pages after the text that mentions it, including in the next section. \FloatBarrier forces all floats that are still waiting to be printed before the text continues. If none is waiting, the command does nothing; unlike \clearpage it does not start a new page on its own.

\usepackage[section]{placeins} builds the barrier into \section, so every figure stays in the section in which it is defined. The figures still float inside their section, which is the difference to [H] from float.

Main commands

\FloatBarrierFloats defined before this point are printed before it.
\usepackage[section]{placeins}Barrier before every \section.
\usepackage[section,above]{placeins}Allows a float at the top of the page on which its section starts, above the heading.
\usepackage[section,below]{placeins}Allows a float at the bottom of the page, below the heading of the next section.

Complete example

\documentclass{article}
\usepackage{graphicx}
\usepackage{placeins}
\begin{document}
\section{Results}
The figure shows the first series of measurements.
\begin{figure}[tp]
  \centering
  \includegraphics[width=0.5\textwidth]{image.png}
  \caption{Result of the first series}
\end{figure}

\FloatBarrier
\section{Discussion}
This section starts after the figure, never before it.
\end{document}
Result
The compiled example

Compiled with pdfLaTeX from TeX Live 2023.

Pitfalls

Related pages