改进 Tikz 流程图

改进 Tikz 流程图

流程图

我如何添加如上流程图所示的圆圈,以便可以为每个流程编号?现在我的最佳目标是使用流程图显示一个流程,并描述流程图下的每个框,所以我想出了在每个框上放置一个数字然后在下面描述它的想法。

如果可能的话请帮我把这些圆圈放上去或者如果可能的话请提出另一种方法。

代码:

                \documentclass{standalone}
            \usepackage{tikz}
            
            \usetikzlibrary{shapes.geometric, arrows}
            \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]
            
            
            \begin{document}
            
                \begin{tikzpicture}[node distance=2cm]
                \small
                \node (start) [startstop] {Start};
                \node (dec1) [decision, right of=start, xshift=1.5cm,align=center] {Decision1};
                \draw [arrow] (start) -- (dec1);
                \node (pro1) [process, right of=dec1, xshift=1.75cm,align=center] {Process};
                \draw [arrow] (dec1) -- node[anchor=south] {No} (pro1);
                \node (dec2) [decision, below of=dec1, yshift=-0.95cm,align=center] {Decision2};
                \draw [arrow] (dec1) -- node[anchor=west] {Yes} (dec2);
            \end{tikzpicture}
            
            \end{document}

答案1

您可以使用append after command来定义添加这些圆圈的样式。例如,

clabel=1 between north west and north east

将节点置于上边缘,并且

clabel=2 between north and east

将其放在右上对角线上。请注意,这\tikzstyle已被弃用,您的节点定位方法也已被弃用。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{positioning,shapes.geometric}
\tikzset{startstop/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30},
io/.style={trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30},
process/.style={rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30},
decision/.style={diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30},
arrow/.style={thick,->,>=stealth},
clabel/.style args={#1 between #2 and #3}{append after command={
(\tikzlastnode.#2) -- (\tikzlastnode.#3) 
node[pos=0.5,circle,draw,font=\sffamily,fill=white,inner sep=1pt]{#1}
}}}


\begin{document}

\begin{tikzpicture}[node distance=3em and 2.5em,nodes={font=\small\sffamily,align=center}]
    \node (start) [startstop,clabel=1 between north west and north east] {Start};
    \node (dec1) [decision, right=of start,clabel=2 between north and east] {Decision1};
    \draw [arrow] (start) -- (dec1);
    \node (pro1) [process, right=of dec1,clabel=3 between north west and north east] {Process};
    \draw [arrow] (dec1) -- node[anchor=south] {No} (pro1);
    \node (dec2) [decision, below=of dec1,clabel=4 between north and east] {Decision2};
    \draw [arrow] (dec1) -- node[anchor=west] {Yes} (dec2);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

您的意思是仅添加如下类型的圆环吗:

\documentclass{standalone}
            \usepackage{tikz}
            
            \usetikzlibrary{shapes.geometric, arrows}
            \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]
            
            
            \begin{document}
            
                \begin{tikzpicture}[node distance=2cm]
                \small
                \node (start) [startstop] {Start};
                \node (dec1) [decision, right of=start, xshift=1.5cm,align=center] {Decision1};
                \draw [arrow] (start) -- (dec1);
                \node (pro1) [process, right of=dec1, xshift=1.75cm,align=center] {Process};
                \draw [arrow] (dec1) -- node[anchor=south] {No} (pro1);
                \node (dec2) [decision, below of=dec1, yshift=-0.95cm,align=center] {Decision2};
                \draw [arrow] (dec1) -- node[anchor=west] {Yes} (dec2);
                
                %adds circles
                \draw [thick] (0,0.5) circle (4pt);
                \draw [thick] (4.3,0.5) circle (4pt);
                \draw [thick] (7,0.5) circle (4pt);
                \draw [thick] (2.7,-2.5) circle (4pt);
            \end{tikzpicture}
            
            \end{document}

在此处输入图片描述

里面有数字:

               \draw [thick] (0,0.5) circle (4pt);
                \node at (0,0.5) {1};
                \draw [thick] (4.3,0.5) circle (4pt);
                \node at (4.3,0.5) {2};
                \draw [thick] (7,0.5) circle (4pt);
                \node at (7,0.5) {3};
                \draw [thick] (2.7,-2.5) circle (4pt);
                \node at (2.7,-2.5) {4};

在此处输入图片描述

相关内容