TeX - LaTeX Asked on April 7, 2021
I am not sure how to google my issue but here it goes. Say I have a graph that has some nodes and arcs joining these nodes, I want to be able to indicate a path connecting some nodes. I thought I can add some dashed arrows with different colors along the various paths I want and I am able to do it for a few cases but for some other cases, I fail and overall the results look bad.
I am okay with how the paths connecting 1 and 6 are, but I would rather have the arrows green/blue and the labels $t_j$
, $r_j$
black. It will be also nice if I can offset the start and ending locations of the oaths so that they don’t look like they are starting and ending at the same point like the paths. $t_j$
and $r_j$
.
and I am totally unsure how to draw the path from 0 to 7
Any additional beautifications are welcome.
here is my code
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}
Building on the suggestion by Jasper Habicht and removing your own color restrictions, this is what I came up with:
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}
Answered by Markus G. on April 7, 2021
By using the [in=<angle>,out=<angle>]
option provided by tikz
and shifting the ending point of a path as @Jasper Habicht
suggested I've come up with this
notice also that I've added a midpoint: (3-5)
. This is used so that the red arrow does not overlap with the rest of the figure.
If you want to change the distance of the arrow from the figure, change the y
coordinate in the
node (3-5) at (5, -4.0) {};
command.
If you do not like the curve of the red arrow, just play with the [in=<angle>,out=<angle>]
options (also true for the blue and arrows) in the
draw [->, red, thick, dashed] (0) to [out=230,in=180] (3-5) node {color{black}$y_j$} to [out=360,in=300] (7);
command. Notice that in=180
and out=360
are used to keep the line straight as it passes through the (3-5)
node.
If you wish to match the arrow tip colour to its body, remove the [black]
option in >={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}
Answered by sRaviolii on April 7, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP