具有可变节点大小和位置的对称接触箭头

具有可变节点大小和位置的对称接触箭头

我寻找一种解决方案,用于在中点处使用对称接触箭头,并且由于内容变化而具有可变节点大小。薛定谔的猫已经帮助我获得了以下代码:

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\node(A){A};
\node[below = of A](B){B};
\node[left = of A](C){C};
\node[right = of A](D){D};
\node[left = of B](E){E};
\node[right = of B](F){F};
\path (barycentric cs:A=1,B=1,D=1,F=1) coordinate (ABDF)
 (barycentric cs:A=1,B=1,C=1,E=1) coordinate (ABCE);
\draw[->] (B.east) to[out=45,in=-90] (ABDF) to[out=90,in=-45] (A.east);
\draw[->] (F.west) to[out=135,in=-90] (ABDF) to[out=90,in=-135] (D.west);
\draw[->] (A.west) to[out=-135,in=90] (ABCE) to[out=-90,in=135] (B.west);
\draw[->] (C.east) to[out=-45,in=90] (ABCE) to[out=-90,in=45]  (E.east);
\end{scope}
\end{tikzpicture}
\end{document}

只要您不用不同的内容替换字母,此示例看起来就很好。但是,我将使用不同的内容,并因此使用不同的节点大小和节点坐标。

如果用文字代替字母 A、B、C、D、E 和 F,对称性就会消失。请看以下示例:

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\node(A){A};
\node[below = of A](B){Hello};
\node[left = of A](C){Tree};
\node[right = of A](D){Road};
\node[left = of B](E){Car};
\node[right = of B](F){Children's doll};
\path (barycentric cs:A=1,B=1,D=1,F=1) coordinate (ABDF)
 (barycentric cs:A=1,B=1,C=1,E=1) coordinate (ABCE);
\draw[->] (B.east) to[out=45,in=-90] (ABDF) to[out=90,in=-45] (A.east);
\draw[->] (F.west) to[out=135,in=-90] (ABDF) to[out=90,in=-135] (D.west);
\draw[->] (A.west) to[out=-135,in=90] (ABCE) to[out=-90,in=135] (B.west);
\draw[->] (C.east) to[out=-45,in=90] (ABCE) to[out=-90,in=45]  (E.east);
\end{scope}
\end{tikzpicture}
\end{document}

如何轻松控制不同内容的箭头的对称性?

答案1

这里有些东西可能朝着正确的方向发展。它不是绝对对称的,因为节点的布局已经不是绝对对称的。现在重心是根据起始和结束锚点而不是节点中心来计算的。还引入了倾斜来解释这样一个事实:上部节点(或更准确地说,它们的起始锚点)的水平位置重心与下部节点的相应水平位置不一致。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,positioning}
\begin{document}
\begin{tikzpicture}[get slope/.style n args={4}{insert path={
 let \p1=($($(#1)!0.5!(#2)$)-($(#3)!0.5!(#4)$)$),\n1={atan2(\y1,\x1)} in
 }}]
 % usage: #1=top left, #2=top right, #3=bottom left, #4=bottom right
\begin{scope}
\node(A){A};
\node[below = of A](B){Hello};
\node[left = of A](C){Tree};
\node[right = of A](D){Road};
\node[left = of B](E){Car};
\node[right = of B](F){Children's doll};
\path (A.east) coordinate (A0) (F.west) coordinate (F0) 
 (B.east) coordinate (B0)  (D.west) coordinate (D0) 
  (barycentric cs:A0=1,F0=1,B0=1,D0=1) coordinate (ABDF)
 (A.west) coordinate (A1)  (B.west) coordinate (B1) 
 (C.east) coordinate (C1)  (E.east) coordinate (E1) 
 (barycentric cs:A1=1,B1=1,C1=1,E1=1) coordinate (ABCE);
\draw[->,get slope={A0}{D0}{B0}{F0}]
 (B0) to[out=45,in=\n1-180] (ABDF) to[out=\n1,in=-45] (A0);
\draw[->,get slope={A0}{D0}{B0}{F0}]
 (F0) to[->,out=135,in=\n1-180] (ABDF) to[out=\n1,in=-135] (D0);
\draw[->,get slope={C1}{A1}{E1}{B1}] 
 (A1) to[out=-135,in=\n1] (ABCE) to[out=\n1-180,in=135] (B1);
\draw[->,,get slope={C1}{A1}{E1}{B1}] 
 (C1) to[out=-45,in=\n1] (ABCE) to[out=\n1-180,in=45]  (E1);
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

虽然我认为这看起来很合理,但是对于任意节点配置,这种方法不一定能产生合理的结果,比如说,三个节点聚集在一个点周围,而第四个节点距离很远。

相关内容