在 Tikz 图中创建与一组箭头相邻的虚线箭头

在 Tikz 图中创建与一组箭头相邻的虚线箭头

我不知道如何用谷歌搜索我的问题,但这里可以找到答案。假设我有一个图,其中有一些节点和连接这些节点的弧,我希望能够指示连接一些节点的路径。我想我可以沿着我想要的各种路径添加一些不同颜色的虚线箭头,而且我能够在少数情况下做到这一点,但在其他一些情况下,我失败了,总体结果看起来很糟糕。
在此处输入图片描述

我对连接 1 和 6 的路径的样子还算满意,但我更希望箭头是绿色/蓝色,标签是$t_j$黑色$r_j$。如果我可以偏移誓言的起点和终点位置,让它们看起来不像路径那样从同一点开始和结束,那就太好了。$t_j$$r_j$

我完全不确定如何绘制从 0 到 7 的路径

欢迎任何额外的美化。

这是我的代码

\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{tikzpicture}
        \begin{scope}[every node/.style={circle,thick,draw}]
                \node (0) at (0.0,0.0) {$0$};
                \node (1) at (2.0,-1.5) {$1$};
                \node (2) at (3.5, 0.0) {2};
                \node (3) at (3.5,-3.0) {3};
                \node (4) at (6.5,0.0) {4};
                \node (5) at (6.5,-3.0) {5};
                \node (6) at (8.0,-1.5) {6};
                \node (7) at (10,0) {7};
        \end{scope}
        \begin{scope}[>={Stealth[black]},
                      every node/.style={fill=white,circle, inner sep=0pt,minimum size=1pt},
                      every edge/.style={draw=black,very thick}]
            \path [->] (0) edge[bend right=30] node {}  (3);
            \path [->] (1) edge node {} (2);
            \path [->] (1) edge node {} (3);
            \path [->] (2) edge node  {} (4);
            \path [->] (3) edge node {} (5); 
            \path [->] (4) edge node {} (6); 
            \path [->] (5) edge node {}  (6); 
            \path [->] (5) edge[bend right=30] node {} (7); 
            \path [red, thick ,dashed, ->] (0) edge[bend right=105] node {$y_j$} (7);
            \path [blue, thick, dashed, ->] (1) edge[bend right=40] node {{$r_j$}} (6);
            \path [green, thick, dashed, ->] (1) edge[bend left=40] node {{$t_j$}} (6);
        \end{scope}
        \end{tikzpicture}

答案1

根据以下建议贾斯珀·哈比希特并消除您自己的颜色限制,这就是我想出的:

\begin{document}
\begin{tikzpicture}
    \begin{scope}[every node/.style={circle,thick,draw}]
        \node (0) at (0.0,0.0) {$0$};
        \node (1) at (2.0,-1.5) {$1$};
        \node (2) at (3.5, 0.0) {2};
        \node (3) at (3.5,-3.0) {3};
        \node (4) at (6.5,0.0) {4};
        \node (5) at (6.5,-3.0) {5};
        \node (6) at (8.0,-1.5) {6};
        \node (7) at (10,0) {7};
        \coordinate (8) at (5.0,-3.6);
    \end{scope}
    \begin{scope}[>={Stealth},
        num/.style={text=black, fill=white,circle, inner sep=0pt,minimum size=1pt},
        every edge/.style={draw,very thick}]
        \path [->] (0) edge[bend right=30] (3);
        \path [->] (1) edge node {} (2);
        \path [->] (1) edge node {} (3);
        \path [->] (2) edge node  {} (4);
        \path [->] (3) edge node {} (5); 
        \path [->] (4) edge node {} (6); 
        \path [->] (5) edge node {}  (6); 
        \path [->] (5) edge[bend right=30] (7); 
        \draw [red, thick ,dashed, ->] (0)  to[out=275,in=175] (8) to[out=0,in=270] (7) ;
        \node[num] at (8) {$y_j$};
        \path [blue, thick, dashed, ->] (1) edge[out=330,in=210] node[num] {{$r_j$}} (6);
        \path [green, thick, dashed, ->] (1) edge[out=30,in=150] node[num] {{$t_j$}} (6);
    \end{scope}
\end{tikzpicture}
\end{document}

编译的 tikz-figure

答案2

通过使用[in=<angle>,out=<angle>]提供的选项tikz并将路径的终点移动为@Jasper Habicht 建议我想出这个 蒂克兹
还要注意,我添加了一个中点:(3-5)。这样使用是为了使红色箭头不与图形的其余部分重叠。
如果要更改箭头与图形的距离,请y更改

\node (3-5) at (5, -4.0) {};

命令。

[in=<angle>,out=<angle>]如果你不喜欢红色箭头的曲线,只需使用

\draw [->, red, thick, dashed] (0) to [out=230,in=180] (3-5) node {\color{black}$y_j$} to [out=360,in=300] (7);

命令。请注意,in=180out=360用于使线在穿过(3-5)节点时保持笔直。

如果您希望箭头颜色与箭头主体相匹配,请删除[black]中的选项>={Stealth[black]}

代码

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}
    \begin{scope}[every node/.style={circle,thick,draw}]
        \node (0) at (0.0,0.0)  {$0$};
        \node (1) at (2.0,-1.5) {$1$};
        \node (2) at (3.5, 0.0) {$2$};
        \node (3) at (3.5,-3.0) {$3$};
        \node (4) at (6.5,0.0)  {$4$};
        \node (5) at (6.5,-3.0) {$5$};
        \node (6) at (8.0,-1.5) {$6$};
        \node (7) at (10,0) {7};
        \node (3-5) at (5, -4.0) {};
    \end{scope}
    \begin{scope}
    [
        >={Stealth[black]},
        every node/.style={fill=white,circle, inner sep=0pt,minimum size=1pt},
        every edge/.style={draw=black,very thick}
    ]
        \path [->] (0) edge[bend right=30] node {}  (3);
        \path [->] (1) edge node {} (2);
        \path [->] (1) edge node {} (3);
        \path [->] (2) edge node {} (4);
        \path [->] (3) edge node {} (5); 
        \path [->] (4) edge node {} (6); 
        \path [->] (5) edge node {}  (6); 
        \path [->] (5) edge[bend right=30] node {} (7);

        \draw [->, red, thick, dashed] (0) to [out=230,in=180] (3-5) node {\color{black}$y_j$} to [out=360,in=300] (7);
        \draw [->, blue, thick, dashed]  ([yshift=-2pt]1.east) to [out=-50,in=-130] node {\color{black}$r_j$} ([yshift=-2pt]6.west);
        \draw [->, green, thick, dashed] ([yshift=2pt]1.east) to [out=50,in=130] node {\color{black}$t_j$} ([yshift=2pt]6.west);
    \end{scope}
\end{tikzpicture}
\end{document}

相关内容