[Tex/LaTex] Placing the floats in the current page or in the previous page

floats

I would like the floats to appear, if possible in the top (or bottom) of the same page where they are defined, or in the bottom of the previous page otherwise (or wherever it fits as near as possible if it doesn't fit in the previous page).

The problem is that LaTeX sends usually the figure to the top of the next page, instead of placing it in the top or bottom of the current page, in the next example I would prefer that LaTeX placed the figure in the first page, even if the place where it is defined is sent to the second page.

\documentclass{article}
\usepackage[a6paper]{geometry}
\usepackage{lipsum}
\begin{document}
First: \lipsum[1]
\begin{figure}[tb]
\begin{tabular}{l|l}
\hline
a & b \\ c & d \\ e & f \\ g & h \\
\hline
\end{tabular}
\caption{some figure}
\end{figure}
Second: \lipsum[2]
\end{document}

What I am looking for is somewhat for the opposite of the package flafter: make figures appear either in the current page or before. Is there a way to enforce this behaviour?

Best Answer

Floats can not go backwards, once a page is output it has gone from TeX's memory, a float found on the next page can not affect it, in order to move a float to a previous page you need to make sure the environment is seen by TeX in the source file before the page is shipped out. TeX does not hold the whole document in memory, or even read the whole input file, it reads the file line by line and ships out pages as soon as possible.

Related Question