[Tex/LaTex] Placing a float at a specified position

floatspositioning

I have a bunch of coordinates generated by a program and the text of the bodies of corresponding figures, e.g.:

\includegraphics{abc.png}
\caption{abc}
\label{fig:abc}

I was wondering if there is some way to place a figure at specified absolute coordinates (say, page 1, x = 245px, y=452px).

I have seen this question, but it doesn't work for figures (which don't go into boxes)

As for why I can't just use non-floats, I'm working with existing documents and don't want to go through everything and manually convert to something different. I was thinking maybe something like this would work:

\documentclass{article}
\usepackage{capt-of}

\newcommand{\fakefigure}[1]{
    \renewcommand{\label}[1]{}
    \renewcommand{\caption}[1]{\captionof{figure}{#1}}
    #1
}

\begin{document}

\fakefigure{
    \includegraphics{abc.png}
    \caption{abc}
    \label{fig:abc}
}
\end{document}

And then I could put that in the box from here. But I'm not sure if there are some other commands I need to trap to make that work.

Best Answer

Here's a way of making the \fakefigure macro suggested in the question work. Well, at least it survives minimal testing in combination with Werner's answer on absolute placement.

The proposed redefinition of \caption won't work because capt-of defines \captionof in terms of \caption. However, it is possible to first save the definition of \caption and then use the saved definition when redefining \caption.

\global\let\oldcaption\caption
\renewcommand\caption{\def\@captype{figure}\oldcaption}% modified from capt-of

I've only allowed for figure type elements here. If you need other kinds of floats to be converted to non-floats, you'd want to reinstitute the optional argument provided by capt-of.

We can then combine this with Mico's suggestion to create the \fakefigure{} macro:

\makeatletter
\global\let\oldcaption\caption
\newcommand{\fakefigure}[1]{%
  \begin{minipage}{\textwidth}
    \renewcommand\caption{\def\@captype{figure}\oldcaption}% modified from capt-of
    #1
  \end{minipage}%
}
\makeatother

This then allows us to write something like

\placetextbox{.35}{,3}{%
  \fakefigure{%
    \includegraphics[height=.2\textheight]{tiger}%
    \caption{abc}%
    \label{fig:abc}%
  }%
}

to place TeX's standard tiger at an arbitrary position on the page.

tiger at arbitrary position

\documentclass{article}
\usepackage{graphicx,kantlipsum,eso-pic}
\makeatletter
\global\let\oldcaption\caption
\newcommand{\fakefigure}[1]{%
  \begin{minipage}{\textwidth}
    \renewcommand\caption{\def\@captype{figure}\oldcaption}% modified from capt-of
    #1
  \end{minipage}%
}
\makeatother
% from Werner's answer at https://tex.stackexchange.com/a/24675/
\newcommand{\placetextbox}[3]{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>}
  \setbox0=\hbox{#3}% box
  \AddToShipoutPictureFG*{% Add <stuff> to current page foreground
    \put(\LenToUnit{#1\paperwidth},\LenToUnit{#2\paperheight}){\vtop{{\null}\makebox[0pt][c]{#3}}}%
  }%
}
\begin{document}
\placetextbox{0.5}{0.5}{\fbox{\Huge\textsf{This is my text.}}}
\placetextbox{0.5}{1}{\Huge\texttt{Here is another piece of text.}}
\placetextbox{0.1}{0.1}{\Large $\mathcal{A}_1$}
\placetextbox{.35}{,3}{%
  \fakefigure{%
    \includegraphics[height=.2\textheight]{tiger}%
    \caption{abc}%
    \label{fig:abc}%
  }%
}
\kant[1-3]
\end{document}