使用 tikz 的流程图中的箭头长度

使用 tikz 的流程图中的箭头长度

我正在使用 tikz 绘制流程图。连接决策菱形和块的一些箭头比其他箭头短,我不知道如何使所有箭头的长度相同。这里是代码:

\begin{tikzpicture}[node distance = 2cm, auto][t]
\node [block] (init) {Perform load forecast} ++(-3.4,+.1);
\node [block, below of=init] (evaluate) {Execute optimization};
\node [block, below of=evaluate] (SOC) {Read SOC of BESS from SCADA};
\node [block, right of=SOC, node distance=3cm] (constraint) {Modify optimization constraint};
\node [decision, below of=SOC] (decide) {Is next BESS active power command violate
 SOC constraint?};
\node [block, below of=decide, node distance=3.5cm] (stop) {Send BESS active power command};
\node [block, below of=decide, node distance=3.5cm] (active) {Send BESS active power command};
\node [block, below of=active, node distance=2cm] (rscada) {Read reactive power load from SCADA};

\node [decision, below of=rscada,node distance=2.6cm] (decide1) {$Q_{res}>Q_L$?};

 \node [block, below of=decide1, node distance=2.6cm] (injq) {Inject $Q_l$};

\node [block, right of=injq, node distance=3cm] (qres) {Inject $Q_{res}$};

% Draw edges
\path [line] (init) -- (evaluate);
\path [line] (evaluate) -- (SOC);
\path [line] (SOC) -- (decide);
\path [line] (decide) -- node[near start] {N}(active);
\path [line] (decide) -| node [very near start]{Y}(constraint);
\path [line] (active) -- (rscada);
\path [line] (rscada) -- (decide1);
\path [line] (decide1) --  node [near start] {Y}(injq);
\path [line] (decide1) -| node [very near start] {N}(qres);

 \path [line] (constraint) |- (evaluate);

\path [line] (qres.east) -- ++(.53,0) node(lowerright){} |- (init.east);
\draw (0,-18.9) -- (0,-19.5);
\draw (3,-18.9) -- (3,-19.5);
\draw (0,-18.9) -- (0,-19.5);
\draw (0,-19.5) -- (4.71,-19.5);
\draw (4.71,-19.5) -- (4.71,-18.1);
\end{tikzpicture}

流程图

答案1

我猜你缺少样式是因为你没有提供完整的 MWE。但你可以放弃使用below of,right of键,因为它们已被弃用。请参阅

因此,您可以below = 2cm of <node name>始终提供语法而不是节点距离调整。 根据您的情况,在decide节点声明中增加类似below = 3cm of SOC或类似的内容。

% in the preamble
\usetikzlibrary{positioning,shapes.geometric}
%...........
%...........
%...........
\begin{tikzpicture}[>=latex,auto,block/.style={align=center,draw,text width=2cm},decision/.style={diamond,draw,text width=2cm,align=center},line/.style={draw,->}]
\node [block] (init) {Perform load forecast} ++(-3.4,+.1);
\node [block, below = of init] (evaluate) {Execute optimization};
\node [block, below = of evaluate] (SOC) {Read SOC of BESS from SCADA};
\node [block, right = of SOC] (constraint) {Modify optimization constraint};
\node [decision, below = of SOC] (decide) {Is next BESS active power command violate
 SOC constraint?};
\node [block, below = of decide] (stop) {Send BESS active power command};
\node [block, below = of decide] (active) {Send BESS active power command};
\node [block, below = of active] (rscada) {Read reactive power load from SCADA};

\node [decision, below = of rscada] (decide1) {$Q_{res}>Q_L$?};
\node [block, below = of decide1] (injq) {Inject $Q_l$};
\node [block, right = of injq] (qres) {Inject $Q_{res}$};
% Draw edges
\path [line] (init) -- (evaluate);
\path [line] (evaluate) -- (SOC);
\path [line] (SOC) -- (decide);
\path [line] (decide) -- node[near start] {N}(active);
\path [line] (decide) -| node [very near start]{Y}(constraint);
\path [line] (active) -- (rscada);
\path [line] (rscada) -- (decide1);
\path [line] (decide1) --  node [near start] {Y}(injq);
\path [line] (decide1) -| node [very near start] {N}(qres);
\path [line] (constraint) |- (evaluate);
\path [line] (qres.east) -- ++(.53,0) node(lowerright){} |- (init.east);
\end{tikzpicture}

在此处输入图片描述

相关内容