I desperately search for an answer now, nothing helps. I want a graphic and a tabular appear before another subsection.
I use the placeins package for that, and expanded it to also do it in subsections. but the figure and the table are placed at the end of the document, on different pages.
It's still not working. here is the whole file: https://drive.google.com/file/d/1Is9gyBBw8-fJo6Zag0SnIIaJ5kpWH718/view?usp=sharing
\usepackage{placeins}
\makeatletter
\AtBeginDocument{%
\expandafter\renewcommand\expandafter\subsection\expandafter{%
\expandafter\@fb@secFB\subsection
}%
}
\makeatother
\begin{document}
\subsection{Tables and Figures}
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{frog.jpg}
\caption{\label{fig:frog}This is a figure caption.}
\end{figure}
\FloatBarrier
\begin{table}
\centering
\begin{tabular}{l|r}
Item & Quantity \\\hline
Widgets & 42 \\
Gadgets & 13
\end{tabular}
\caption{\label{tab:widgets}An example table.}
\end{table}
\FloatBarrier
\subsection{Mathematics}
...
\end{document}



example-imageas that is available for tests and fill in the document class and anything else required to reproduce the issue. – David Carlisle Jun 30 '19 at 14:06