如何创建带标签的盒子

如何创建带标签的盒子

我怎样才能将“识别”和“控制”放入箭头所示的框中?

在此处输入图片描述

有什么想法吗?

我的代码是:

\tikzstyle{startstop} = [ellipse,
minimum width=3cm,
minimum height=1cm,
text centered,
draw=black,
fill=orange!15]

\tikzstyle{io} = [trapezium,
trapezium stretches=true, % A later addition
trapezium left angle=70,
trapezium right angle=110,
minimum width=3cm,
minimum height=1cm, text centered,
draw=black, fill=blue!30]

\tikzstyle{process} = [rectangle, rounded corners,
minimum width=5cm,
minimum height=1cm,
text centered,
text width=5cm,
draw=black,
fill=violet!10]

\tikzstyle{decision} = [diamond,
minimum width=3cm,
minimum height=1cm,
text centered,
draw=black,
fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{figure}
\begin{tikzpicture}[node distance=2cm]


\node (start) [startstop] {Start};
\node (1) [process, below of=start] {Academic discipline in 1956};
\node (2) [process, below of=1] {Lionel Messi};
\node (3) [process, below of=2] {Kaka};
\node (4) [process, below of=3] {Roberto Carlos};
\node (5) [process, below of=4] {Rivaldo};
\begin{scope}[on background layer]
\node[rectangle, rounded corners,minimum width=6cm,minimum height=10cm] [fit = (1) (2) (3) (4) (5),fill=blue!10,label=north:\textcolor{red}{Identification}] (bx4) {};
\end{scope}
\node (6) [process, right of=1, xshift=6cm] {Silver didrachma from Crete depicting Talos, an ancient mythical automaton with artificial intelligence};
\node (7) [process, below of=6] { two visions for how to achieve machine intelligence emerged};
\node (8) [process, below of=7] {Researchers in the 1960s};
\node (9) [process, below of=8] {Carlo};
\node (10) [process, below of=9] {Mourinho};
\node (11) [process, below of=10] {Enrique};
\node (12) [process, below of=11] {Puskas};
\node (13) [process, below of=12] {Zidane};
\begin{scope}[on background layer]
\node[rectangle,rounded corners,minimum width=6cm,minimum height=16.5cm] [fit = (6) (7) (8) (9) (10) (11) (12) (13),fill=blue!10,label=north east:\textcolor{red}{Control}] (bx4) {};
\end{scope}

\draw [arrow] (start) -- (1);
\draw [arrow] (1) -- (2);
\draw [arrow] (2) -- (3);
\draw [arrow] (3) -- (4);
\draw [arrow] (4) -- (5);
\draw [arrow] (5) |- ++(0,-2) -| ++(4,0)-| ++(0,12)-| ++(4,0)--(6);
\draw [arrow] (6) -- (7);
\draw [arrow] (7) -- (8);
\draw [arrow] (8) -- (9);
\draw [arrow] (9) -- (10);
\draw [arrow] (10) -- (11);
\draw [arrow] (11) -- (12);
\draw [arrow] (12) -- (13);
\draw [arrow] (13) |- ++(0,-2)-| ++(-12,0)-| ++(0,14)--(2) ;
\end{tikzpicture}
\end{figure}

答案1

您可以更改标签的锚点,这里我定义了一个header键,将red标签放置anchor = south eastnorth east:其父节点的锚点处。

代码

\documentclass[tikz]{standalone}
\usetikzlibrary{
  arrows.meta,      % uptodate arrow tips
  calc,             % coordinate calculations
  shapes.geometric, % for ellipse
  chains,           % for chains
  positioning}      % loaded by chains
\begin{document}
\begin{tikzpicture}[
  node distance=1cm and 2cm,
  startstop/.style = {
    ellipse, minimum width=3cm, minimum height=1cm,
    text centered, draw=black, fill=orange!15},
  process/.style = {
    rectangle, rounded corners, minimum height=1cm,
    text centered, text width=5cm, draw=black, fill=violet!10},
  fake fit/.style={% it's a matrix
    rectangle, fill=blue!10, inner sep=5mm, rounded corners},
  every join/.style={thick, -Stealth}, % capital S
  do compass points/.style={
    insert path={
      coordinate[ left=1cm of #1, name=#1-west]
      coordinate[right=1cm of #1, name=#1-east]
      coordinate[above=1cm of #1, name=#1-north]
      coordinate[below=1cm of #1, name=#1-south]}},
  header/.style={
    label={[red, anchor=south east]north east:{#1}}}
]
\matrix[start chain=m1 going below, fake fit] (m1) {
  \foreach \t in {Academic discipline in 1956, Lionel Messi, Kaka,
                  Roberto Carlos, Rivaldo}
    \node[on chain, process, join]{\t};
\\};
\node[above=of m1-begin, startstop] (start) {Start}
  edge[every join] (m1-begin);
\matrix[
  start chain=m2 going below, fake fit,
  right=of m1.north east, matrix anchor=north west] (m2) {
  \foreach \t in {
    {Silver didrachma from Crete depicting Talos, % comma needs {}
     an ancient mythical automaton with artificial intelligence},
    two visions for how to achieve machine intelligence emerged,
    Researchers in the 1960s,
    Carlo,  Mourinho, Enrique, Puskas, Zidane}
    \node[on chain, process, join]{\t};
\\};
\path[do compass points/.list={m1-2, m1-end, m2-begin, m2-end}];
\node also[header=Identification](m1-begin)
 node also[header=Control]       (m2-begin);

\draw [every join] (m1-end) -- (m1-end-south)
  -| ($(m1-end)!.5!(m2-begin)$) |- (m2-begin-north) -- (m2-begin);
\draw [every join] (m2-end) |- (m2-end-south -| m1-2-west) |- (m1-2);
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容