I always put my float environments at the end of the paragraph where it was first referenced.
But I have a problem when the paragraph is split over two pages (beginning at the bottom of the first page and ending at the top of the second page). The float could be placed easily at the top of the first page, because it is referenced directly in the first sentence of the paragraph which is on the first page even if the float is on this page too. But Latex puts the float on the second page resulting in a half empty first page (because of the now missing float) and a half empty second page (because the float is now the only thing on this page).
Is there an easier way than manually move the float environment in the source before the paragraph (with all the problems when the above mentioned condition no longer holds, e.g. when additional text is inserted)?
MWE (with the float on the second page)
\documentclass{article}
\usepackage{algorithm2e}
\usepackage[nopar]{lipsum}
\begin{document}
\null
\vfill
\lipsum[1-3]
In the first sentence I reference the float~\ref{alg:Algo}. After the first sentence there are many more sentences and the float ist put after the whole paragraph. After the first sentence there are many more sentences and the float ist put after the whole paragraph. After the first sentence there are many more sentences and the float ist put after the whole paragraph. After the first sentence there are many more sentences and the float ist put after the whole paragraph. After the first sentence there are many more sentences and the float ist put after the whole paragraph.
\begin{algorithm}[tbp]
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\LinesNumbered
\caption{Caption}
\label{alg:Algo}
\Input{-}
\Output{-}
\BlankLine
First Line\;
First Line\;
First Line\;
First Line\;
First Line\;
\Return{result}\;
\end{algorithm}
\end{document}
MWE (with the float on the first page)
\documentclass{article}
\usepackage{algorithm2e}
\usepackage[nopar]{lipsum}
\begin{document}
\null
\vfill
\lipsum[1-3]
\begin{algorithm}[tbp]
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\LinesNumbered
\caption{Caption}
\label{alg:Algo}
\Input{-}
\Output{-}
\BlankLine
First Line\;
First Line\;
First Line\;
First Line\;
First Line\;
\Return{result}\;
\end{algorithm}
In the first sentence I reference the float~\ref{alg:Algo}. After the first sentence there are many more sentences and the float ist put after the whole paragraph. After the first sentence there are many more sentences and the float ist put after the whole paragraph. After the first sentence there are many more sentences and the float ist put after the whole paragraph. After the first sentence there are many more sentences and the float ist put after the whole paragraph. After the first sentence there are many more sentences and the float ist put after the whole paragraph.
\end{document}
[H]? – David Carlisle Aug 20 '14 at 12:58blah blah \ref{foo}\begin{figure}....\label{foo}\end{figure} blah blah ....– David Carlisle Aug 20 '14 at 12:59Hnot to suggest you use it, but that was my best guess as to the cause of the problem you describe but that guess was false... – David Carlisle Aug 20 '14 at 14:19\ref. – David Carlisle Aug 20 '14 at 15:25