我想使用 tikz 库将菱形的东点与两个矩形(第 2 阶段、第 3 阶段)之间的中点连接起来;请看图。
以下是示例代码:
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\begin{document}
\begin{tikzpicture}[sibling distance=80pt,box/.style={rectangle,draw}]
\tikzstyle{box} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, aspect=3]
\node (dec) [decision] {$A>B$};
\node (proc1) [box, below of=dec, yshift=-0.5cm] {Phase 1};
\node (proc2) [box, below of=proc1, yshift=-0.5cm] {Phase 2};
\node (proc3) [box, below of=proc2, yshift=-0.5cm] {Phase 3};
\draw [arrow] (dec) -- (proc1);
\draw [arrow] (proc1) -- (proc2);
\draw [arrow] (proc2) -- (proc3);
\draw [arrow] (dec) -| ([xshift=1cm, yshift=0cm]dec.east) |- coordinate[midway](proc3)(proc2);
\end{tikzpicture}
\end{document}
主要思想是计算两个矩形的中点:Phase2 和 Phase 3。
不幸的是,最终得到的终点是矩形第 2 阶段东边的中点。
感谢您的帮助。
答案1
我将按以下方式绘制您的流程图:
\documentclass[border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
calc, chains,
positioning,
shapes.geometric}
\begin{document}
\begin{tikzpicture}[
> = Stealth,
node distance = 8mm and 12mm,
start chain = going below,
box/.style = {draw, minimum width=3cm, minimum height=1cm, align=center},
decision/.style = {diamond, draw, minimum width=3cm, minimum height=1cm,
align=center, aspect=3}
]
\begin{scope}[nodes={on chain, join=by ->}]
\node (dec) [decision] {$A>B$};
\node (proc1) [box] {Phase 1};
\node (proc2) [box] {Phase 2};
\node (proc3) [box] {Phase 3};
\end{scope}
\draw [->] (dec.east) --++ (1,0) |- ($(proc2.south)!0.5!(proc3.north)$);
\end{tikzpicture}
\end{document}
- 节点以链形式连接
- 节点之间的箭头由宏绘制
join
calc
最后两个节点之间的坐标通过链计算- 在定义图像元素样式时使用最近的钾Z语法,用于定位库`定位。
答案2
解决方案很简单。连接两个矩形时,计算中点:
\draw [arrow] (proc2) -- (proc3) coordinate[midway] (mid);
并与钻石的东点相连:
\draw [arrow] (dec) -| ([xshift=1cm, yshift=0cm]dec.east) |- (mid);