关于流程图的问题

关于流程图的问题

我一直在尝试使用 TikZ 包生成这样的流程图。

在此处输入图片描述

下面是我的代码,但我无法完成以下操作:

  1. 如何使用线条将问号与“是/否”框的第一列连接起来?

  2. 我怎样才能在线上放置数字(1,2,3,4)来表示 4 种不同的情况?

  3. 如何使用箭头将第二列“是/否”框与第三列框(CO、D、NT、AT)连接起来?

  4. 是否有可能在“是/否”框的第一列和第二列放置一个大框或一些突出显示的区域,以表示有两个不同的阶段(第一阶段和第二阶段)?

任何关于改进编码和流程图的建议都将受到赞赏。

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{booktabs,caption,fixltx2e}
\usepackage[flushleft]{threeparttable}
\usetikzlibrary{arrows,automata}
\RequirePackage{epstopdf}
\usetikzlibrary{positioning,shapes.geometric}
\usepackage{sidecap}
\usepackage{wrapfig}

\begin{document}

\begin{tikzpicture}


\tikzstyle{circle} = [draw, ellipse,fill=pink!20, node distance=3.3cm, minimum height=2.5em, text width=3.5em, text centered]

\tikzstyle{block} = [rectangle, draw, fill=blue!20, text width=3.4em, text centered, rounded corners, minimum height=1.5em, node distance=3.3cm]

\tikzstyle{line} = [draw, thick, -latex']



\node [block] (Rone) {\small{Yes}};
\node [block, below of=Rone,below=-2.8cm] (Rtwo) {\small{No1}};

\node [block, right of=Rone,right=-1.5cm] (Tone) {\small{Yes1}};
\node [block, right of=Rtwo,right=-1.5cm] (Ttwo) {\small{No1}};

\node [block, below of=Rtwo,below=-2.5cm] (Rthree) {\small{Yes2}};
\node [block, below of=Rthree,below=-2.8cm] (Rfour) {\small{No2}};

\node [block, right of=Rthree,right=-1.5cm] (Tthree) {\small{Yes2}};
\node [block, right of=Rfour,right=-1.5cm] (Tfour) {\small{Yes2}};

\node [block, below of=Rfour,below=-2.5cm] (Rfive) {\small{Yes3}};
\node [block, below of=Rfive,below=-2.8cm] (Rsix) {\small{No3}};

\node [block, right of=Rfive,right=-1.5cm] (Tfive) {\small{No3}};
\node [block, right of=Rsix,right=-1.5cm] (Tsix) {\small{No3}};

\node [block, below of=Rsix,below=-2.5cm] (Rseven) {\small{Yes4}};
\node [block, below of=Rseven,below=-2.8cm] (Reight) {\small{No4}};

\node [block, right of=Rseven,right=-1.5cm] (Tseven) {\small{No4}};
\node [block, right of=Reight,right=-1.5cm] (Teight) {\small{Yes4}};

\node [circle,  below left =0.1 cm and 2 cm of Rfour] (Pat) {\large{?}};

\node [circle,  below right =-0.2 cm and 2 cm of Tone] (C) {\scriptsize{CO}};

\node [circle,  below right =-0.4 cm and 2 cm of Tthree] (C) {\scriptsize{AT}};

\node [circle,  below right =-0.4 cm and 2 cm of Tfive] (C) {\scriptsize{NT}};

\node [circle,  below right =-0.2 cm and 2 cm of Tseven] (C) {\scriptsize{DF}};


\path [line] (Rone) -- (Tone);
\path [line] (Rtwo) -- (Ttwo);
\path [line] (Rthree) -- (Tthree);
\path [line] (Rfour) -- (Tfour);
\path [line] (Rfive) -- (Tfive);
\path [line] (Rsix) -- (Tsix);
\path [line] (Rseven) -- (Tseven);
\path [line] (Reight) -- (Teight);


\draw [-] (Tone.east) -- ++(1,0) -- ++(0,-0.8) -- (Ttwo.east);
\draw [-] (Tthree.east) -- ++(1,0) -- ++(0,-0.8) -- (Tfour.east);
\draw [-] (Tfive.east) -- ++(1,0) -- ++(0,-0.8) -- (Tsix.east);
\draw [-] (Tseven.east) -- ++(1,0) -- ++(0,-0.8) -- (Teight.east);

\draw [-] (Rone.west) -- ++(-1,0) -- ++(0,-0.8) -- (Rtwo.west);
\draw [-] (Rthree.west) -- ++(-1,0) -- ++(0,-0.8) -- (Rfour.west);
\draw [-] (Rfive.west) -- ++(-1,0) -- ++(0,-0.8) -- (Rsix.west);
\draw [-] (Rseven.west) -- ++(-1,0) -- ++(0,-0.8) -- (Reight.west);

\end{tikzpicture}

\end{document}

答案1

这里有一个具有三个matrix节点和两个\foreach循环的可能解决方案。

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix,positioning,arrows.meta}

\begin{document}
\begin{tikzpicture}[
    font=\sffamily, >=latex
]

\matrix (phase1) [matrix of nodes, 
      nodes={draw, minimum width=1cm, 
             minimum height=5mm, anchor=center, outer sep=0pt}, 
      row sep=-\pgflinewidth, fill=yellow!30, label=below:Phase I]
{
Yes \\ No \\[5mm] 
Yes \\ No \\[5mm] 
Yes \\ No \\[5mm] 
Yes \\ No \\
};

\matrix (phase2) [matrix of nodes, 
      nodes={draw, minimum width=1cm, 
             minimum height=5mm, anchor=center, outer sep=0pt}, 
      row sep=-\pgflinewidth, right=of phase1, fill=green!30, label=below:Phase II]
{
Yes \\ No \\[5mm] 
No \\ Yes \\[5mm] 
No \\ No \\[5mm] 
Yes \\ Yes \\
};

\matrix (phase3) [matrix of nodes, 
      nodes={draw, minimum width=1cm, 
             minimum height=10mm-\pgflinewidth, anchor=center, outer sep=0pt}, 
      row sep=5mm, right= of phase2]
{
CO \\ 
D \\ 
NT \\ 
AT \\ 
};

\node[circle, draw=green!70!black, fill=green!70, minimum width=1cm,
      anchor=center,left=of phase1] (question) {?};

\foreach \i [count=\x] in {1,3,5,7}{
    \draw[->] (question) --++(.75,0) |- 
               node[above,pos=.75] {\x} (phase1-\i-1.south west);
    \draw[->] (phase2-\i-1.south east) -- (phase3-\x-1);
 }

\foreach \i in {1,2,...,8}
    \draw[->] (phase1-\i-1) -- (phase2-\i-1);

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容