matrix
我使用in绘制了以下流程图tikz
(代码取自这个问题):
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains}
\begin{document}
\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=.5
},
rectangle connector/.default=-2cm,
straight connector/.style={
connector,
to path=--(\tikztotarget) \tikztonodes
}
}
\begin{tikzpicture}
\matrix (m)[matrix of nodes, column sep=.8cm,row sep=6mm,
align=center, nodes={rectangle,draw, anchor=center} ]{
|[block]| {Start} & \\
|[block]| {Setting up the system } &
\\
|[block]| {Execute benchmarking applications} &
\\
|[block]| {Retrieve data for VNF and NFVI KPIs} & |[block]|
{Change parameters} \\
|[block]| {Data synthesis and Analysis} & \\
|[decision]| {Something meaningful ?} & \\
|[block]| {Perform statistical operations} & \\
|[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);
\draw [rectangle connector=2.5cm] (m-6-1) to node[descr, pos=0.5] {No} (m-4-2);
\draw [rectangle connector=2.5cm] (m-4-2) to (m-3-1);
\end{tikzpicture}
\end{document}
这给了我以下输出:
答案1
您有一条带边缘标签的路径No
。rectangle connector
不适用于此设置。您可以使用边缘标签绘制此路径的方式是
\draw [connector] (<start>) -| node[descr, pos=0.25] {No} (<target>);
您还正在加载chains
。一般来说,我并不喜欢到处使用这个库,但在我看来,您的图表是一个可以理解的例子。这会使代码更短一些,并允许我们避免重复。(如果您保留matrix
,请考虑添加cells={nodes={block}}
和删除所有|[block]|
以缩短代码。)我还做了一些其他小的布局更改,以达到
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,positioning,chains}
\begin{document}
\tikzset{
decision/.style={
diamond,
draw,
text width=4em,
align=center,
%text badly centered,
inner sep=0pt,
rounded corners=false
},
block/.style={
rectangle,
draw,
text width=10em,
text centered,
rounded corners
},
connector/.style={
-latex,
font=\scriptsize
},
descr/.style={
fill=white,
inner sep=2.5pt
},
}
\begin{tikzpicture}[node distance=5mm,node font=\sffamily]
\begin{scope}[start chain=1 going below,nodes={on chain,join,block},
every join/.style={connector}]
\path node{Start}
node{Setting up the system}
node {Execute benchmarking applications}
node {Retrieve data for VNF and NFVI KPIs}
node {Data synthesis and Analysis}
node[decision] {Some-\\thing meaning-ful?}
node {Stop};
\end{scope}
\path (1-4.east) -- node[right=8mm,block] (CP) {Change parameters}
(1-5.east);
\draw [connector] (1-6) -| node[descr, pos=0.25] {No} (CP);
\draw [connector] (CP) |- (1-3);
\end{tikzpicture}
\end{document}
答案2
Tikz 允许使用语法-|
和在两个对象(点,节点)之间构建水平和垂直路径|-
。请参阅手册 3.1.4b 的第 153 页。
\draw [rectangle connector=2.5cm] (m-6-1) -| (m-4-2.south);
\draw [rectangle connector=2.5cm] (m-4-2) |- (m-3-1);
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains}
\begin{document}
\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=.5
},
rectangle connector/.default=-2cm,
straight connector/.style={
connector,
to path=--(\tikztotarget) \tikztonodes
}
}
\begin{tikzpicture}
\matrix (m)[matrix of nodes, column sep=.8cm,row sep=6mm,
align=center, nodes={rectangle,draw, anchor=center} ]{
|[block]| {Start} & \\
|[block]| {Setting up the system } &
\\
|[block]| {Execute benchmarking applications} &
\\
|[block]| {Retrieve data for VNF and NFVI KPIs} & |[block]|
{Change parameters} \\
|[block]| {Data synthesis and Analysis} & \\
|[decision]| {Something meaningful ?} & \\
|[block]| {Perform statistical operations} & \\
|[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);
\draw [rectangle connector=2.5cm] (m-6-1) -| (m-4-2.south);
\draw [rectangle connector=2.5cm] (m-4-2) |- (m-3-1);
\end{tikzpicture}
\end{document}