我使用以下 MWE,它会产生一个由 4 个方块组成的堆栈,其中最上面的一个方块标有“0”标签。我想要的是将标签“1”、“2”和“3”添加到最上面的方块后面的相应方块上。
\documentclass{report}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{shadows}
\begin{document}
\begin{tikzpicture}
\node[
minimum width = 3cm,
minimum height = 3cm,
draw, fill = white,
copy shadow = {shadow xshift = 3ex, shadow yshift = -3ex},
copy shadow = {shadow xshift = 2ex, shadow yshift = -2ex},
copy shadow = {shadow xshift = 1ex, shadow yshift = -1ex}
] (Block) {};
\node[inner sep = 2pt, below left] at (Block.north east) {0};
\end{tikzpicture}
\end{document}
答案1
我会在这里使用循环和标签,这样您就不必手动放置它们。
代码
\documentclass[tikz,convert=false,border=40pt]{standalone}
\usetikzlibrary{shadows}
\tikzset{
copy shadow label/.style={
at={(\myCopyshadownode.north east)},
anchor=north east,
inner sep=+2pt},
labeled copy shadow xshift/.initial=1em,
labeled copy shadow yshift/.initial=-1em,
labeled copy shadow/.style={
append after command={
\pgfextra{\let\myCopyshadownode\tikzlastnode}
node[copy shadow label/.try] {0}
},
@labeled copy shadow/.list={#1,...,1}},
@labeled copy shadow/.style={
copy shadow={
shadow xshift={#1*\pgfkeysvalueof{/tikz/labeled copy shadow xshift}},
shadow yshift={#1*\pgfkeysvalueof{/tikz/labeled copy shadow yshift}}},
append after command={
node[copy shadow label/.try,
xshift=#1*\pgfkeysvalueof{/tikz/labeled copy shadow xshift},
yshift=#1*\pgfkeysvalueof{/tikz/labeled copy shadow yshift}] {#1}
}
}
}
\begin{document}
\begin{tikzpicture}
\node [
minimum size=+3cm, draw, fill=white,
labeled copy shadow=3] {};
\end{tikzpicture}
\end{document}
输出
答案2
在 tikz 之外,它们可以以嵌套方式堆叠。您可以设置水平和垂直移位。
\documentclass{report}
\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{stackengine}
\begin{document}
\def\mypic#1{%
\begin{tikzpicture}
\node[
minimum width = 3cm,
minimum height = 3cm,
draw, fill = white,
] (Block) {};
\node[inner sep = 2pt, below left] at (Block.north east) {#1};
\end{tikzpicture}
\unskip}
\def\hgap{\hspace{1em}} % YOU CAN ALTER THIS HORIZONTAL SHIFT
\setstackgap{L}{2ex} % YOU CAN ALTER THIS VERTICAL SHIFT
\def\stackalignment{l}
\def\stacktype{L}
\stackon{\hgap\hgap\hgap\mypic{4}%
}{%
\stackon{\hgap\hgap\mypic{3}%
}{%
\stackon{\hgap\mypic{2}%
}{%
\mypic{1}%
}%
}%
}%
\end{document}
如果将垂直堆栈间隙设置为负数,则结果(毫不奇怪)将呈现不同的形式: