Floats – How to Place an Image Inside Another Image in LaTeX

floatspositioning

I currently have some LaTeX code to have multiple images side by side:

\begin{figure*}
\begin{center}
\includegraphics[height=2cm]{foo11.jpg}
\includegraphics[height=2cm]{foo12.jpg}\\
\includegraphics[height=2cm]{foo21.jpg}
\includegraphics[height=2cm]{foo22.jpg}
\end{center}
\caption{my caption.}
\end{figure*}

I would now like to add a small inset, inside for example foo12.jpg and foo22.jpg. For example, having the image bar12.jpg as a small thumbnail in the top-right corner of foo12.jpg and having the image bar22.jpg as a small thumbnail in the top-right corner of foo22.jpg.

Of course, my goal is not to do that using Photoshop (or any external tool/script) but to do it directly in LaTeX. I guess this should be doable (since with Acrobat we can place images wherever we want in a PDF, and since LaTeX figures are "floating"), but have no idea how and I can't find any resource to help.

Best Answer

If you know the dimensions of the images, then you can easily do this with a raised overlap.

enter image description here

\documentclass{article}
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\begin{document}
\begin{figure}
  \centering
  \setbox1=\hbox{\includegraphics[height=2cm]{example-image-b}}
  \includegraphics[height=2cm]{example-image-a}\llap{\includegraphics[height=1cm]{example-image-c}}
  \includegraphics[height=2cm]{example-image-a}\llap{\raisebox{1cm}{\includegraphics[height=1cm]{example-image-c}}} \\
  \includegraphics[height=2cm]{example-image-b}\llap{\makebox[\wd1][l]{\includegraphics[height=1cm]{example-image-c}}}
  \includegraphics[height=2cm]{example-image-b}\llap{\makebox[\wd1][l]{\raisebox{1cm}{\includegraphics[height=1cm]{example-image-c}}}}
  \caption{My caption.}
\end{figure}
\end{document}

I've used the example images from the mwe package, and knowing that the heights will be 1cm, raising by 1cm will fill the 2cm of the original image. However, if you don't know the heights, one can always box the contents and extract the height, as I did with \setbox1=\hbox{...} and using \wd1 (width of box 1). There might be better ways of doing this.

Related Question