[Tex/LaTex] Absolute positions of text over a tikz image

pdftexpgfplotstikz-pgf

I'm trying to create a composite figure in Latex, by layering two images (pngs) on top of each other with a text label added.

Sadly, this seem surprisingly difficult to achieve in LaTeX.

I tried the overpic package, but found it quite cumbersome: I don't want to have a base image on which to layer the others, since the coordinates are then wrong.

Tikz looks good and I can add images using:

\begin{figure}[hbtp]
\centering
\begin{tikzpicture}
\node at (0,0) {\includegraphics[width=.9\textwidth]{image1}};
\node at (0,0) {\includegraphics{image2}};
%\node at (0,0) {text}; doesn't work
\end{tikzpicture}
\end{figure}

However, the images are then put side by side, rather than overlayed. And I can't see how to add text at given coordinates either. The manual seemed quite confusing too, so if anyone has some recommended examples, or advice, it would be greatly appreciated please.

Thanks

Best Answer

Improved version

To have finer control, you can use Caramdir's answer to Drawing on an image with TikZ. The idea is to place the picture so that the lower left corner is at the origin of the TikZ coordinate system; a helper grid is added (See Jake's answer to the same question) just to easily visualize coordinates during the placement of other elements:

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

\begin{document}

\begin{figure}[hbtp]
\centering
\begin{tikzpicture}
\node[anchor=south west] at (0,0) (image1) {\includegraphics[width=.9\textwidth]{example-image-a}};
\begin{scope}[x={(image1.south east)},y={(image1.north west)}]
% draw a grid
\draw[help lines,xstep=.1,ystep=.1,overlay] (0,0) grid (1,1);
% draw ticks
\foreach \x in {0,1,...,9} { \node [anchor=north,overlay] at (\x/10,0) {0.\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east,overlay] at (0,\y/10) {0.\y}; }
\node at (0.2,0.3) {\includegraphics[width=3cm]{example-image-b}};
\node at (0.6,0.8) {\includegraphics[width=3cm]{example-image-c}};
\node[fill=white] at (0.8,0.4) {some additional test text};
\end{scope}

\end{tikzpicture}
\end{figure}

\end{document}

enter image description here

First version

You can simply use the overlay option:

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

\begin{document}

\begin{figure}[hbtp]
\centering
\begin{tikzpicture}
\node at (0,0) {\includegraphics[width=.9\textwidth]{example-image-a}};
\node[overlay] at (0,0) {\includegraphics[width=3cm]{example-image-b}};
\node[overlay] at (0,0) {some test text};
\end{tikzpicture}
\end{figure}

\end{document}

enter image description here

Or name the first node and use the name to place the other elements:

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

\begin{document}

\begin{figure}[hbtp]
\centering
\begin{tikzpicture}
\node at (0,0) (image1) {\includegraphics[width=.9\textwidth]{example-image-a}};
\node at (image1.center) {\includegraphics[width=3cm]{example-image-b}};
\node at (image1.center) {some test text};
\end{tikzpicture}
\end{figure}

\end{document}
Related Question