# How to stack images with Tikz?

I would like to stack several png images as shown below

How can I do this with Tikz?

TikZ has a predefined 3d coordinate system, which is not orthographic, but more than sufficient to stack some objects in the z direction.

\documentclass[tikz,border=3mm]{standalone}
\definecolor{fb}{RGB}{128,158,204}
\definecolor{db}{RGB}{111,141,191}
\begin{document}
\begin{tikzpicture}
\foreach \Z in {0,0.5,1,1.5}
{\draw[fill=fb,draw=db] (-2,-2,\Z) rectangle (2,2,\Z);}
\end{tikzpicture}
\end{document}


For external images it works the same way. (I made them a bit transparent to show that these are really different images, but you can remove the opacity=0.8 key.)

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \X [count=\Z]in {a,b,c,duck}
{\node[opacity=0.8] at (0,0,\Z/2) {\includegraphics[width=4cm,height=3cm]{example-image-\X}};}
\end{tikzpicture}
\end{document}


• @random9 This is in the second part of my answer. – user194703 May 26 at 15:32
• @BambOo It needs to be stressed that there is no pineapple on the pizza. ;-) – user194703 May 26 at 15:59
• @BambOo pineapple on a pizza is a bit like an italic differential d: wrong but some people like it. ;-) – user194703 May 26 at 16:13
• @random9 Yes, TikZ has a unit vector in the z direction, which is (-1/(2*sqrt(2)),-1/(2*sqrt(2))) in screen coordinates. You can verify this by adding \makeatletter \pgfmathsetmacro{\pft}{1cm/(2*sqrt(2))} \typeout{e_z=(\the\pgf@zx,\the\pgf@zy)=(-\pft,-\pft)} \makeatother to the code. That is, if you supply a third component to the coordinate, you will add the component times this unit vector. – user194703 May 26 at 18:38
• @random9 It means that, say, the point (1,1,0) gets mapped to the screen coordinate (1cm,1cm), and the point (1,1,1) will get mapped to ((1-1/(2*sqrt(2)))*1cm, (1-1/(2*sqrt(2)))*1cm), which is shifted to the down left compared to the first point. – user194703 May 26 at 18:53