我必须写一个如下图所示的流程图
我已经使用了这些包,
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
但我无法得到我想要的。我希望这里的一些 LaTeX 专家可以帮助我。
另一个选项是使用algorithm2e
包,是否可以同时拥有这两个代码?
当我使用半命令时,它会转到其他页面?如何在一页中编写完整的流程图?
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains}
\begin{document}
% Define block styles
\tikzset{
decision/.style={
diamond,
draw,
text width=4em,
text badly centered,
inner sep=0pt
},
block/.style={
rectangle,
draw,
text width=10em,
text centered,
rounded corners
},
cloud/.style={
draw,
ellipse,
minimum height=2em
},
descr/.style={
fill=white,
inner sep=2.5pt
},
connector/.style={
-latex,
font=\scriptsize
},
rectangle connector/.style={
connector,
to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
pos=0.5
},
rectangle connector/.default=-2cm,
straight connector/.style={
connector,
to path=--(\tikztotarget) \tikztonodes
}
}
\begin{tikzpicture}
\matrix (m)[matrix of nodes, column sep=2cm,row sep=8mm, align=center, nodes={rectangle,draw, anchor=center} ]{
|[block]| {Start}; & \\
|[block]| {Assume that $a=c$ the optimilalty cretierin given by } & \\
|[decision]| {Locally optimal} & \\
|[block]| {Assume that $a=d$ the optimilalty cretierin given by} & \\
|[decision]| {Locally optimal} & \\
|[block]| {Assume that $a=e$ the optimilalty cretierin given by} & \\
|[decision]| {Locally optimal} & \\
|[block]| {Assume that $a=f$ the optimilalty cretierin given by} & \\
|[decision]| {Locally optimal} & \\
|[block]| {Assume that $a=k$ the optimilalty cretierin given by} & \\
|[decision]| {Locally optimal} & \\
|[block]| {Stop}; & \\
};
\path [>=latex,->] (m-1-1) edge (m-2-1);
\path [>=latex,->] (m-2-1) edge (m-3-1);
\path [>=latex,->] (m-3-1) edge (m-4-1);
\path [>=latex,->] (m-4-1) edge (m-5-1);
\path [>=latex,->] (m-5-1) edge (m-6-1);
\path [>=latex,->] (m-6-1) edge (m-7-1);
\path [>=latex,->] (m-7-1) edge (m-8-1);
\path [>=latex,->] (m-8-1) edge (m-9-1);
\path [>=latex,->] (m-9-1) edge (m-10-1);
\path [>=latex,->] (m-10-1) edge (m-11-1);
\path [>=latex,->] (m-11-1) edge (m-12-1);
\end{tikzpicture}
\end{document}
答案1
例如:
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains}
\begin{document}
% Define block styles
\tikzset{
decision/.style={
diamond,
draw,
text width=4em,
text badly centered,
inner sep=0pt
},
block/.style={
rectangle,
draw,
text width=10em,
text centered,
rounded corners
},
cloud/.style={
draw,
ellipse,
minimum height=2em
},
descr/.style={
fill=white,
inner sep=2.5pt
},
connector/.style={
-latex,
font=\scriptsize
},
rectangle connector/.style={
connector,
to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
pos=0.5
},
rectangle connector/.default=-2cm,
straight connector/.style={
connector,
to path=--(\tikztotarget) \tikztonodes
}
}
\begin{tikzpicture}
\matrix (m)[matrix of nodes, column sep=2cm,row sep=8mm, align=center, nodes={rectangle,draw, anchor=center} ]{
|[block]| {Start} & \\
|[block]| {Assume that $a=c$ the optimilalty cretierin given by } & \\
|[decision]| {Locally optimal} & \\
|[block]| {Assume that $a=d$ the optimilalty cretierin given by} & \\
|[decision]| {Locally optimal} & |[block]| {Stop} \\
|[block]| {Assume that $a=e$ the optimilalty cretierin given by} & |[decision]| {Locally optimal} \\
|[decision]| {Locally optimal} & |[block]| {Assume that $a=k$ the optimilalty cretierin given by} \\
|[block]| {Assume that $a=f$ the optimilalty cretierin given by} & |[decision]| {Locally optimal} \\
};
\path [>=latex,->] (m-1-1) edge (m-2-1);
\path [>=latex,->] (m-2-1) edge (m-3-1);
\path [>=latex,->] (m-3-1) edge (m-4-1);
\path [>=latex,->] (m-4-1) edge (m-5-1);
\path [>=latex,->] (m-5-1) edge (m-6-1);
\path [>=latex,->] (m-6-1) edge (m-7-1);
\path [>=latex,->] (m-7-1) edge (m-8-1);
\path [>=latex,->] (m-8-1) edge (m-8-2);
\path [>=latex,->] (m-8-2) edge (m-7-2);
\path [>=latex,->] (m-7-2) edge (m-6-2);
\path [>=latex,->] (m-6-2) edge (m-5-2);
\end{tikzpicture}
\end{document}