多个重叠矩形作为 TikZ 节点

多个重叠矩形作为 TikZ 节点

我正在尝试创建一个 TikZ 流程图,其中需要区分串行和并行流。以下是串行到并行的示例:

serial to parallel nodes

我设法创建了多个矩形堆栈,但很难将文本居中,也无法将其合并为节点形状。我总是可以手动绘制所有内容,但我想知道是否有更简单的方法来实现这一点?特别是,有没有办法创建一个 TikZ 样式,其中包含多个可轻松合并到节点中的重叠矩形?

这是我的代码,它重新创建了底部矩形,文本居中不正确:

\newcommand{\pstack}[3]{
\draw[fill=white, minimum height=4em] #1 rectangle #2;
\draw[fill=white, minimum height=4em] #1 ++(-0.05,0.05) ++(-0.05,0.05) rectangle +#2;
\draw[fill=white, minimum height=4em, thick] #1 ++(-0.1,0.1) ++(-0.1,0.1) rectangle +#2;
\path #1 -- +#2 node[pos=0.75] {#3};
}
\begin{tikzpicture}[node distance = 2cm, auto]%[scale=.8, z={(-.707,-.3)}]
    \pstack{(0,0)}{(2,1)}{some text};
\end{tikzpicture}

答案1

您可以double copy shadowshadowstikz 库中使用。

一个例子:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shadows,positioning,calc}
\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},
         ordinary/.style = {rectangle,draw,thick,minimum height = 1cm,minimum width=2cm}}
\begin{document}

\begin{tikzpicture}
   \node [ordinary] at (0,0) (a) {Some};
   \node [multiple,below=3cm of a] (b) {Text};
   \draw[-latex] (a) -- coordinate (ab) (b);
   \draw (ab) -- ++(0.7,-0.5)coordinate[pos=.3](ab1) coordinate[pos=.6](ab2);
   \draw[-latex] (ab1) -- ($(b.north west)!(ab1)!(b.north east)$);
   \draw[-latex] (ab2) -- ($(b.north west)!(ab2)!(b.north east)$);
\end{tikzpicture}
\end{document}

enter image description here

相关内容