![无法在 Latex 中创建流程图](https://linux22.com/image/343873/%E6%97%A0%E6%B3%95%E5%9C%A8%20Latex%20%E4%B8%AD%E5%88%9B%E5%BB%BA%E6%B5%81%E7%A8%8B%E5%9B%BE.png)
我正在尝试在 latex 中创建流程图。我已将流程图附在下面。有人能帮我吗?
这是我尝试过的。我能够从节点到节点画线,但无法从节点到多节点画线。
\documentclass{article}
\usepackage{tikz}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{10pt}%
%%%>
%usepackage{threeparttable}
\usepackage{longtable}
\usepackage{amsmath}
\usepackage{cleveref}
\usepackage{acro}
%\usepackage[final]{graphicx}
\usepackage{float,epsf,caption,subcaption}
\usepackage{psfrag}
\usepackage{matlab-prettifier}
\usepackage{svg}
\usepackage{url}
\usepackage{rotating}
\usepackage{epstopdf}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows,positioning}
%\usepackage[backend=biber,style=ieee,sorting=ynt]{biblatex}
\newcommand\abs[1]{\left|#1\right|}
\newcommand\figref{Figure~\ref}
\renewcommand{\eqref}{\ref}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.arrows}
\usepackage{array}
\begin{document}
\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{tikzpicture}[node distance=2cm]
%%order of the nodes
\node (start) [startstop] {Start};
\node (in1) [io, below of=start] {Selecte a pixel in the vessel mask};
\node (pro1) [process, below of=in1] {obtain R,G,B values of the corresponding di pixel};
\node (d1) [decision, below of=pro1, yshift=-0.5cm] {d1};
\node (d2) [decision, left of=d1,yshift=-2cm] {d2};
\node (d3) [decision, below of=d2,xshift=4cm] {d3};
\node (d4) [decision, below of=d2] {d4};
\node (d5) [decision, below of=d4,xshift=2cm] {d5};
\node (d6) [decision, below of=d4, xshift=-2cm] {d6};
\node (d7) [decision, below of=d6,xshift=2cm] {d7};
\node (d8) [decision, below of=d6, xshift=-2cm] {d8};
\node (d9) [decision, below of=d8, xshift=11cm,] {d9};
\node (stop) [startstop, below of=d9] {Stop};
%%%%%%%%%%%% arrows
\draw [arrow] (start) -- (in1);
\draw [arrow] (in1) --(pro1);
%\draw [arrow] (pro1.east) |-(d1.east);
%\draw [arrow] (d1) -| (d9)
%\path([d1.west]edge [d2.north])
%\draw[arrow](d2) -- (d3)
%\draw[arrow](d2) -- (d4)
\end{tikzpicture};
%% equations
Equation numbers below are used in the above flow diagram.
\begin{equation}\label{eq:D1}\tag{D1}
g=10
\end{equation}
\begin{equation}\label{eq:D2}\tag{D2}
g=10
\end{equation}
\begin{equation}\label{eq:D3}\tag{D3}
g=10
\end{equation}
\begin{equation}\label{eq:D4}\tag{D4}
g=10
\end{equation}
\begin{equation}\label{eq:D5}\tag{D5}
g=10
\end{equation}
\begin{equation}\label{eq:D6}\tag{D6}
g=10
\end{equation}
\begin{equation}\label{eq:D7}\tag{D7}
g=10
\end{equation}
\begin{equation}\label{eq:D8}\tag{D8}
g=10
\end{equation}
\begin{equation}\label{eq:D9}\tag{D9}
g=10
\end{equation}
\end{document}
答案1
我已附上我的完整答案和通过代码获取的图像。
\documentclass{article}
\usepackage{tikz}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{10pt}%
%%%>
%usepackage{threeparttable}
\usepackage{longtable}
\usepackage{amsmath}
\usepackage{cleveref}
\usepackage{acro}
%\usepackage[final]{graphicx}
\usepackage{float,epsf,caption,subcaption}
\usepackage{psfrag}
\usepackage{matlab-prettifier}
\usepackage{svg}
\usepackage{url}
\usepackage{rotating}
\usepackage{epstopdf}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows,positioning}
%\usepackage[backend=biber,style=ieee,sorting=ynt]{biblatex}
\newcommand\abs[1]{\left|#1\right|}
\newcommand\figref{Figure~\ref}
\renewcommand{\eqref}{\ref}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.arrows}
\usepackage{array}
\begin{document}
\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{tikzpicture}[node distance=2cm]
%%order of the nodes
\node (start) [startstop] {Start};
\node (in1) [io, below of=start] {Selecte a pixel in the vessel mask};
\node (pro1) [process, below of=in1] {obtain R,G,B values of the corresponding di pixel};
\node (d1) [decision, below of=pro1, yshift=-0.5cm] {d1};
\node (d2) [decision, left of=d1,yshift=-2cm] {d2};
\node (d3) [decision, below of=d2,xshift=4cm] {d3};
\node (d4) [decision, below of=d2] {d4};
\node (d5) [decision, below of=d4,xshift=2cm] {d5};
\node (d6) [decision, below of=d4, xshift=-2cm] {d6};
\node (d7) [decision, below of=d6,xshift=2cm] {d7};
\node (d8) [decision, below of=d6, xshift=-2cm] {d8};
\node (d9) [decision, below of=d8, xshift=11cm,] {d9};
\node (stop) [startstop, below of=d9] {Stop};
%%%%%%%%%%%% arrows
\draw [arrow] (start) --(in1);
\draw [arrow] (in1) --(pro1);
\draw[arrow] (pro1) --(d1);
\draw[arrow] (d1.east)-|node[above]{yes}(d9);
\draw[arrow] (d1.west)-|node[above]{no}(d2);
\draw[arrow] (d2.east)-|node[above]{yes} (d3);
\draw[arrow] (d2)-- node[left]{no}(d4);
\draw[arrow] (d4.east)-|node[above]{yes} (d5);
\draw[arrow] (d4.west)-| node[above]{no}(d6);
\draw[arrow] (d6.east)-|node[above]{yes} (d7);
\draw[arrow] (d6.west)-| node[above]{no}(d8);
\draw[arrow] (d8.west) |- node[left]{no}(d9);
\draw[arrow] (d9.south) |- node[below]{yes}(stop.north);
\draw[arrow] (d5.south) -| node[right]{no}(d9);
\draw[arrow] (d7.south) -| node[right]{no}(d9);
\draw[arrow] (d3.south) -| node[right]{no}(d9);
\draw[arrow] (d9.east) |-node[right]{no}(0,-1);
\end{tikzpicture};
%% equations
Equation numbers below are used in the above flow diagram.
\begin{equation}\label{eq:D1}\tag{D1}
g=10
\end{equation}
\begin{equation}\label{eq:D2}\tag{D2}
g=10
\end{equation}
\begin{equation}\label{eq:D3}\tag{D3}
g=10
\end{equation}
\begin{equation}\label{eq:D4}\tag{D4}
g=10
\end{equation}
\begin{equation}\label{eq:D5}\tag{D5}
g=10
\end{equation}
\begin{equation}\label{eq:D6}\tag{D6}
g=10
\end{equation}
\begin{equation}\label{eq:D7}\tag{D7}
g=10
\end{equation}
\begin{equation}\label{eq:D8}\tag{D8}
g=10
\end{equation}
\begin{equation}\label{eq:D9}\tag{D9}
g=10
\end{equation}
\end{document}
答案2
我允许自己重新设计您的好解决方案。在此我做了以下更改:
- 使用最新的 TikZ 语法(
\tikzset
代替\tikzstyle
) - 利用库定位并使用其语法(
=of ...
而不是“of = ...”) - 移动标签
no
并yes
移至决策块 - 为所有线条制定通用样式定义
- 稍微重新排列线条
此后您的流程图变为:
在下面的 MWE 中,我从您的 MWE 中删除了所有与流程图无关的内容(包、文档文本):
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, calc, positioning, shapes.geometric,}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{10pt}%
\begin{document}
\tikzset{
base/.style = {draw, minimum width=3cm, minimum height=1cm, align=center},
startstop/.style = {base, rounded corners, fill=red!30},
io/.style = {base, trapezium,
trapezium left angle=70, trapezium right angle=110,
trapezium stretches=true, %%%% <-- added
fill=blue!30},
process/.style = {base, fill=orange!30},
decision/.style = {base, diamond, fill=green!30},
every path/.style = {thick,-Stealth}
}
\begin{tikzpicture}[
node distance = 1cm and 0.8cm]
%%order of the nodes
\node (start) [startstop] {Start};
\node (in1) [io, below=of start] {Select a pixel\\
in the vessel mask};
\node (pro1) [process, below=of in1] {obtain R,G,B values of \\
the corresponding di pixel};
\node (d1) [decision, below=of pro1] {d1};
\node (d2) [decision, below left =of d1] {d2};
\node (d4) [decision, below=of d2] {d4};
\node (d3) [decision, right=of d4 -| d1] {d3};
\node (d5) [decision, below right=of d4] {d5};
\node (d6) [decision, below left =of d4] {d6};
\node (d7) [decision, below right=of d6] {d7};
\node (d8) [decision, below left =of d6] {d8};
\node (d9) [decision, below right=of d7 -| d3.east] {d9};
\node (stop) [startstop, below=of d9] {Stop};
%%%%%%%%%%%% arrows
\draw (start) edge (in1)
(in1) edge (pro1)
(pro1) edge (d1);
\draw (d1.east) node[above right] {yes} -| (d9);
\draw (d1.west) node[above left] {no} -| (d2);
\draw (d2.east) node[above right] {yes} -| (d3);
\draw (d2) -- node[left]{no} (d4);
\draw (d4.east) node[above right] {yes} -| (d5);
\draw (d4.west) node[above left] {no} -| (d6);
\draw (d6.east) node[above right] {yes} -| (d7);
\draw (d6.west) node[above left] {no} -| (d8);
\draw (d8.west) node[above left] {no} -- ++ (-1,0) |- (d9);
\draw (d9.south) -- node[right] {yes} (stop.north);
%
\draw (d3.east) node[above right] {no} -- (d3 -| d9);
\draw (d5.east) node[above right] {no} -- (d5 -| d9);
\draw (d7.east) node[above right] {no} -- (d7 -| d9);
%
\draw (d9.east) node[above right]{no} -- ++ (1,0) |- ($(start)!0.5!(in1)$);
\end{tikzpicture};
\end{document}
笔记:
- 使用
trapezium
比较棘手。如果此形状的节点中的文本比用 声明的文本更宽minimum width
,则形状会变得出乎意料的宽。我通过将文本设置为两行来防止这种情况。 - 你的(以及我的)MWE 没有在你的问题中重现草图
编辑:trapezium
如果将此形状的节点添加到选项中,则可以避免形状 大小的问题trapezium stretches=true
。