我如何绘制与矩形节点的关系?

我如何绘制与矩形节点的关系?

我正在尝试使用节点在两个图形中绘制一个简单的关系。基本上我想要的是这样的: 在此处输入图片描述

我如何使用 tikz 来实现这一点?这两个关系应该彼此相邻。我认为如果使用子图,效果会更好。有什么想法吗?

编辑:这是我目前所拥有的:

\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}
\usetikzlibrary{positioning,arrows}
\tikzset{
block/.style={
  draw, 
  rectangle, 
  minimum height=1.5cm, 
  minimum width=3cm, align=center
  }, 
line/.style={->,>=latex'}
}
\begin{document}
\begin{figure}[htbp]
\begin{subfigure}{.5\textwidth}
\centering
\begin{tikzpicture}
  \node[block] (a) {Text 1};
  \node[block, right = 0.5cm of a] (b) {Text 5};
  \draw[line] (a.east) |- (b.west);
\end{tikzpicture} 
\caption{Text}
\label{fig:myfirstsubfig}
\end{subfigure}
\begin{subfigure}{.5\textwidth}
  \centering
  \begin{tikzpicture}
  \node[block] (a) {Text 1};
  \node[block, above right = 0.2cm and 0.5cm of a] (b) {Text 3};
  \node[block, below right = 0.2cm and 0.5cm of b]   (c) {Text 5};
  \draw[line] (a.north) |- (b.west);
  \draw[line] (b.east) -| (c.north);
\end{tikzpicture} 
\caption{Text}
\label{fig:mysecondsubfig}
\end{subfigure}
\end{figure}
\end{document}

编辑:目前有三个问题:两个子图不相邻,缺少标签,缺少Text 2和的子框Text 4。有什么想法吗?

编辑:现在子图彼此相邻。我现在需要的只是子框和标签。

答案1

这看起来不像图像,但您的代码表明您正在对其进行一些修改,并且我对此进行了修改。

\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}
\usepackage[scale=.8]{geometry}
\usetikzlibrary{positioning,arrows}
\tikzset{
  block/.style={
    draw,
    rectangle,
    minimum height=1.5cm,
    minimum width=3cm,
    align=center
  },
  subblock/.style={
    draw,
    rectangle,
    minimum height=.75cm,
    minimum width=1.5cm,
    align=center
  },
  line/.style={->,>=latex'}
}
\begin{document}
  \begin{figure}[htbp]
    \begin{subfigure}[b]{.5\textwidth}
      \centering
      \begin{tikzpicture}
        \node[block] (a) {Text 1};
        \node[block, right = 1.5cm of a] (b) {Text 5};
        \draw[line] (a.east) -- (b.west) node [midway, above] {do(a)};
      \end{tikzpicture}
      \caption{Text}
      \label{fig:myfirstsubfig}
    \end{subfigure}
    \begin{subfigure}[b]{.5\textwidth}
      \centering
      \begin{tikzpicture}
        \node[block] (a) {Text 1};
        \node[block, above right = 0.2cm and 0.5cm of a] (b) {Text 3\\};
        \node (b2) [anchor=south west, subblock] at (b.south west) {Text 2};
        \node (b4) [anchor=south east, subblock] at (b.south east) {Text 4};
        \node[block, below right = 0.2cm and 0.5cm of b]   (c) {Text 5};
        \draw[line] (a.north) |- (b2.west) node [midway, above] {do(a)};
        \draw[line] (b4.east) -| (c.north) node [midway, above] {do(b)};
      \end{tikzpicture}
      \caption{Text}
      \label{fig:mysecondsubfig}
    \end{subfigure}
  \end{figure}
\end{document}

子块样式

相关内容