我正在尝试在适合节点上使用复制阴影,该阴影包装了其他适合节点:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,shadows,positioning,backgrounds,fit}
\begin{document}
\begin{tikzpicture}
\tikzstyle{node1} = [rectangle, rounded corners, align=center, minimum width=0.6cm, minimum height=0.3cm, text centered, draw=black!20, fill=black!10, font=\small]
\tikzstyle{node2} = [rectangle, rounded corners, align=center, minimum width=0.6cm, minimum height=0.3cm, text centered, draw=black!20, fill=black!10, font=\small]
\tikzstyle{container1} = [inner sep=7pt, draw=black!20, rounded corners, line width=0.6mm]
\tikzstyle{bignode1} = [inner sep=3pt, fill=black!50, draw=black!20, rounded corners]
\tikzstyle{bignode2} = [inner sep=3pt, fill=black!60, draw=black!20, rounded corners]
\tikzstyle{arrow} = [>=stealth', shorten >=1pt, auto, thick, black!80]
\tikzset{multiple/.style = {double copy shadow={shadow xshift=1ex,shadow yshift=-1.5ex,draw=black!30},fill=white,draw=black,thick,minimum height = 1cm,minimum width=2cm}}
\node[node1, label={[name=id1Lbl]Label 1}] (id1) {Text 101};
\node[node1, right=0.4cm of id1] (id2) {Text 101};
\begin{pgfonlayer}{background}
\node[bignode1] [fit={(id1Lbl) (id1) (id2)}] (idbig1) {};
\end{pgfonlayer}
\node[node2, label={[name=id2Lbl]Label 2}, below right=1.5cm and -0.6cm of id1] (id3) {Text 102};
\begin{pgfonlayer}{background}
\node[bignode2] [fit={(id2Lbl) (id3)}] (idbig2) {};
\end{pgfonlayer}
\draw[arrow] (id1.south) -- (idbig2.north);
\draw[arrow] (id2.south) -- (idbig2.north);
\begin{pgfonlayer}{background}
%\node[container1] [fit={(idbig1) (idbig2)}, draw=black!20, rounded corners, label={[name=cont1Lbl]Container1}] (cont1) {};
\node[multiple] [fit={(idbig1) (idbig2)}, draw=black!20, rounded corners, label={[name=cont1Lbl]Container1}] (cont1) {};
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
不过我想保留背景颜色idbig1和idbig2,就像我使用的那样:
\node[container1] [fit={(idbig1) (idbig2)}, draw=black!20, rounded corners, label={[name=cont1Lbl]Container1}] (cont1) {};
简而言之,我想保留这些节点的背景并显示双重复制阴影。使用适合节点包裹其他适合节点可以实现吗?
答案1
像这样?
对于上图,您需要定义更多背景层。为所有其他样式定义通用样式并合并到样式“container1”中也是明智的做法copy shadow
。:
\documentclass[tikz, margin=7mm]{standalone}
\usetikzlibrary{arrows, backgrounds, calc, fit,
positioning, shapes, shadows}
\pgfdeclarelayer{background}% <-- added
\pgfdeclarelayer{back background}% <-- added
\pgfsetlayers{back background,% <-- added
background,%
main}
\begin{document}
\begin{tikzpicture}[
node distance = 15mm and 4mm,% <-- added
% tikzstyle is depreciated, instead them the styles can be
% defined as option of tikzpicture
arrow/.style = {draw=black!80, thick, -stealth', shorten >=1pt, shorten <=1pt},
base/.style = {rectangle, rounded corners, draw=black!20, fill=black!10,
font=\small, align=center},
node1/.style = {base, minimum width=0.6cm, minimum height=0.3cm},
bignode1/.style = {base, fill=black!40},
bignode2/.style = {base, fill=black!60},
container1/.style = {base, line width=0.6mm, fill=white,
double copy shadow={shadow xshift=1ex, shadow yshift=-1.5ex}}
]
\node[node1, label={[name=id1Lbl]Label 1}] (id1) {Text 101};
\node[node1, right=of id1] (id2) {Text 101};
%
\node[node1, label={[name=id2Lbl]Label 2},
below=of $(id1)!0.5!(id2)$] (id3) {Text 102};
%
\begin{pgfonlayer}{background}
\node[bignode1] [fit=(id1Lbl) (id1) (id2)] (idbig1) {};
\node[bignode2] [fit=(id2Lbl) (id3)] (idbig2) {};
\end{pgfonlayer}
%
\draw[arrow] (id1.south) -- (idbig2.north);
\draw[arrow] (id2.south) -- (idbig2.north);
%
\begin{pgfonlayer}{back background}
\node[container1, fit=(idbig1) (idbig2),
label=Container1] {};
\end{pgfonlayer}
\end{tikzpicture}
\end{document}