2

Is there a safe and sound way to let the insides of a float environment know on which column the float is placed?

Here is an examples that fails:

\documentclass[twocolumn]{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{float}
\usepackage{xparse}

\makeatletter
\NewDocumentCommand{\blindfigure}{O{}}{
\begin{figure}[#1]
\includegraphics[width=\linewidth,height=.35\linewidth]{example-image-a}
\caption{\if@firstcolumn I'm on the left\else I'm on the right\fi}
\end{figure}
}
\makeatother

\begin{document}
\blindtext
\blindfigure[H]
\blindtext
\blindfigure[H]
\blindtext
\blindfigure[H]
\end{document}

The second float is reflowed to the second column so it gets tricked:

floats and stuff

I'd love to have a solution that works with all float targets (hHtbp!).

  • 1
    I think, querying the column occurs too late in the \caption command. –  Apr 23 '16 at 14:57
  • 1
    The caption is typeset at the moment the figure environment is processed, not when it is placed. – egreg Apr 23 '16 at 15:24
  • @egreg Yes, I figured that out; btw, I don't really care about the caption, I just used it to display the problem. I any case the whole content of figure is processed before the placement, so theoretically I have no access to placement information from the inside. One way could be hijacking the float mechanism and rewiring it into process+fake placement+reprocess w/placement data+placement. That really sounds daunting, though. I was hoping for some clever trick. – Paolo Brasolin Apr 23 '16 at 15:31
  • @egreg: Isn't the whole twocolumn algorithm a box-shifting, i.e. the box with the figure is typeset and nothing can be changed afterwards? –  Apr 23 '16 at 15:41
  • @ChristianHupfer Yes: TeX must know the size of the float in order to be able to place it. – egreg Apr 23 '16 at 16:27
  • @egreg: Then there's no solution to this? –  Apr 23 '16 at 16:42

0 Answers0