我正在努力强制箭头连接到节点的特定侧。我有兴趣实现以下任一解决方案:
- 明确强制箭头连接到节点的左侧
- 利用自动定位/对齐来强制箭头不与其他箭头重叠
例子
当前结果
期望的结果
箭头穿过底部节点并进入大流程节点,以便它不会与其余箭头交叉。
平均能量损失
% vim:ft=tex:
%
\documentclass{standalone}
% TiKz drawing
\usepackage{tikz}
\usetikzlibrary{
matrix,
arrows.meta,
positioning,
scopes,
backgrounds,
fit}
\begin{document}
% Define set to use across flow charts
\tikzset{%
>={Latex[width=2mm,length=2mm]},
% Specifications for style of nodes:
base/.style = {rectangle, rounded corners, draw=black,
minimum width=2cm, minimum height=1cm,
text centered, font=\sffamily},
activityStarts/.style = {base, fill=blue!30},
startstop/.style = {base, fill=red!30},
activityRuns/.style = {base, fill=green!30},
process/.style = {base, minimum width=2.5cm, fill=orange!15,
font=\ttfamily},
back group/.style={fill=gray!20,rounded corners, draw=black!50, dashed, inner xsep=15pt, inner ysep=10pt}
}
\begin{tikzpicture}[node distance=1.5cm, every node/.style={fill=white, font=\sffamily}, align=center, scale=0.7, transform shape]
% Specification of nodes (position, etc.)
\node (start) [activityStarts] {Start Node};
\node (lit) [process, right = of start] {ProcNode};
\node (data) [process, right = of lit] {ProcTwo};
\node (eda) [process, right = of data] {ProcThree};
\node (reseldev) [activityRuns, below = 4cm of start] {BigProcess};
\node (res2) [process, right = of reseldev] {Res 2};
\node (res1) [process, above = of res2] {Res 1};
\node (res3) [process, below = of res2] {Res 3};
\draw [->] (start) -- (lit);
\draw [->] (lit) -- (data);
\draw [->] (data) -- (eda);
\draw [->, rounded corners=5pt] (eda) -- ++ (0,0) |- (reseldev);
\draw [->] (reseldev) -- (res1);
\draw [->] (reseldev) -- (res2);
\draw [->] (reseldev) -- (res3);
\end{tikzpicture}
\end{document}
答案1
您可以使用该ext.paths.ortho
库(库集的一部分tikz-extra
)进行之字形连接,如下所示:
% vim:ft=tex:
%
\documentclass{standalone}
% TiKz drawing
\usepackage{tikz}
\usetikzlibrary{
matrix,
arrows.meta,
positioning,
scopes,
backgrounds,
fit,
ext.paths.ortho}
\begin{document}
% Define set to use across flow charts
\tikzset{%
>={Latex[width=2mm,length=2mm]},
% Specifications for style of nodes:
base/.style = {rectangle, rounded corners, draw=black,
minimum width=2cm, minimum height=1cm,
text centered, font=\sffamily},
activityStarts/.style = {base, fill=blue!30},
startstop/.style = {base, fill=red!30},
activityRuns/.style = {base, fill=green!30},
process/.style = {base, minimum width=2.5cm, fill=orange!15,
font=\ttfamily},
back group/.style={fill=gray!20,rounded corners, draw=black!50, dashed, inner xsep=15pt, inner ysep=10pt}
}
\begin{tikzpicture}[node distance=1.5cm, every node/.style={fill=white, font=\sffamily}, align=center, scale=0.7, transform shape]
% Specification of nodes (position, etc.)
\node (start) [activityStarts] {Start Node};
\node (lit) [process, right = of start] {ProcNode};
\node (data) [process, right = of lit] {ProcTwo};
\node (eda) [process, right = of data] {ProcThree};
\node (reseldev) [activityRuns, below = 4cm of start] {BigProcess};
\node (res2) [process, right = of reseldev] {Res 2};
\node (res1) [process, above = of res2] {Res 1};
\node (res3) [process, below = of res2] {Res 3};
\draw [->] (start) -- (lit);
\draw [->] (lit) -- (data);
\draw [->] (data) -- (eda);
\draw [->, rounded corners=5pt] (eda.south) |-|[ distance=.75cm] (reseldev.north);
\draw [->] (reseldev) -- (res1);
\draw [->] (reseldev) -- (res2);
\draw [->] (reseldev) -- (res3);
\end{tikzpicture}
\end{document}
答案2
稍微修改了@Alan Munn 的回答(+1),大部分都是题外话的建议:
- 使用
chains
库来定位节点 P
所有节点使用通用节点样式 ( )reseldev
使用循环在和res...
节点之间绘制箭头
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
chains,
ext.paths.ortho,
positioning,
}
\begin{document}
\begin{tikzpicture}[
node distance=8mm and 12 mm,
arr/.style = {-{Latex[width=2mm,length=2mm]}},
base/.style = {rectangle, rounded corners, draw=,
minimum width=2cm, minimum height=1cm,
font=\sffamily},
P/.style = {base, fill=#1},
]
% Specification of nodes (position, etc.)
\begin{scope}[start chain = going right,
nodes = {P=red!30,on chain, join=by arr}]
\node (start) [P=blue!30] {Start Node};
\node (lit) {ProcNode};
\node (data) {ProcTwo};
\node (eda) {ProcThree};
\end{scope}
\begin{scope}[start chain = going below,
nodes = {P=red!30,on chain}]
\node (res1) [below=of lit] {Res 1};
\node (res2) {Res 2};
\node (res3) {Res 3};
\end{scope}
%
\node (reseldev) [P=green!30, left=of res2] {BigProcess};
% arrows out of join macro
\foreach \i in {res1, res2, res3}
\draw[arr] (reseldev) -- (\i.west);
\draw [->, rounded corners]
(eda) |-|[ distance=4mm] (reseldev);
\end{tikzpicture}
\end{document}
答案3
尝试这个修改过的(部分)代码:
\begin{tikzpicture}[node distance=1.5cm, every node/.style={fill=white, font=\sffamily}, align=center, scale=0.7, transform shape]
% Specification of nodes (position, etc.)
\draw[gray!20] (0,0) grid (12,-8);% You can comment or delete this line
\node (start) [activityStarts] {Start Node};
\node (lit) [process, right = of start] {ProcNode};
\node (data) [process, right = of lit] {ProcTwo};
\node (eda) [process, right = of data] {ProcThree};
\node (reseldev) [activityRuns, below = 4cm of start] {BigProcess};
\node (res2) [process, right = of reseldev] {Res 2};
\node (res1) [process, above = of res2] {Res 1};
\node (res3) [process, below = of res2] {Res 3};
\draw [->] (start) -- (lit);
\draw [->] (lit) -- (data);
\draw [->] (data) -- (eda);
% \draw [->, rounded corners=5pt] (eda) -- ++ (0,0) |- (reseldev);
\draw [->] (reseldev) -- (res1);
\draw [->] (reseldev) -- (res2);
\draw [->] (reseldev) -- (res3);
\draw[->] (eda.270)--(11.8,-1)--(0,-1)-- (reseldev);% <<< added
\end{tikzpicture}
输出:
无论如何我认为这个解决方案更直接:
使用修改后的最终代码:
% vim:ft=tex:
\documentclass[border=10pt]{standalone}
% TiKz drawing
\usepackage{tikz}
\usetikzlibrary{
matrix,
arrows.meta,
positioning,
scopes,
backgrounds,
fit}
\begin{document}
% Define set to use across flow charts
\tikzset{%
>={Latex[width=2mm,length=2mm]},
% Specifications for style of nodes:
base/.style = {rectangle, rounded corners, draw=black,
minimum width=2cm, minimum height=1cm,
text centered, font=\sffamily},
activityStarts/.style = {base, fill=blue!30},
startstop/.style = {base, fill=red!30},
activityRuns/.style = {base, fill=green!30},
process/.style = {base, minimum width=2.5cm, fill=orange!15,
font=\ttfamily},
back group/.style={fill=gray!20,rounded corners, draw=black!50, dashed, inner xsep=15pt, inner ysep=10pt}
}
\begin{tikzpicture}[node distance=1.5cm, every node/.style={fill=white, font=\sffamily}, align=center, scale=0.7, transform shape]
% Specification of nodes (position, etc.)
\node (start) [activityStarts] {Start Node};
\node (lit) [process, right = of start] {ProcNode};
\node (data) [process, right = of lit] {ProcTwo};
\node (eda) [process, right = of data] {ProcThree};
\node (reseldev) [activityRuns, below = 4cm of eda] {BigProcess};
\node (res2) [process, left = of reseldev] {Res 2};
\node (res1) [process, above = of res2] {Res 1};
\node (res3) [process, below = of res2] {Res 3};
\draw [->] (start) -- (lit);
\draw [->] (lit) -- (data);
\draw [->] (data) -- (eda);
\draw [->] (reseldev) -- (res1);
\draw [->] (reseldev) -- (res2);
\draw [->] (reseldev) -- (res3);
\draw[->] (eda)-- (reseldev);
\end{tikzpicture}
\end{document}