Tikz 有多个箭头进入同一个节点,但不在完全相同的位置

Tikz 有多个箭头进入同一个节点,但不在完全相同的位置

我遇到了一个问题,我有多个箭头进入同一个节点,但它们最终互相覆盖。如何让一个箭头从不同的位置进入节点?

我希望黄色箭头以不同的角度进入,但仍位于圆圈后面

\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, arrows.meta, decorations.shapes}

\begin{document}

\tikzset{decorate sep/.style 2 args={decorate,decoration={shape backgrounds,shape=circle,shape size=#1,shape sep=#2}}}

\begin{tikzpicture}[
    font=\sf \scriptsize,
    >=LaTeX,
    cell/.style={
        rectangle, 
        sharp corners=5mm, 
        draw,
        thick,
        minimum width=1cm,
        minimum height=1cm,
        },
    roundThing/.style={
        circle,
        draw,
        inner sep=-0.5pt,
        minimum height=1cm,
        },
    ]

    \coordinate[](upLeft) at (-2, 1);
    \node[roundThing](roundThing1){roundThing};

    \node[roundThing, below= of roundThing1](roundThing2){roundThing};

    \node[roundThing, below=of roundThing2](roundThing3){roundThing};

    \node[cell, right=of roundThing2](square1){square1};

    \node[cell] (square2) at (-1, -6) {square2};

    \draw[decorate sep={0.5mm}{3mm},fill] (roundThing2) -- (roundThing3);

    \draw[->, red] (square2) |- (roundThing1);
    \draw[->, red] (square2) |- (roundThing2);
    \draw[->, red] (square2) |- (roundThing3);

    \draw[->, blue] (roundThing1) -- (square1);
    \draw[->, blue] (roundThing2) -- (square1);
    \draw[->, blue] (roundThing3) -- (square1);


    \draw[yellow] (square1) |- (upLeft);
    \draw[->, yellow] (upLeft) |- (roundThing1);
    \draw[->, yellow] (upLeft) |- (roundThing2)[xshift=-1cm];
    \draw[->, yellow] (upLeft) |- (roundThing3);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

像这样?

在此处输入图片描述

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, positioning}

\begin{document}
    \begin{tikzpicture}[
            > = LaTeX,
node distance = 4mm and 8mm,
  base/.style = {draw, minimum size=10mm, font=\sffamily\scriptsize},
  cell/.style = {base, thick},
roundThing/.style = {base,circle, inner sep=-0.5pt},
                        ]
\node[roundThing] (rt1) {roundThing};
\node[roundThing, below=of rt1] (rt2) {roundThing};
\node[roundThing, below=of rt2] (rt3) {roundThing};
%
\draw[dotted, very thick, shorten >=0.5mm, shorten <=0.5mm] (rt2) -- (rt3);
%
\node[cell, right=of rt2] (square1) {square1};
\node[cell, below left=of rt3.south] (square2) {square2};
%
\coordinate[above left=of rt1] (upLeft);
% yellow lines
\draw[<-, yellow] (rt1.150) -- ++(150:4mm) -| (upLeft) -| (square1);
\draw[<-, yellow] (rt2.150) -- ++(150:4mm) -| (upLeft);
\draw[<-, yellow] (rt3.150) -- ++(150:4mm) -| (upLeft);
% blue lines
\draw[->, blue] (rt1) edge (square1)
                (rt2) edge (square1)
                (rt3)  to  (square1);
% red lines
\draw[->, red] (square2) |- (rt1);
\draw[->, red] (square2) |- (rt2);
\draw[->, red] (square2) |- (rt3);
    \end{tikzpicture}
\end{document}
  • 如果你写入standalone文档类选项tikz,那么它将加载tikz包,因此你不需要再次加载它
  • 不要使用诸如 等命令\sf\bf在现代LaTeX它们被替换为等\itshape\bfseries
  • 为所有节点定义通用的样式特征是明智的,例如使用名称base并在其中定义,(在您的情况下)draw,,fontminimum size
  • 对于简单的虚线,你不需要decoration.shapes库...

相关内容