0

The following code works absolutely fine:

\documentclass[varwidth=\maxdimen]{standalone}
\usepackage{overpic}

\begin{document}

\begin{figure} \fbox{\begin{overpic}[unit=30mm]{example-grid-100x100bp.jpg} \end{overpic}}% \fbox{\begin{overpic}{example-grid-100x100bp.jpg} \end{overpic}} \end{figure} \end{document}

and gives the following image:

enter image description here

However, when I simply change \usepackage{overpic} to \usepackage[abs]{overpic}, or \begin{overpic}[scale=0.02, unit=30mm]{example-grid-100x100bp.jpg} to \begin{overpic}[abs, scale=0.02, unit=10mm]{example-grid-100x100bp.jpg}, I get:

enter image description here

So basically the second image is now overlapping on the first. I would have expected the 2 images to simply be side to side, instead of overlapping as in the second image. I would have expected that setting unit to some value should not change the position of the plot, but it does. Is this a bug, or am I misunderstanding something?

My main use case of \overpic is that it allows to put text on the graphics, for example like this:

\begin{figure}
    \fbox{\begin{overpic}[abs, unit=30mm]{example-grid-100x100bp.jpg}
    \put(0.5, 0.5){hello}
    \end{overpic}}%
    \fbox{\begin{overpic}{example-grid-100x100bp.jpg}
    \end{overpic}}
\end{figure}

which gives me:

enter image description here

EDIT: as suggested in comments, I added a \fbox around the \overpic to show that overpic seems to think that the figure is now smaller.

Seems to be related to this question:overpic overlap box frame

(image from here:http://mirrors.ctan.org/macros/latex/contrib/mwe/example-grid-100x100bp.jpg)

Chachni
  • 183
  • Please use an image that others have access to, for example one of the images listed in https://ctan.org/tex-archive/macros/latex/contrib/mwe – daleif Apr 13 '23 at 14:03
  • Perhaps you should also explain exactly what outcome you are expecting. – daleif Apr 13 '23 at 14:07
  • 1
    Thanks, I updated the post as you suggested. Hope it is clearer now. – Chachni Apr 13 '23 at 14:14
  • If you use \fbox{\begin{overpic}....\end{overpic}} you can see that the size of the first image (under abs) if smaller than the actual image and this it appears to be overlapping – daleif Apr 13 '23 at 14:31
  • Thanks for the suggestion. So by setting [abs, unit=30mm] (which should just set the unit and the positional option), makes overpic believe that the image is now smaller than what is actually is? That doesn't sound right – Chachni Apr 13 '23 at 14:35
  • overpic uses counters to set the picture size and this are integers. With a large unitlength (10mm or 30mm in your examples) you get a quite drastic rounding errors. Imho overpic could avoid that as a current picture environment allows the use of dimensions. – Ulrike Fischer Apr 13 '23 at 15:52

1 Answers1

0

One option is to NOT put abs anywhere and specify the units directly inside the \put command:

\begin{figure}
    \fbox{\begin{overpic}{example-grid-100x100bp.jpg}
    \put(15mm, 15mm){hello}
    \end{overpic}}%
    \fbox{\begin{overpic}{example-grid-100x100bp.jpg}
    \end{overpic}}
\end{figure}

which then gives the wanted result:

enter image description here

Chachni
  • 183