描述
我想用有向边(或路径)连接两个节点。边应 1) 弯曲且 2) 有装饰 - 但仅在边的中间。草稿如下所示:尝试 1
我分别实现了 1) 和 2)。但我没有实现 1) + 2) 的组合,或者结果很差。据我所知,路径修饰是一个全局属性,因此适用于完整路径。正如这里所写tikz 手册,第 11.2.3 章以及几篇帖子。
第二次尝试
我尝试使用两个虚拟纸币 A 和 B,并在它们之间用锯齿线创建一条路径\documentclass[margin=10pt]{standalone}
\usepackage{tikz} %drawings
\usetikzlibrary{arrows,positioning, decorations.pathmorphing} %drawings positioning
\usepackage[siunitx]{circuitikz}
\begin{document}
\begin{tikzpicture}
\draw [help lines] (0,0) grid (15,10);
% CONTENT NODES
\node[align=center] (agent) at (2,5){Agent :: Mental Models};
\node[align=center] (action) at (7, 5){Actions/\\ Communications};
% DUMMY NODES
\node(A) at (4.5, 3){};
\node(B) at (5.5, 3){};
% ZIGZAG LINE BETWEEN DUMMY NODES
\path [decoration={zigzag, post length=0.1cm, pre length=0.1cm, amplitude=5}]
(A) edge[decorate] node[below] {takes} (B);
% CONNECT DUMMY NODES TO CONTENT NODES WITH ADJUSTED MARGIN
\path[shorten >=-.3cm]
(action) edge[bend left] (B);
\path[shorten <=-0.3cm]
(A) edge[->, bend left] (agent);
\end{tikzpicture}
\end{document}
但问题是没有闭合路径。结果很丑。参考锯齿线段的断开
第三次尝试
我尝试使用这个包\usepackage[siunitx]{circuitikz}
绘制完整的路径。这对于直线路径非常有效。但我无法将它用于弯曲路径
第四次尝试
我测试了在 Inkscape 中绘制与 SVG 相同的内容并将其导入文档。这至少有两个缺点:SVG 中有很多文本,并且文本框与文本的正确对齐很麻烦。此外,在维护等方面,我更喜欢“干净的代码”而不是权宜之计。答案1
您可以使用一些pre length
和post length
,就像您已经做的那样,但与pre=curveto
和结合使用post=curveto
,这将使示例中的直线段弯曲。
\documentclass[margin=10pt]{standalone}
\usepackage{tikz} %drawings
\usetikzlibrary{arrows.meta,bending,positioning, decorations.pathmorphing} %drawings positioning
\begin{document}
\begin{tikzpicture}
\draw [help lines] (0,0) grid (15,10);
% CONTENT NODES
\node[align=center] (agent) at (2,5){Agent :: Mental Models};
\node[align=center] (action) at (7, 5){Actions/\\ Communications};
% DUMMY NODES
\node(A) at (4.5, 3){};
\node(B) at (5.5, 3){};
% ZIGZAG LINE BETWEEN DUMMY NODES
\draw [decoration={zigzag,pre=curveto,post=curveto,
post length=1cm, pre length=1cm, amplitude=5},decorate,-{Latex[bend]}]
(action) to[bend left=60] node[below=0.5ex] {takes} (agent);
\end{tikzpicture}
\end{document}
您可以将其设为路径长度的一小部分。
\documentclass[margin=10pt]{standalone}
\usepackage{tikz} %drawings
\usetikzlibrary{arrows.meta,bending,positioning,decorations.markings, decorations.pathmorphing} %drawings positioning
\begin{document}
\begin{tikzpicture}
\draw [help lines] (0,0) grid (15,10);
% CONTENT NODES
\node[align=center] (agent) at (2,5){Agent :: Mental Models};
\node[align=center] (action) at (7, 5){Actions/\\ Communications};
% DUMMY NODES
\node(A) at (4.5, 3){};
\node(B) at (5.5, 3){};
% ZIGZAG LINE BETWEEN DUMMY NODES
\path [preaction={decorate,decoration={markings,
mark=at position 0 with {\xdef\mypgfdecoratedpathlength{\pgfdecoratedpathlength}}}},
postaction={decorate,draw,
decoration={zigzag,pre=curveto,post=curveto,
post length=0.4*\mypgfdecoratedpathlength,
pre length=0.4*\mypgfdecoratedpathlength,
amplitude=5},decorate,-{Latex[bend]}
}]
(action) to[bend left=60] node[below=0.5ex] {takes} (agent);
\end{tikzpicture}
\end{document}