如何绘制自包含框来表达层次结构

如何绘制自包含框来表达层次结构

我想画一些独立的框来表达层次结构?我想画下面的图像,我知道如何使用 Tikz 绘制小框 (A、B、C):

\tikzstyle{block} = [rectangle, draw, text centered]
\begin{tikzpicture}[node distance = 2cm, auto]
    \node [block, thick] (init) {initialize model};
    \node [block,thick, right of=init,node distance=3cm] (system) {system};
    \draw [->, ultra thick] (init) -- (system);
\end{tikzpicture}

但我不知道如何绘制大框(系统常规和特殊)。快照

答案1

以下代码重新创建了您问题中提供的图像:

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

\begin{document}
    \begin{tikzpicture}[
node distance = 8mm and 4mm,
 block/.style = {rectangle, draw, thick,
                 text width=12mm, align=center},
   FIT/.style = {rectangle, draw, thick, inner ysep=12mm, inner xsep=6mm,
                 fit=#1},
   arr/.style = {-Stealth, ultra thick},
         font = \sffamily\bfseries
                        ]
\node [block]               (a) {A};
\node [block,below=of a]    (b) {B};
\node [FIT=(a) (b)] (ssys) {};
    \node[below right=0mm of ssys.north west] {System special};
\node [block, below left=of ssys] (c) {C};
\node [FIT=(ssys) (c)] (gsys) {};
     \node[below right=0mm of gsys.north west] {System general};
%
\draw [arr] (c.north) -- (b.south);
\draw [arr] (b) -- (a);
\end{tikzpicture}
\end{document}

在此处输入图片描述

在代码中我使用tikzarrows.meta(用于箭头)、fit(用于节点“系统特殊”和“系统通用”)以及positioning用于在图像中定位节点。

相关内容