Tikz:防止箭头与DAG图中的节点重叠

Tikz:防止箭头与DAG图中的节点重叠

我想知道是否有办法防止箭头与节点 E、F、G、H 重叠。也许可以稍微移动箭头,同时仍保持线条平滑,不会突然改变方向。谢谢。

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning,calc,arrows.meta}%arrows is deprecated

\begin{document}

\begin{tikzpicture}[->,>=Stealth,auto,
  thick,main node/.style={draw, rectangle, align=center, text width=1cm}]

\node[main node, ] (1) at (0,8)    {A};
\node[main node, anchor=north west] (2) at(1.north east) {B};
\node[main node, anchor=north west] (3) at(2.north east) {C};
\node[main node, anchor=south west] (4) at(3.north east) {D};

\node[main node, ] (5) at (-0.5,4)    {E};
\node[main node, anchor=north west] (6) at(5.north east) {F};
\node[main node, anchor=north west] (7) at(6.north east) {G};
\node[main node, anchor=north west] (8) at(7.north east) {H};
\node[main node, anchor=south west] (9) at(8.north east) {I};

\node[main node, ] (10) at (-4,0)   {A};
\node[main node, anchor=north west] (11) at(10.north east) {B};
\node[main node, anchor=north west] (12) at(11.north east) {C};
\node[main node, anchor=south west] (13) at(12.north east) {D};

\node[main node, ] (14) at (4,0)   {A};
\node[main node, anchor=north west] (15) at(14.north east) {B};
\node[main node, anchor=north west] (16) at(15.north east) {C};
\node[main node, anchor=south west] (17) at(16.north east) {D};

\draw (1.south) to[out=-90, in=90, looseness=1.2]  (10.north);
\draw (2.south) to[out=-90, in=90, looseness=1.2] (11.north);
\draw (3.south) to[out=-90, in=90, looseness=1.2] (12.north);

\draw (1.south) to[out=-90, in=90, looseness=1.2] (5.north);
\draw (2.south) to[out=-90, in=90, looseness=1.2] (6.north);

\draw (1.south) to[out=-90, in=90, looseness=1.2] (14.north);
\draw (2.south) to[out=-90, in=90, looseness=1.2] (15.north);
\draw (3.south) to[out=-90, in=90, looseness=1.2] (16.north);

\draw [red] (9.north) to[out=90, in=-90, looseness=1.2] (4.south);
\draw (13.north) to[out=90, in=-90, looseness=1.2] (8.south);
\draw (17.north) to[out=90, in=-90, looseness=1.2] (7.south);

\end{tikzpicture}

\end{document}

在此处输入图片描述

答案1

in只需调整和的角度即可out。由于右下角节点的位置,您还需要稍微移动它们。

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning,calc,arrows.meta}%arrows is deprecated

\begin{document}
    \resizebox{\textwidth}{!}{
    \begin{tikzpicture}[->,>=Stealth,auto,
        thick,main node/.style={draw, rectangle, align=center, text width=1cm}]
        
        \node[main node, ] (1) at (0,8)    {A};
        \node[main node, anchor=north west] (2) at(1.north east) {B};
        \node[main node, anchor=north west] (3) at(2.north east) {C};
        \node[main node, anchor=south west] (4) at(3.north east) {D};
        
        \node[main node, ] (5) at (-0.5,4)    {E};
        \node[main node, anchor=north west] (6) at(5.north east) {F};
        \node[main node, anchor=north west] (7) at(6.north east) {G};
        \node[main node, anchor=north west] (8) at(7.north east) {H};
        \node[main node, anchor=south west] (9) at(8.north east) {I};
        
        \node[main node, ] (10) at (-5,0)   {A};
        \node[main node, anchor=north west] (11) at(10.north east) {B};
        \node[main node, anchor=north west] (12) at(11.north east) {C};
        \node[main node, anchor=south west] (13) at(12.north east) {D};
        
        \node[main node, ] (14) at (6.2,0)   {A};
        \node[main node, anchor=north west] (15) at(14.north east) {B};
        \node[main node, anchor=north west] (16) at(15.north east) {C};
        \node[main node, anchor=south west] (17) at(16.north east) {D};
        
        \draw (1.south) to[out=-140, in=120, looseness=1.2]  (10.north);
        \draw (2.south) to[out=-140, in=120, looseness=1.2] (11.north);
        \draw (3.south) to[out=-140, in=120, looseness=1.2] (12.north);
        
        \draw (1.south) to[out=-90, in=90, looseness=1.2] (5.north);
        \draw (2.south) to[out=-90, in=90, looseness=1.2] (6.north);
        
        \draw (1.south) to[out=-15, in=70, looseness=1.2] (14.north);
        \draw (2.south) to[out=-15, in=70, looseness=1.2] (15.north);
        \draw (3.south) to[out=-15, in=70, looseness=1.2] (16.north);
        
        \draw [red] (9.north) to[out=90, in=-90, looseness=1.2] (4.south);
        \draw (13.north) to[out=90, in=-90, looseness=1.2] (8.south);
        \draw (17.north) to[out=90, in=-90, looseness=1.2] (7.south);
        
    \end{tikzpicture}
}
\end{document}

请注意,由于默认边距非常大,我只是\resizebox想调整尺寸,您可以根据需要进行调整。

在此处输入图片描述

相关内容