答案1
下面是定义新命令的示例\imagestack
。堆栈是通过在背景层上绘制背景中的帧来创建的。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\pgfdeclarelayer{bg}
% set the order of the layers (main is the standard layer)
\pgfsetlayers{bg,main}
% \imagestack{image_name}{position}{path_to_image}
\newcommand{\imagestack}[3] {
\node[inner sep=0, draw] (#1) at (#2) {\includegraphics[width = 2cm]{#3}};
\coordinate (offset) at (0.05cm, 0.05cm);
% draw on the background layer
\begin{pgfonlayer}{bg}
\foreach \i in {3,...,1}
\filldraw[draw=black, fill=white] ($(#1.south east) + \i*(offset)$) rectangle ($(#1.north west) + \i*(offset)$);
\end{pgfonlayer}
}
\imagestack{image}{{0,0}}{example-image-a}
\end{tikzpicture}
\end{document}
答案2
按照 Ignasi 和 Claudio Fiandrino 的建议,最好的解决方案可能是使用阴影库。请参见以下示例:
\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{shadows}
\begin{document}
\begin{tikzpicture}
\tikzset{imageStack/.style={
draw=black,
double copy shadow={shadow xshift=5ex, shadow yshift=2.5ex},
fill=white,
inner sep=0}}
\node [imageStack] (exampleImageStack) {\includegraphics{example-image-a}};
\end{tikzpicture}
\end{document}
来源:https://mirror.informatik.hs-fulda.de/tex-archive/graphics/pgf/base/doc/pgfmanual.pdf