6

I try to rebuild a graph within tikz. This Graph has some edges which have an arrow underneath of them. Important for me is the bend which should be the same as the red edges. Not like in the reference picture where the arrows are not perfectly fit into the edge flow.

image description here

Thats how my current graph looks like:

image description here

The problem I have is that I am not able to create those curved edges with an arrow tip. So that they are this short as you can the in the reference picture and bending correctly.

Thats my code on some tests:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning,decorations.markings}

\begin{document}
    \begin{tikzpicture}[nodes={draw,circle},decoration={markings, mark=at position 0.5 with {\arrow[scale=1.5,>=stealth,color=black]{>}}}]
        \node (A) at (0,0) {A};
        \node[right=5cm of A] (B) {B};

        \draw[postaction={decorate}, color=white] (A) to[out=-45, in=-135] (B);
        \path[shorten >=40pt,shorten <=40pt,->] (A) edge[bend left] (B);
        \path[dashed] (A) edge[bend left] (B);
    \end{tikzpicture}
\end{document}

enter image description here

As you can see I can get it somehow smaller than the actual edge. But using higher values for shorten only makes the edge looks very weird and offsets its position even more. Using the method with a white edge will fit perfectly my arrow on the edge but it does not have a little tail.

I do have already skimmed through the 3.xx manual of pgf and tikz but could not really find anything that fit my needs.

2 Answers 2

4
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{backgrounds,decorations.markings}
\begin{document}
\begin{tikzpicture}[nodes={draw,circle,fill=gray!20,text
  width=width("52"),align=center},
  record points/.style={postaction=decorate,decoration={markings,
  mark={at position 0.4 with {\coordinate(#1-1);}},
  mark={at position 0.5 with {\coordinate(#1-2);}},
  mark={at position 0.6 with {\coordinate(#1-3);}},
  mark={at position 0.7 with {\coordinate(#1-4);}}}}]

  \path (0,0) node (s) {s} (-5,2) node (53) {53} (-5,0) node (52) {52}
  (-5,-2) node (51) {51};
  \begin{scope}[on background layer]
  \draw[line width=6pt,red!10,record points=T]
  ([yshift=6pt]s.center) to[out=170,in=-45] 
   (53.center);
  \draw[line width=6pt,red!10,record points=M]
  ([yshift=0pt]s.center) to (52.center);
  \draw[line width=6pt,red!10,record points=B]
  ([yshift=-6pt]s.center) to[out=190,in=45] (51.center);
  \end{scope}
  \foreach \X in {T,M,B}
  {\draw[-latex] plot[smooth,variable=\x,samples at={1,...,4}](\X-\x);}
\end{tikzpicture}
\end{document}

enter image description here

2

You can't really use shorten >/shorten < with curves since they shorten the path on a straight tangent, really deforming the path somewhat. (Though, this is barely noticeable with straight-ish curves.)

With the bending library, this can be either achieved by redrawing the path between times via the show path construction decoration or by shortening the path via the arrow seperation. (Without the bending library the latter would look the same as with the normal shortening.)

The rest of the answer is similar to other one, especially the use of the backgrounds library and the on background layer key.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{matrix, arrows.meta, bending, backgrounds, decorations.pathreplacing}
\tikzset{
  partial curve/.style args={[#1]#2:#3}{
    postaction=decorate,
    decoration={
      name=show path construction,
      curveto code={\draw[{#1}]\pgfextra{\pgfpathcurvebetweentime{#2}{#3}{\pgfpointdecoratedinputsegmentfirst}{\pgfpointdecoratedinputsegmentsupporta}{\pgfpointdecoratedinputsegmentsupportb}{\pgfpointdecoratedinputsegmentlast}};},
      lineto code={\draw[{#1}]\pgfextra{\pgfpathmoveto{\pgfpointlineattime{#2}{\pgfpointdecoratedinputsegmentfirst}{\pgfpointdecoratedinputsegmentlast}}\pgfpathlineto{\pgfpointlineattime{#3}{\pgfpointdecoratedinputsegmentfirst}{\pgfpointdecoratedinputsegmentlast}}};}}},
  nudge/.style={shift={(#1:5pt)}},
  @/.style 2 args={n#1/.style={nudge=#1#2}}, @/.list={left, right, up, down}}
\begin{document}
\begin{tikzpicture}[
  >=Latex,
  pc/.style={every edge/.append style={
    draw=pink, line width=+1.5ex,
    partial curve={[draw=black, thick, ->].25:.75}}}]
\matrix[row sep=1.5cm, column sep=3cm, matrix of nodes,
  nodes={shape=circle, draw, fill=lightgray, align=center,
         text height=height("0"), text depth=+0pt, text width=width("00")},
] (m) { 53 \\ 52 & s \\ 51 & & 00 \\};
\scoped[on background layer]
  \path[pc] (m-2-2.center) edge (m-2-1.center)
            ([nd]m-2-2.center) edge[out=200, in= 45] (m-3-1.center)
            ([nu]m-2-2.center) edge[out=160, in=-45] (m-1-1.center)
            (m-2-2.center) edge[overlay, out=-90, distance=5cm, in=90] (m-3-3.center);
\end{tikzpicture}
\begin{tikzpicture}[
  >=Latex,
  pc/.style={every edge/.append style={
    draw=pink, line width=+1.5ex,
    postaction={draw=black, thick, {_[sep=+40pt]->[sep=+40pt]}}}}]
\matrix[row sep=1.5cm, column sep=3cm, matrix of nodes,
  nodes={shape=circle, draw, fill=lightgray, align=center,
         text height=height("0"), text depth=+0pt, text width=width("00")},
] (m) { 53 \\ 52 & s \\ 51 & & 00 \\};
\scoped[on background layer]
  \path[pc] (m-2-2.center) edge (m-2-1.center)
            ([nd]m-2-2.center) edge[out=200, in= 45] (m-3-1.center)
            ([nu]m-2-2.center) edge[out=160, in=-45] (m-1-1.center)
            (m-2-2.center) edge[overlay, out=-90, distance=5cm, in=90] (m-3-3.center);
\end{tikzpicture}
\end{document}

Output

enter image description hereenter image description here

You must log in to answer this question.

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