latex - 用 Tikz 连接节点而不跨越其他块
问题描述
我想在我的代码中连接块 B 和 M 而不让连接线“切割”F。如何强制连接扩大连接线并避免 F?
\documentclass[11pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.geometric,arrows,positioning,intersections}
\begin{document}
\begin{tikzpicture}[auto,node distance=1cm,thick,
main node/.style={black,draw,minimum width=1.5cm,minimum height=0.75cm}]%circle,draw,font=\sffamily\Large\bfseries}]
\node[main node] (L) {L};
\node[main node] (F) [left = of L ] {F};
\node[main node] (C) [below = of F ] {M};
\node[main node] (B) [right = of L ] {B};
\node[main node] (AP) [below = of B ] {AP};
\node[main node] (A) [below = of L ] {A};
\node[main node] (H) [right = of B ] {H};
\node[main node] (G) [right = of H] {G};
\node[main node] (BR) [below = of G] {BR};
\node[main node] (LR) [below = of BR] {LR};
\node[main node] (U) [below = of AP ] {U};
\node[main node] (P) [below = of U ] {P};
\path[every node/.style={font=\sffamily\small}]
(L) edge node [right] {} (B)
(L) edge node [right] {} (F)
(L) edge node [right] {} (C)
(F) edge node [right] {} (C)
(B.north) edge [out=90,in=90] node [right] {} (F.north)
(B.north) edge [out=90,in=180] node [right] {} (C.west)
(B) edge node [right] {} (AP)
(B) edge node [right] {} (A)
(AP.east) edge [out=0,in=270] node [left] {} (H.south)
(B) edge node [right] {} (H)
(H) edge node [right] {} (G)
(U.east) edge [out=0,in=270] node [left] {} (H.south)
(P.east) edge [out=0,in=270] node [left] {} (H.south)
(U) edge node [right] {} (P)
(BR.west) edge [out=180,in=270] node [right] {} (H.south)
(LR.west) edge [out=180,in=270] node [right] {} (H.south)
(BR.east) edge [out=0,in=0] node [right] {} (G.east)
(LR.east) edge [out=0,in=0] node [right] {} (G.east);
\end{tikzpicture}
\end{document}
这就是我现在得到的
这就是我想要得到的
谢谢!
解决方案
在 tikz 中没有直接的方法可以做到这一点,但这可以通过添加中间节点来实现。这里有两种方法可以做到这一点。
第一个(蓝色)在主路径中使用边缘。由于边只有一个分支,因此在适当的位置创建坐标并在另一边中重复使用。
第二种方式(红色)使用带有多个中间节点的常规 tikz 线。如果需要,它更灵活,并且可以使用任意数量的中间节点。
应调整中间节点的位置以达到预期的效果。
\documentclass[11pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.geometric,arrows,positioning,intersections}
\begin{document}
\begin{tikzpicture}[auto,node distance=1cm,thick,
main node/.style={black,draw,minimum width=1.5cm,minimum height=0.75cm}]%circle,draw,font=\sffamily\Large\bfseries}]
\node[main node] (L) {L};
\node[main node] (F) [left = of L ] {F};
\node[main node] (C) [below = of F ] {M};
\node[main node] (B) [right = of L ] {B};
\node[main node] (AP) [below = of B ] {AP};
\node[main node] (A) [below = of L ] {A};
\node[main node] (H) [right = of B ] {H};
\node[main node] (G) [right = of H] {G};
\node[main node] (BR) [below = of G] {BR};
\node[main node] (LR) [below = of BR] {LR};
\node[main node] (U) [below = of AP ] {U};
\node[main node] (P) [below = of U ] {P};
\path[every node/.style={font=\sffamily\small}]
(L) edge node [right] {} (B)
(L) edge node [right] {} (F)
(L) edge node [right] {} (C)
(F) edge node [right] {} (C)
(B.north) edge [out=90,in=90] node [right] {} (F.north)
%%%% (B.north) edge [out=90,in=180] node [right] {} (C.west)
%west_of_F is an intermediate node to allow a proper connection of B and C
(B.north) edge [blue,out=90,in=90] coordinate[at end] (west_of_F) ($(F.west)+(-1cm,0)$)
(west_of_F) edge [blue, out=-90,in=180] (C.west)
(B) edge node [right] {} (AP)
(B) edge node [right] {} (A)
(AP.east) edge [out=0,in=270] node [left] {} (H.south)
(B) edge node [right] {} (H)
(H) edge node [right] {} (G)
(U.east) edge [out=0,in=270] node [left] {} (H.south)
(P.east) edge [out=0,in=270] node [left] {} (H.south)
(U) edge node [right] {} (P)
(BR.west) edge [out=180,in=270] node [right] {} (H.south)
(LR.west) edge [out=180,in=270] node [right] {} (H.south)
(BR.east) edge [out=0,in=0] node [right] {} (G.east)
(LR.east) edge [out=0,in=0] node [right] {} (G.east);
\draw[red] (B.north) to[out=90,in=0] ($(B.north)+(-3cm,2cm)$)
to [out=180,in=90] ($(C.west)+(-1.1cm,2cm)$)
to [out=-90,in=180] (C.west);
\end{tikzpicture}
\end{document}
推荐阅读
- animation - Unreal - 同时移动玩家的相机和手
- java - 可以存储携带数据到二维码的数组列表吗?
- javascript - 我如何在 React Native Mapview 中设置标记
- angular - 在 ng2-charts 中没有显示多个饼图
- python - 基于类的视图如何确定将调用哪个模板文件?
- angular - 如何在 Angular 5 中执行缓存 http get 请求?
- node.js - 如何让多个用户使用单一路由登录
- dialogflow-es - Dialogflow v2 Beta 1 使用 Python 更新意图
- java - TableRow 在 TableLayout 中返回空值?
- sql - SQL 乘以 AVG