This question led to a new package:
chkfloat
Making small tweaks to my (two-column) document can result in my floats (both single and double columns) moving all over the place. I know that my document is more likely to look good if float F
is on page P
say, than if it is on page P+1
. However, I have a long document and it is tiresome to check every page after each build to see if my floats have moved.
Therefore, I would like LaTeX to raise an error (or at least alert me in some way) if float F(n)
is not on page P(n)
where F(n)
and P(n)
are specified for some subset of my floats (I'd be happy with an answer that can deal with tracking one float to begin with though!). However, it is not possible to put checking code inside the floats themselves, because this code is executed when the floats are "read" rather than when they are "placed".
Even if I can tweak the float parameters so that the floats appear in locations I prefer, this would still be a useful automated test, so the focus of my question is not intended to be about float parameters, unless there are some magic parameters that force LaTeX to put the floats in approximate places that I specify (that is, floating places! --- not just 'here', which I assume is not possible for two column floats anyway).
Clearly, LaTeX does keep track of which floats appear on which page, as the \listoffigures
can show this information. But I am not sure what's the best way of accessing that information myself to do the testing; is there a hook that gets called when a float is placed? Preferably the test would work in one run (note that the list of figures takes two runs to update), but this is not essential.
I've included a single-column MWE with a single float to play with. Changing the \lipsum
range changes where the float gets placed. (If the double column nature makes a big difference, I can try to supply a modified MWE.)
\documentclass{article}
\usepackage[a4paper]{geometry}%don't trust MikTeX's defaults!
\usepackage{lipsum}
\begin{document}
% choose which of the following two lines to use to configure where the float appears.
\lipsum[1-5]% figure appears on page 2 if this line is used
%\lipsum[1-4]% figure appears on page 1 if this line is used
\begin{figure}
\centering
Hello world. I was typeset on page \thepage, but that may not be where I appear!
\rule{4cm}{4cm}
\caption{fig}
\end{figure}
***Figure appeared in the text just above here.***
\lipsum[5-8]
\listoffigures
\end{document}
X
pages (whereX
is arbitrary number, best probablyX=1
). Would that be sufficient to you?X=0
is best, as "float gets moved more thanX
pages" is the same as "float has moved". (Also, I'm not sure if we are talking about "a float" as in a particular floatF
? But I'm sure the general case that just detects that "there exists a float in the document that has moved" could be adapted to focus on a specific float.)\begin{figure}[!h]
then LaTeX gives warnings in the.log
file if it has changed it; in your example, it givesLaTeX Warning:
!h' float specifier changed to!ht'.
You could thengrep
the.log
file accordingly