How to put a PDF figure on top of another one

Typesetting material over each other is relatively easy without any extra packages by exploiting the \llap and \rlap TeX commands. These basically typeset some material from the current position to the left, respectively right, regardless what and without changing the current position.

As graphics included by \includegraphics are aligned at the bottom, one additionally can use \raisebox to lift the second graphics in y direction:

\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}

\begin{document}
  \lipsum[3]
  \begin{figure}
    \centering
    \includegraphics[height=6cm]{example-image-a}%
    \llap{\raisebox{3cm}{%  move next graphics to top right corner
      \includegraphics[height=3cm]{example-image-b}%
    }}
    \caption{My overlay figure.}
  \end{figure}  

  \lipsum[3]

\end{document}

enter image description here

If one does not want to scale the first figure to a specific height, but to something like \columnwidth, it is also possible to measure the resulting height. There are many ways to do this (which basically all results in: "box it" + "measure it") In the following, I simply use the functionality provided by the calc package:

\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{calc}       % for height measuring

\begin{document}
  \lipsum[3]
  \begin{figure}
    \centering
    % first measure it's height (store in \dimen0), then actually include the graphics
    \settototalheight{\dimen0}{\includegraphics[width=\columnwidth]{example-image-a}}%
    \includegraphics[width=\columnwidth]{example-image-a}%
    \llap{\raisebox{\dimen0-3cm}{%  move next graphics to top right corner
      \includegraphics[height=3cm]{example-image-b}%
    }}
    \caption{My overlay figure.}
  \end{figure}  

  \lipsum[3]

\end{document}

enter image description here


It is a generic solution. With a trivial edit you will get what you want. Please TeXing it with either xelatex or latex-dvips-ps2pdf.

enter image description here

\documentclass{article}
\usepackage{graphicx}
\usepackage{pstricks}

\newbox\IBox
\savebox\IBox{\includegraphics[scale=0.8]{god}}

\def\Rows{5}
\def\Columns{5}

\psset
{
    xunit=\dimexpr\wd\IBox/\Columns\relax,
    yunit=\dimexpr\ht\IBox/\Rows\relax,
}

\usepackage{lipsum}
\begin{document}
\lipsum[1-3]
\begin{figure}
\begin{pspicture}[showgrid=top](\dimexpr\wd\IBox+3\psxunit\relax,\ht\IBox)
    \rput[bl](0,0){\usebox\IBox}
    \rput[tr](8,5){\includegraphics[scale=0.5]{example-image-b}}
\end{pspicture}
\caption{The Gods must be crazy.}%
\label{fig:}%
\end{figure}
\lipsum[4-7]
\end{document}

The image is taken from The Gods must be crazy.


Hopefully it is the last edit.

enter image description here

\documentclass{article}
\usepackage{graphicx}
\usepackage{pstricks}

\newbox\IBox
\savebox\IBox{\includegraphics[scale=1]{example-image-a}}

\def\Rows{5}
\def\Columns{5}

\psset
{
    xunit=\dimexpr\wd\IBox/\Columns\relax,
    yunit=\dimexpr\ht\IBox/\Rows\relax,
}

\usepackage{lipsum}
\begin{document}
\lipsum[1-3]
\begin{figure}
\begin{pspicture}[showgrid=top](\wd\IBox,\ht\IBox)
    \rput[bl](0,0){\usebox\IBox}
    \rput[tr](\wd\IBox,\ht\IBox){\includegraphics[scale=0.5]{example-image-b}}
\end{pspicture}
\caption{Is the answer of this question ``No''?}%
\label{fig:}%
\end{figure}
\lipsum[4-7]
\end{document}

Tags:

Pdf

Floats