I'm interested in changing how floats are formatted depending on whether they are placed at the top, bottom, or middle of a page, or on a float page. One package I am aware of that does something like this is tufte-latex, which places hanging captions in the margin below full-width figures if the figures are at the top or middle, but above if the figures are at the bottom. Looking at the code for tufte-latex, though, this is a pretty rudimentary check (as near as I can tell, the caption is placed on top exactly when the only placement specifier is "b"). And when the floats are put on a float page, the hanging captions don't look right.

Ideally, I'd like to be able to tell where a float has actually been placed and do something like

\if \finalfloatplacement t%
  % hang caption in margin below float
\if \finalfloatplacement h%
  % same as 't'; hang caption in margin below float
\if \finalfloatplacement b%
  % hang caption in margin above float
\if \finalfloatplacement p%
  % center caption below float

Presumably this would take a couple of LaTeX runs to iron out the positions.

  • the output routine provides no information about where it is placing a float, so the output routine would need to be hacked to provide that in (some sort of) label structure: hacking the or is a non-trivial operation... (not something i would even recommend; and note that latex 3's output routine is likely to be very different.) – wasteofspace May 16 '12 at 10:36
  • Please see tex.stackexchange.com/questions/56673/… – Yiannis Lazarides Dec 17 '12 at 13:03

You have to dig fairly deep into LaTeX internals for this but it is possible for the figure to be saved four times (set for t b p h float areas respectively) and then the output routine pick the box it needs.

In the version here I have not redefined the whole output routine, so while it does pick the correct box (I hope) various arts of the output routine that test measurements are not redefined. This means that when measuring they will see a box that contains all of the four choices side by side, so it will have height the maximum height. This is probably OK unless the settings are very different. In the example the settings just differ in wording slightly and in colour.

the \floatswitch command that this defines must be the only thing in the float, otherwise things will go wrong.

enter image description here

\def\a{One two three four five six. }
\def\b{Apple, Pear, Banana, Orange. }


\hbox to 3sp{%


\ifdim\wd#1=3sp %
\setbox\z@\vsplit\z@ to \textheight





\def\@wtryfc #1{%



\caption{t floats are red}}
\caption{b floats are blue}}
\caption{p floats are green}}
\caption{h floats are yellow}}
\fbox{NO SWITCH}
\caption{no switch}


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.