使用矩阵创建流程图

使用矩阵创建流程图

我正在使用矩阵创建流程图,并且我有一个要连接箭头的内层。我该如何实现以下目标:

在此处输入图片描述

我还试图将标题分离为一个节点(如下图所示),以便矩阵不会随着每个矩阵标题的增加而变厚。代码如下:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds,fit,matrix}

\tikzset{%
  every neuron/.style={
    circle,
    draw,
    minimum size=1cm
  },
  neuron missing/.style={
    draw=none, 
    scale=4,
    text height=0.333cm,
    execute at begin node=\color{black}$\vdots$
  },
}
\begin{document}
\tikzset{
            topology/.style={rounded corners,
                           draw=white!50,
                           fill=white!20,
                           thick,
                           inner sep=3pt},
            neuron/.style={fill=black!10,
                           draw=black,
                           rounded corners,
                           inner sep=15pt},
            synapse/.style={draw=black!50,
                           fill=black,
                           rounded corners,
                           inner sep=5pt},
            empty synapse/.style={draw=none,
                           fill=none,
                           rounded corners,
                           inner sep=5pt}
}
\colorlet{colIP}{white!40}

\pgfdeclarelayer{topology}
\pgfsetlayers{topology,main}
\definecolor{airforceblue}{rgb}{7.36, 0.54, 0.66}
\begin{tikzpicture}[remember picture]

\matrix (N0) [neuron,inner sep=3mm,
                     matrix of nodes,
                     nodes={synapse,draw=black},
                     row sep=1mm,
                     nodes in empty cells,
                     outer sep=2mm]{
|[label={[inner sep=2pt,outer sep=0]90:Avara Ka Davara}]| \textcolor{white}{Synapse$_1$} \\
\textcolor{white}{Synapse$_2$} \\
| [empty synapse] | $\vdots$ \\
\textcolor{white}{Synapse$_n$} \\
};

\matrix (N1) at (5,0) [neuron,inner sep=3mm,
                     matrix of nodes,
                     nodes={synapse,draw=blue},
                     row sep=1mm,
                     nodes in empty cells,
                     outer sep=2mm]{
|[label={[inner sep=2pt,outer sep=0]90: Expecto Patronum}]| Synapse$_1$ \\
Synapse$_2$ \\
Synapse$_3$ \\
Synapse$_4$ \\
};

\matrix (N2) at (10,0) [neuron,inner sep=3mm,
                     matrix of nodes,
                     nodes={synapse,draw=blue},
                     row sep=1mm,
                     nodes in empty cells,
                     outer sep=2mm]{
|[label={[inner sep=2pt,outer sep=0]90: Wingardium Leviosa}]| Synapse$_1$ \\
Synapse$_2$ \\
Synapse$_3$ \\
Synapse$_4$ \\
};

\begin{pgfonlayer}{topology}
\node[fit=(N0)(N1),topology,xshift=2mm,yshift=-1.5mm,minimum height=8cm] (T) {};
\end{pgfonlayer}
\end{tikzpicture}
\end{document}

答案1

我(只是)猜测你喜欢画下面的图:

在此处输入图片描述

抱歉,但我看不懂你的代码,所以接下来的 MWE 大部分都是我从头开始写的。这时我可能会误解你代码的某些部分。如果发生这种情况,请告诉我。

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                backgrounds,
                fit,
                matrix,
                positioning}
\usepackage{xcolor}

\tikzset{
   arr/.style = {-{Triangle[scale=0.8]}, 
                 draw=gray, ultra thick,
                 shorten >=1mm, shorten <=1mm}, 
    en/.style = {draw=none, fill=none, text=black},
every label/.append style = {font=\bfseries, text=black, inner sep=0pt},
   FIT/.style = {draw=gray, fill=gray!30, rounded corners, 
                 inner xsep=2em, inner ysep=3ex, yshift=2ex,
                 fit = #1, node contents={}},
neuron/.style = {matrix of nodes,
                 nodes={draw=blue, rounded corners, fill=gray!50, 
                        text height=2ex, minimum width=6em, 
                        inner sep=1mm,
                        text=#1},
                 row sep=2mm,
                 outer sep=2mm},
        }
\begin{document}
    \begin{tikzpicture}[
node distance = 11mm
                        ]
%%%
\matrix (N0) [neuron=white]
{
|[label=:Avara Ka Davara]| Synapse$_1$         \\
Synapse$_2$         \\
|[en]| $\vdots$     \\
Synapse$_n$         \\
};
\scoped[on background layer]
    \node (f0) [FIT=(N0-1-1) (N0-4-1)];

\matrix (N1) [neuron=black, right=of N0]
{
|[label=Expecto Patronum]| Synapse$_1$ \\
Synapse$_2$     \\
Synapse$_3$     \\
Synapse$_4$     \\
};
\scoped[on background layer]
    \node (f1) [FIT=(N1-1-1) (N1-4-1)];

\matrix (N2) [neuron=black, right=of N1]
{
|[label=Expecto Patronum]| Synapse$_1$ \\
Synapse$_2$     \\
Synapse$_3$     \\
Synapse$_4$     \\
};
\scoped[on background layer]
    \node (f2) [FIT=(N2-1-1) (N2-4-1)];
%%%%
\draw[arr] (N0-1-1 -| f0.east) -- (N1-1-1 -| f1.west);
\draw[arr] (f1) -- (f2);
\coordinate[below left= of N0.south west] (aux);
\draw[arr] (f2.east) -- ++ (5mm,0) |- (aux) |- (f0);
    \end{tikzpicture}
\end{document}

附录: 您在评论中的请求可以通过不同的方式实现,但是如果您期望,该解决方案应该自动保持FIT节点的相等高度,那么这将成为一个非常苛刻/复杂的问题。

让我们首先展示一个更简单的情况,当FIT节点可以有不同的高度时:

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                backgrounds,
                fit,
                matrix,
                positioning}
\usepackage{xcolor}

\tikzset{
   arr/.style = {-{Triangle[scale=0.8]}, 
                 draw=gray, ultra thick,
                 shorten >=1mm, shorten <=1mm}, 
    en/.style = {draw=none, fill=none, text=black},
every label/.append style = {name=LN, anchor=south,     % <---
                 font=\bfseries, text=black, 
                 text width=10em, align=flush center,   % <---
                 yshift=1ex},                           % <---
   FIT/.style = {draw=gray, fill=gray!30, rounded corners, 
                 inner sep=1ex,
                 fit=#1, node contents={}},
neuron/.style = {matrix of nodes,
                 nodes={draw=blue, rounded corners, fill=gray!50, 
                        text height=2ex, minimum width=6em, 
                        inner sep=1mm,
                        text=#1},
                 row sep=2mm,
                 outer sep=0mm},
        }
\begin{document}
    \begin{tikzpicture}[
node distance = 0mm and 11mm                            % <---
                        ]
%%%
\matrix (N0) [neuron=white]
{
|[label=Avara Ka Davara
        Avara Ka Davara]| Synapse$_1$         \\        % <--- longer label
Synapse$_2$         \\
|[en]| $\vdots$     \\
Synapse$_n$         \\
};
\scoped[on background layer]
    \node (f0) [FIT=(LN) (N0-4-1)];                     % <---

\matrix (N1) [neuron=black, 
              above right=of N0.south east]             % <---
{
|[label=Expecto Patronum]| Synapse$_1$ \\
Synapse$_2$     \\
Synapse$_3$     \\
Synapse$_4$     \\
};
\scoped[on background layer]
    \node (f1) [FIT=(LN) (N1-4-1)];

\matrix (N2) [neuron=black,
              above right=of N1.south east]             % <---
{
|[label=Expecto Patronumy]| Synapse$_1$ \\
Synapse$_2$     \\
Synapse$_3$     \\
Synapse$_4$     \\
};
\scoped[on background layer]
    \node (f2) [FIT=(LN) (N2-4-1)];
%%%%
\draw[arr] (N0-1-1 -| f0.east) -- (N0-1-1 -| f1.west);  % <---
\draw[arr] (f1) -- (f1 -| f2.west);                     % <---
\coordinate[below left= 0.5 and 0.5 of N0.south west] (aux);    % <---
\draw[arr] (f2.east) -- ++ (0.5,0) |- (aux) |- (f0);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

对于具有相等节点高度的解决方案,FIT请提出新问题,因为(i)这是新问题,而不是问题中提出的问题,(ii)这里已经睡觉时间有一段时间了......

相关内容