3

I am trying to adapt How to superimpose two images in a beamer presentation? to a document type article.

The goal is to have two superimposed images in the document: enter image description here

To this end I modified the code

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}

\begin{figure}

  \begin{center}
    \includegraphics[width=0.8\textwidth]{example-image-a}
  \end{center}

  \begin{tikzpicture}[overlay, remember picture]
    \node at (current page.north east)
          [
            anchor=north east,
            xshift=0mm,
            yshift=0mm
          ]
          {
            \includegraphics[width=0.3\textwidth]{example-image-b}
          };
  \end{tikzpicture}

\end{figure}

\end{document}

There is a difficulty in modifying the wording current page. It should be current "figure", but I don't know how to properly describe it in Latex.

Suggestions?

Viesturs
  • 7,895

3 Answers3

5

TikZ solution:

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}

\begin{figure}
    \begin{tikzpicture}
    \node(a){\includegraphics[width=0.8\textwidth]{example-image-a}};
    \node at (a.north east)
    [
    anchor=center,
    xshift=0mm,
    yshift=0mm
    ]
    {
        \includegraphics[width=0.3\textwidth]{example-image-b}
    };
    \end{tikzpicture}
\end{figure}

\end{document}

enter image description here

d-cmst
  • 23,095
4

Use \stackinset. The following invocation says to inset image B, at a distance -.1\textwidth from the right and -.1\textwidth from the top of image A.

For negative-distance insets (that extend outside the border of the base image) the left-right centering of the base image is not affected.

\documentclass{article}
\usepackage{graphicx}
\usepackage{stackengine}
\begin{document}
\begin{figure}
\centering
\stackinset{r}{-.1\textwidth}{t}{-.1\textwidth}
  {\includegraphics[width=0.3\textwidth]{example-image-b}}
  {\includegraphics[width=0.8\textwidth]{example-image-a}}
\end{figure}
\end{document}

enter image description here

4

To position the second picture relative to the current "figure", just name the first picture picA and put \node at (picA.north east) in the same tikzpicture. @AlexG pointed out the same idea in a comment.

\documentclass{article}
\usepackage{tikz}    
\begin{document}

\begin{figure}    
  \centering
  \begin{tikzpicture}
  \node(picA){\includegraphics[width=0.8\textwidth]{example-image-a}};
  \node at (picA.north east){\includegraphics[width=0.3\textwidth]{example-image-b}};
  \end{tikzpicture}    
\end{figure}

\end{document}

enter image description here

AboAmmar
  • 46,352
  • 4
  • 58
  • 127