4

In the example below you can see an illustration of the problem I have. I would like to draw an error from node s to 6, but I want to clear node 1. It is easy to do using \draw as you can see from the red dotted line. However, I would much rather find the correct option and have it included in the \path command. Grateful for any help.

enter image description here

\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, 
                automata,
                intersections,
                positioning,
                quotes,
                matrix
                }
\usetikzlibrary{shapes,arrows,fit}

\begin{document}


\begin{tikzpicture}[auto, node distance = 30mm and 40mm,
        dot/.style = {circle, fill=red, inner sep=2pt, node contents={}},
every state/.style = {circle, draw=red, very thick},
 every edge/.style = {draw=blue, line width=1pt, -Stealth,
                      shorten >=2pt, shorten <=2pt,
                      },
 every edge quotes/.style = {auto, sloped, inner sep=2pt},
       every label/.style = {rectangle, inner sep=2pt, font=\large},
     mincut/.style = {draw=green!40!black, line width=3pt, dashed}
                                              ]

\node[state]  at (0, 0)  (1) [label=left:{ $ $}] {$1$};
\node[state]  (4) [right= of 1, label=right:{ $ $}] {4};
\node[state]  (2) [above=  of 4, label=above:{ $ $}] {2};
\node[state]  (6) [below right=2 and 1.7 of 4, label=below:{ $ $}] {6};

\node[state]  (s) [above=  of 1, label=above:{ $ $}] {s};


\path       (s) edge["{$5,0$}"]                 (1)
                edge["{$1,0$}"]                 (2)
                edge["{$2,0$} ",out=180,in=200] (6)

            (1) edge["{$2,2$}"]                 (2)
                edge["{$3,1$}"]                 (4)
                edge["{$2,2$}"]                 (6);
                
                
\draw[red,->,very thick,dashed] (s) .. controls (-3,-2) .. (6);

\end{tikzpicture}

\end{document}

5
  • Well, you already found Bézier curves. They take more than one control point: ‘.. controls (1,2) and (2,3) .. ‘ and should ultimately be able to do what you want with a little trial and error.
    – Markus G.
    Jun 18, 2021 at 19:19
  • 1
    And in terms of adding that to your single draw command ( which I personally find a bit questionable) you should be able to just add it using the ‘--‘ syntax instead of ‘edge’.
    – Markus G.
    Jun 18, 2021 at 19:26
  • FYI: I added another option to my answer, which I thought of immediately after posting. Jun 18, 2021 at 20:07
  • @MarkusG. , I have been under the impression, from other post that I have read, that it is better to use \path as opposed to \draw but I don't know why. Can you explain? Jun 19, 2021 at 8:01
  • 1
    Well, \draw is just shorthand for \path[draw] so I rarely ever use \path in my tikzpictures.
    – Markus G.
    Jun 19, 2021 at 8:05

1 Answer 1

5

I wouldn't say using an additional \draw is any less correct, but you can play with the looseness parameter, in addition to the in and out angles. For example,

edge["{$2,0$} ", out=230, in=180, looseness=1.4] (6)

Alternatively, specify a custom path with to path, e.g.

edge["{$2,0$} ", to path={(\tikztostart) .. controls +(-4,-5) and +(-4,-1) ..  (\tikztotarget) \tikztonodes}] (6)

See section 14.13 The To Path operation in the manual.

Below I also used the bbox library to get a better bounding box.

enter image description here

\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, 
                automata,
                intersections,
                positioning,
                quotes,
                matrix,
                bbox % <-- added
                }
\usetikzlibrary{shapes,arrows,fit}

\begin{document}


\begin{tikzpicture}[auto, node distance = 30mm and 40mm,
        dot/.style = {circle, fill=red, inner sep=2pt, node contents={}},
every state/.style = {circle, draw=red, very thick},
 every edge/.style = {draw=blue, line width=1pt, -Stealth,
                      shorten >=2pt, shorten <=2pt,
                      },
 every edge quotes/.style = {auto, sloped, inner sep=2pt},
       every label/.style = {rectangle, inner sep=2pt, font=\large},
     mincut/.style = {draw=green!40!black, line width=3pt, dashed}
                                              ]

\node[state]  at (0, 0)  (1) [label=left:{ $ $}] {$1$};
\node[state]  (4) [right= of 1, label=right:{ $ $}] {4};
\node[state]  (2) [above=  of 4, label=above:{ $ $}] {2};
\node[state]  (6) [below right=2 and 1.7 of 4, label=below:{ $ $}] {6};

\node[state]  (s) [above=  of 1, label=above:{ $ $}] {s};


\path [bezier bounding box] % for improved bounding box calculation, requires bbox library
            (s) edge["{$5,0$}"]                 (1)
                edge["{$1,0$}"]                 (2)
                edge["{$2,0$} ", out=230, in=180, looseness=1.4] (6)
                edge["{$2,0$} ", red, dashed, to path={(\tikztostart) .. controls +(-3,-7) and +(-5,0) ..  (\tikztotarget) \tikztonodes}] (6)

            (1) edge["{$2,2$}"]                 (2)
                edge["{$3,1$}"]                 (4)
                edge["{$2,2$}"]                 (6)
               ;

\end{tikzpicture}

\end{document}
1
  • That is just what I needed. Thanks for the bbox tip also. Jun 18, 2021 at 20:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .