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}
(-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.
(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.