如何在流程图旁边绘制标签框,并将流程图放在图形环境下,以便它出现在 LoF 上

如何在流程图旁边绘制标签框,并将流程图放在图形环境下,以便它出现在 LoF 上

你好,我想将框描述添加到我的流程图中,例如。(画得不好请见谅)。

首先,我不知道如何制作该框和其中的形状并将其对齐成相等的符号。该框应约为 5x6cm(灵活)。我希望流程图的标题位于流程图下方。

这是我仅针对流程图的尝试:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\usepackage{caption}

\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=red!30]
\tikzstyle{io}=[trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{line} = [draw, very thick, color=black!50, -latex']

\begin{document}
    \begin{tikzpicture}[node distance=2cm]
        \node(start)[startstop]{Start};
        \node(in1)[io, below of=start]{Input};
        \node(pro1)[process, below of=in1]{Process 1};
        \node(dec1)[decision, below of=pro1, yshift=-0.5cm]{Decision 1};
        \node(pro2a)[process, below of=dec1, yshift=-0.5cm]{Process 2a};
        \node(pro2b)[process, right of=dec1, xshift=2cm]{Process 2b};
        \node(out1)[io, below of=pro2a]{Output};
        \node(stop)[startstop, below of=out1]{Stop};
        
        \draw[arrow](start)--(in1);
        \draw[arrow](in1)--(pro1);
        \draw[arrow](pro1)--(dec1);
        \draw[arrow](dec1)--node[anchor=east]{yes}(pro2a);
        \draw[arrow](dec1)--node[anchor=south]{no}(pro2b);
        \path[line, dashed](pro2b) |- (pro1);
        \draw[arrow](pro2a)--(out1);
        \path[line](out1)--(stop);

    \end{tikzpicture}   
\end{document}

请帮助我。提前致谢。

答案1

我把大部分精力都花在了偏离主题的问题上。关于如何添加图例的想法是从 @js bibra 的回答 (+1) 中偷来的,并略微升级以更好地匹配你的草图:

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                matrix,
                positioning,
                quotes,
                shapes.geometric}
\usepackage{array}
\usepackage{caption}

\tikzset{FlowChart/.style = {
      base/.style = {draw, minimum width=32mm, minimum height=8mm,
                     align=center},
 startstop/.style = {base, rectangle, rounded corners, fill=red!30},
   process/.style = {base, rectangle, fill=orange!30},
        io/.style = {base, trapezium, trapezium stretches,
                     trapezium left angle=70, trapezium right angle=110,
                     fill=blue!30},
  decision/.style = {base, diamond, aspect=1.3, fill=green!30, inner xsep=1pt},
       arr/.style = {-Stealth, semithick}
                            }
        }% end of tikzset

\begin{document}
\begin{figure}[htb]
\centering
    \begin{tikzpicture}[FlowChart, 
node distance = 6mm and 12mm,
  start chain = A going below,
                        ]
    \begin{scope}[every node/.append style={on chain=A, join=by arr}]
\node [startstop]   {Start};        % A-1
\node [io]          {Input};
\node [process]     {Process 1};    % A-3
\node [decision]    {Decision 1};   % A-4
\node [process]     {Process 2a};   
\node [io]          {Output};
\node [startstop]   {Stop};         % A-7
    \end{scope}
\node (A-8) [process, right=of A-4] {Process 2b};
%
\draw[arr]  (A-4) to ["yes"]    (A-8);
\path       (A-4) to ["no"]     (A-5);
\draw[arr, dashed]
            (A-8) |- (A-3);
%
\matrix (m) [draw, below right=0mm of A-1.north -| A-8.east,
             matrix of nodes,
             column 1/.style = {every node/.append style={scale=0.25, anchor=south}},
             column sep = 1em
            ]
{
                    &   {}      \\
                    &   {}      \\
\draw[arr] (-.3,0) -- (0.3,0);          & bla bla   \\
\draw[arr, dashed] (-.3,0) -- (0.3,0);  & bla bla   \\
|[startstop]|       & bla bla   \\
|[io]|              & bla bla   \\
|[process]|         & bla bla   \\
|[decision]|        & bla bla   \\
};
\node[below] at (m.north) {Description:};
    \end{tikzpicture}
\caption{Flowchart}
\label{fig:flowchart}
\end{figure}
\end{document}

笔记tizstyle已被弃用,请tikzset按照上述 MWE(最小工作示例)使用它。

在此处输入图片描述

答案2

我只画出了前两个节点和右边的图例——sam 改编自——

相同的 tikz。两个矩阵。(图例)

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{
    positioning,
    calc,
    shapes.geometric,
    matrix}

\begin{document}

\begin{tikzpicture}[
  line/.style={
    draw,
    thick,
    -latex
  },
  status/.style={
    rectangle, rounded corners,
    draw=black, 
    text centered, 
    anchor=north, 
    text=black, 
    minimum width=2em, 
    minimum height=2em
  },
trapezium/.style={
    trapezium,trapezium left angle=70,trapezium left angle=110,
    draw=black, 
    text centered, 
    anchor=north, 
    text=black, 
    minimum width=2em, 
    minimum height=2em
},
  m2style/.style={
    column sep=1em, 
    row sep=1em,
    nodes={status},
    font=\bfseries
  },
  mstyle/.style={
    column sep=10em, 
    row sep=3em,
    nodes={status},
    font=\bfseries
  }
]

\matrix (m) [
  matrix of nodes,
  ampersand replacement=\&,
  mstyle,
  row 1 column 1/.style={nodes={fill=green!30}},
  row 2 column 1/.style={nodes={fill=blue!30}},
]{
    A\\
    B\\
};

\matrix (m2) [
  right=1.8cm of m, 
  draw=black, 
  matrix of nodes,
  ampersand replacement=\&,
  m2style,
  column 2/.append style={nodes={text width=1.5cm}},
]{
    |[fill=green]|H  \& Healthy \\
    |[fill=red]|A1 \& Infected  \\
    |[fill=yellow]|A2 \& Infected  \\
    |[fill=gray]|D \& Death  \\
};

\draw[line] (m-1-1) -- (m-2-1) node[pos=0.5,left,align=left] {label1};
%\draw[line] (m-1-2) -- (m-1-3) node[pos=0.5,above] {wait $\tau$ ticks};
%\draw[line] (m-1-3) -- (m-2-3) node[pos=0.5,right] {wait 1 tick};
%\draw[line] (m-2-3) -- (m-2-2) node[pos=0.5,above] {$p_\mathrm{replenished}$};
%\draw[line] (m-2-2) -| (m-1-1) node[pos=0.2,above] {$1-p_\mathrm{infected}$};
%\draw[line] (m-2-2) -- (m-1-2) node[pos=0.5,left] {$p_\mathrm{infected}$};

\path let
  \p1=(m2.east),
  \p2=(m2.west)
  in
  node[align=center,text width=\x1-\x2,anchor=south,inner sep=0pt] 
  at ([yshift=5pt]m2.north)
  {Description};
\end{tikzpicture}

\end{document}

相关内容