带有 tikzpicture 的流程图

带有 tikzpicture 的流程图

我对最后一个块关闭块图有些困惑。实际上,使用以下设置,结果是“结尾”附加在前一个块上,我无法理解如何创建垂直空间。此外,我想为每个块设置相同的尺寸(高度和宽度)。

\tikzset{
block/.style = {draw, fill=white, rectangle, minimum height=3em, minimum width=3em},
decision/.style = {draw, diamond, aspect=1.5}
tmp/.style  = {coordinate}, 
sum/.style= {draw, fill=white, circle, node distance=1cm},
input/.style = {coordinate},
output/.style= {coordinate},
pinstyle/.style = {pin edge={to-,thin,black}}
}

\begin{tikzpicture}[auto, node distance=2cm,>=latex']

\node[sum] (start) {start};
\node[block, below of =start] (A) {solution};
\node[block, below of=A] (B) {solution};
\node[block, below of=B] (C) {calculation};
\node[block, below of=C] (D) {Updating geometry};
\node[sum,   below of=D] (end) {end};

\draw [->] (start) -- node{$\bold{v}, p,\bold{u}, q$} (A);
\draw [->] (A) -- node{$\bold{v}, p$} (B);
\draw [->] (B) -- node{$\bold{u}, q$} (C);
\draw [->] (C) -- node{$\frac{\partial L}{\partial \beta}$} (D);
\draw [->] (D) -- node{} (end);
\end{tikzpicture}

答案1

问题在于您使用的是一种已弃用的节点定位方法。(node distance在 的定义中,您也有一个sum。)使用该positioning库,您可以解决这些问题。语法从 更改为below of=...below=of ...below=<distance> of ...可以使用包实现相等的大小eqparbox,并且您需要编译两次。我添加了一个equal size样式,它采用一个可选参数来指示要使其相等的节点组,下面的框和圆圈被视为这些组。

\documentclass[tikz,border=3mm]{standalone}
\usepackage{amsmath,eqparbox}
\usetikzlibrary{arrows,positioning}
\newbox\eqnodebox
\begin{document}
\tikzset{equal size/.style={execute at begin
    node={\setbox\eqnodebox=\hbox\bgroup},
    execute at end node={\egroup\eqmakebox[#1][c]{\copy\eqnodebox}}},
    equal size/.default=A,
    block/.style = {draw, fill=white, rectangle, minimum height=3em, minimum
    width=3em,equal size=B},
    sum/.style= {draw, fill=white, circle,equal size=S},
}

\begin{tikzpicture}[auto, node distance=2.5em,>=latex']

\node[sum] (start) {start};
\node[block, below=of start] (A) {solution};
\node[block, below=of A] (B) {solution};
\node[block, below=of B] (C) {calculation};
\node[block, below=of C] (D) {Updating geometry};
\node[sum,   below=of D] (end) {end};

\draw [->] (start) -- node{$\boldsymbol{v}, p,\boldsymbol{u}, q$} (A);
\draw [->] (A) -- node{$\boldsymbol{v}, p$} (B);
\draw [->] (B) -- node{$\boldsymbol{u}, q$} (C);
\draw [->] (C) -- node{$\frac{\partial L}{\partial \beta}$} (D);
\draw [->] (D) -- node{} (end);
\end{tikzpicture}
\end{document}

在此处输入图片描述

这个arrows库也有点过时了,但我暂时保留了它,而且我不得不用 来替换\bold,我不知道\boldsymbol。出于这些原因,最好提供可编译的代码,正如评论中要求的那样。

附录:您可以使用chains将节点放在链上。我添加了一种允许您添加边标签的样式。

\documentclass[tikz,border=3mm]{standalone}
\usepackage{amsmath,eqparbox}
\usetikzlibrary{arrows,positioning,chains}
\newbox\eqnodebox
\makeatletter
\tikzset{ce/.code=\gdef\tikz@chain@edge@label{#1},ce={},
labeled join/.style={every join/.append style={#1,
edge label={\tikz@chain@edge@label}}}}
\makeatother
\begin{document}
\tikzset{equal size/.style={execute at begin
    node={\setbox\eqnodebox=\hbox\bgroup},
    execute at end node={\egroup\eqmakebox[#1][c]{\copy\eqnodebox}}},
    equal size/.default=A,
    block/.style = {draw, fill=white, rectangle, minimum height=3em, minimum
    width=3em,equal size=B,on chain,join},
    sum/.style= {draw, fill=white, circle,equal size=S,on chain,join},
}

\begin{tikzpicture}[ node distance=2.5em,>=latex']
\begin{scope}[start chain=going below,labeled join={->}]
\node[sum,ce=A] (start) {start};
\node[block,ce={$\boldsymbol{v}, p,\boldsymbol{u}, q$}] (A) {solution};
\node[block,ce={$\boldsymbol{v}, p$}] (B) {solution};
\node[block,ce={$\boldsymbol{u}, q$}] (C) {calculation};
\node[block,ce={$\frac{\partial L}{\partial \beta}$}] (D) {Updating geometry};
\node[sum,ce={}] (end) {end};
\end{scope}
\end{tikzpicture}
\end{document}

还请注意,您可能需要查看包forest,它可能为您提供创建此图形的更便捷的方法。

\documentclass[border=3mm]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows}
\usepackage{amsmath}
\tikzset{
    block/.style = {draw, fill=white, rectangle, minimum height=3em, minimum
    width=3em,text width={width("updating geometry")},text centered},
    sum/.style= {draw, fill=white, circle},
}
\begin{document}
\begin{forest}
for tree={el/.style={edge label={node[midway,circle,right]{#1}}},
    edge={-latex'},where n children=0{sum}{if level=0{sum}{block}},
    l sep=2.5em}
[start
 [solution,el={$\boldsymbol{v}, p,\boldsymbol{u}, q$}
  [solution,el={$\boldsymbol{v}, p$}
   [calculating,el={$\boldsymbol{u}, q$}
    [updating geometry,el={$\frac{\partial L}{\partial \beta}$}
     [end]
    ]   
   ]
  ]
 ] 
]
\end{forest}
\end{document}

在此处输入图片描述

相关内容