在 LaTeX 中绘制数据流图

在 LaTeX 中绘制数据流图

是否可以在 LaTeX 中绘制如下数据流图?如果可以,怎么做?(实际上我只是对边界框感到困惑)。

多谢

数据流图

编辑:以下代码将为我提供除边界框之外的所有内容,有人可以帮忙吗?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}
\begin{center}
\begin{tikzpicture}[
  font=\rmfamily\footnotesize,
  every matrix/.style={ampersand replacement=\&,column sep=2cm,row sep=.6cm},
  source/.style={draw,thick,rounded corners,fill=yellow!20,inner sep=.3cm},
  process/.style={draw,thick,circle,fill=blue!20},
  sink/.style={source,fill=green!20},
  datastore/.style={draw,very thick,shape=datastore,inner sep=.3cm},
  dots/.style={gray,scale=2},
  to/.style={->,>=stealth',shorten >=1pt,semithick,font=\rmfamily\scriptsize},
  every node/.style={align=center}]

  % Position the nodes using a matrix layout
  \matrix{
    \node[source] (a) {A}; \& \& \\
     \& \& \node[source] (b) {B};\\
     \node[source] (c) {C}; \& \node[source] (d) {D};\\
     \& \& \node[source] (e) {E};\\
     \node[source] (f) {F}; \& \& \\      
  };

  % Draw the arrows between the nodes and label them.
  \draw[to] (a) -- node[midway,above] {raw events}
      node[midway,below] {level 0} (c);
  \draw[to] (c) -- node[midway,right] {raw event data\\level 1} (f);
  \draw[to] (f) to[bend right=20] node[midway,above] {events}
      node[midway,below] {level 1} (d);
  \draw[to] (d)-- node[midway,above] {events}
      node[midway,below] {level 1} (b);
  \draw[to] (d) -- node[midway,above] {events}
      node[midway,below] {level 1} (e);
\end{tikzpicture}
\end{center}
\end{document}

答案1

正如评论中提到的,该fit库正是为此目的而设计的。关于该fit节点,有一点需要了解,那就是除了中心之外,很难将文本放在其中的任何地方,因此要标记虚线部分,您需要手动放置单独的节点。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,fit,positioning}

\begin{document}
\begin{tikzpicture}[
  font=\rmfamily\footnotesize,
  every matrix/.style={ampersand replacement=\&,column sep=2cm,row sep=.6cm},
  source/.style={draw,thick,rounded corners,fill=yellow!20,inner sep=.3cm},
  process/.style={draw,thick,circle,fill=blue!20},
  sink/.style={source,fill=green!20},
  datastore/.style={draw,very thick,shape=datastore,inner sep=.3cm},
  dots/.style={gray,scale=2},
  to/.style={->,>=stealth',shorten >=1pt,semithick,font=\rmfamily\scriptsize},
  every node/.style={align=center}]

  % Position the nodes using a matrix layout
  \matrix{
    \node[source] (a) {A}; \& \& \\
     \& \& \node[source] (b) {B};\\
     \node[source] (c) {C}; \& \node[source] (d) {D};\\
     \& \& \node[source] (e) {E};\\
     \node[source] (f) {F}; \& \& \\      
  };

  % Draw the arrows between the nodes and label them.
  \draw[to] (a) -- node[midway,above] {raw events}
      node[midway,below] {level 0} (c);
  \draw[to] (c) -- node[midway,right] {raw event data\\level 1} (f);
  \draw[to] (f) to[bend right=20] node[midway,above] {events}
      node[midway,below] {level 1} (d);
  \draw[to] (d)-- node[midway,above] {events}
      node[midway,below] {level 1} (b);
  \draw[to] (d) -- node[midway,above] {events}
      node[midway,below] {level 1} (e);
  % Draw the dotted surrounding lines and add the labels as separate nodes
  % This is necessary because the anchor of the fitted node is always center

  \node[draw,dotted,fit=(a) (c) (f),inner sep=4ex,] (ACF) {};
  \node[above=-3ex of ACF] (ACFt) {Title 1};
  \node[draw,dotted,fit=(b) (e), inner sep=4ex] (BE) {};
  \node[above=-3ex of BE] (Bet) {Title 2};
\end{tikzpicture}
\end{document}

代码输出

相关内容