如何为此 Tikz 代码定位箭头?

如何为此 Tikz 代码定位箭头?

我需要在流程图中两个预定义块之间绘制箭头。我知道如果块不共线,我可以使用“|-”绘制弯曲箭头,但那不起作用。下面是我的代码

\documentclass{beamer}
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{textcomp}
\usetikzlibrary{arrows, positioning, shapes.geometric}

\begin{document}
% Definition of blocks:

\tikzstyle{block} = [rectangle, minimum width=2cm, minimum height=1cm, text centered, text width=2cm, draw=black, fill=white]
\tikzstyle{adder} = [circle,minimum size=1em,text centered, draw=black]
\tikzstyle{arrow} = [thick,->,>=stealth]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 \begin{frame}
 \begin{center} 
 \begin{tikzpicture}[node distance=2 cm]
 \draw [step=0.5cm,gray!30,very thin](-5.5,-2) grid (5,5);
 \node(ref.pnt) at (-5,3.4) [FIX]{};
 \node(b1) [block, right of=ref.pnt, xshift=-1.33cm] {B1};
 \node(b2) [s.block, right of=b1, xshift=0.3cm] {B2};
 \node(b3) [block, right of=b2, xshift=0.3cm] {B3};
 \node(b4) [block, right of=b3, xshift=0.8cm] {B4};
 \node(add) [adder, below right of=b4, xshift=0.0cm] {+};
 \node(b5) [block, below left of=add, xshift=-0.0cm] {B5};
 \node(b6) [block, left of=b5, xshift=-0.8cm] {B6};
 \node(b7) [s.block, left of=b6, xshift=-0.3cm] {B7};
 \node(b8) [s.block, below of=b7, xshift=-0.0cm] {B8};
 \node(b9) [block, left of=b7, xshift=-0.3cm] {B9};

 \draw [arrow] (b1) -- (b2);
 \draw [arrow] (b2) -- (b3);
 \draw [arrow] (b3) -- (b4);
 \draw [active.arrow] (b4)  |- (add);
 \draw [arrow] (add)  |- (b5);
 \draw [arrow] (b5)  -- (b6);
 \draw [arrow] (b6)  -- (b7);
 \draw [arrow] (b7)  -- (b9);
 \draw [arrow] (b9)  |- (b8);
 \draw [active.arrow] (b8)  |- (b6);
 \draw [active.arrow] (b6)  |- (b5);

\end{tikzpicture}
\end{center}
\end{frame}
\end{document}

在此处输入图片描述 上图中的绿色箭头表示所需位置。我该如何指定此案例的起始/结束位置。

答案1

\draw [arrow] (b4)  |- (add);
\draw [arrow] (b8)  |- (b6);

只需切换|-到即可解决-|。但我不知道该怎么做才能解决:

\draw [active.arrow] (b6)  |- (b5);

答案2

与此同时,@serial 解决了你的问题(正如你指出的那样),但是,请注意,你的 MWE 并未定义你在其中使用的所有样式……所以我为了练习,以不同的方式重写了你的 MWE。看看它是否对你未来的项目有用

\documentclass{beamer}
\usepackage{tikz}
\usepackage{textcomp}
\usetikzlibrary{arrows, calc, chains, positioning, scopes}

\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
    \begin{center}
\begin{tikzpicture}[
               > = stealth,
   node distance = 2 cm and 0.5 cm,
     start chain = A going right,
    block/.style = {rectangle, draw, fill=white,
                    text width=2cm, minimum height=1cm,
                    align=center,on chain=A},
   sblock/.style = {block, text width=1cm},
    adder/.style = {circle, draw, minimum size=1em,
                    inner sep=1pt, node contents={\Large$+$}},
every join/.style = {thick},
    arrow/.style = {thick,->}
                    ]
%---
%\draw [step=0.5cm,gray!30,very thin] (-5.5,-2) grid (5,5);
%---
\node [block]               {B1};% node name: A-1
\node [sblock,join = by ->] {B2};
\node [block, join = by ->] {B2};
\node [sblock,join = by ->] {B4};
%
\node [block, below=of A-1] {B9};
\node [sblock,join = by <-] {B7};
\node [block, join = by <-] {B6};
\node [sblock,join = by <-] {B5};
%
\node [sblock, 
       below=1cm of A-6]    {B8};% node name: A-9
%
\node (add) [adder, right=of $(A-4.east)!0.5!(A-8.east)$];
%
    \begin{scope}[arrow]
\draw (A-4)  -| (add);
\draw (A-4)  |- (add);
\draw (add)  |- (A-8);
%
\draw (A-5)  |- (A-9);
\draw (A-9)  -| ([xshift=-3mm] A-7.south);
\draw ([xshift=3mm] A-7.south) |- (A-9 -| A-8) -- (A-8);    
    \end{scope}
\end{tikzpicture}
    \end{center}
\end{frame}
\end{document}

如你所见,我把节点命名留给了链,使用 join 简化了节点之间的箭头绘制,在块的样式中我省略了minimum width,正如你所见,这对 来说是多余的minimum width。有了 ,你就可以在每一个宏中scope[arrow]省去编写 的麻烦。[arrow]\draw

编辑: 我还纠正了您在 MWE 中使用的 TikZ 的所有过时语法!

在此处输入图片描述

相关内容