4

So I am trying to add an arrow to a path of the figure-8 knot to indicate its orientation, but I can't seem to get it visible on the diagram. I'm a beginner in TikZ and any help would be appreciated. This is my code:

\documentclass{article}

\usepackage{graphicx,amssymb,amstext,amsmath}

\usepackage{tikz}
\usepackage{braids}
\usepackage{wrapfig}
\usepackage{blindtext}
\usetikzlibrary{decorations.pathreplacing,decorations.markings,hobby,knots,celtic,shapes.geometric,calc}


\tikzset{
  knot diagram/every strand/.append style={
    line width=3pt,violet
  },
  show curve controls/.style={
    postaction=decorate,
    decoration={show path construction,
      curveto code={
        \draw [blue, dashed]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentsupporta)
        node [at end, draw, solid, red, inner sep=2pt]{};
        \draw [blue, dashed]
        (\tikzinputsegmentsupportb) -- (\tikzinputsegmentlast)
        node [at start, draw, solid, red, inner sep=2pt]{}
        node [at end, fill, blue, ellipse, inner sep=2pt]{}
        ;
      }
    }
  },
  show curve endpoints/.style={
    postaction=decorate,
    decoration={show path construction,
      curveto code={
        \node [fill, blue, ellipse, inner sep=2pt] at (\tikzinputsegmentlast) {}
        ;
      }
    }
  }
}

\begin{center}
\begin{tikzpicture}[use Hobby shortcut, postaction={decorate}, decoration={
  markings,
  mark=at position 0.2 with {\arrow[line width=3pt]{<}}}]
\begin{knot}[
  consider self intersections=true,
%  draft mode=crossings,
  ignore endpoint intersections=false,
  flip crossing=3,
  rotate=180,
]
\strand ([closed]0,0) .. (1.5,1) .. (.5,2) .. (-.5,1) .. (.5,0) .. (0,-.5) .. (-.5,0) .. (.5,1) .. (-.5,2) .. (-1.5,1) .. (0,0);
\end{knot}
\path (0,-.7);
\end{tikzpicture}
JpW
  • 119
  • Welcome to TeX.SE! A way to draw more attention to your question is to make sure that the code can be compiled (yours is missing a \begin{document} as well as \end{center} \end{document}), loads only the necessary packages (you can kick out \usepackage{graphicx,amssymb,amstext,amsmath}\usepackage{wrapfig}\usepackage{blindtext}, none of which is used, as well as several tikz libraries). Sometimes it helps to add a sketch of what you want to achieve. –  Feb 02 '19 at 21:12

1 Answers1

6

Welcome to TeX.SE! In order to "employ" the decoration, you need to add it to the path. To do so, I gave your decoration a name

add arrow/.style={postaction={decorate}, decoration={
  markings,
  mark=at position 0.5 with {\arrow[line width=3pt]{<}}}}

and then added it to the path \strand[add arrow] ....

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{braids}
\usetikzlibrary{decorations.markings,hobby,knots,celtic}

\begin{document}
\tikzset{
  knot diagram/every strand/.append style={
    line width=3pt,violet
  },
}

\begin{tikzpicture}[use Hobby shortcut,
 add arrow/.style={postaction={decorate}, decoration={
  markings,
  mark=at position 0.5 with {\arrow[line width=3pt]{<}}}}]
\begin{knot}[
  consider self intersections=true,
%  draft mode=crossings,
  ignore endpoint intersections=false,
  flip crossing=3,
  rotate=180,
]
\strand[add arrow] ([closed]0,0) .. (1.5,1) .. (.5,2) .. (-.5,1) .. (.5,0) .. (0,-.5) .. (-.5,0) .. (.5,1) .. (-.5,2) .. (-1.5,1) .. (0,0);
\end{knot}
\path (0,-.7);
\end{tikzpicture}
\end{document}

enter image description here

Note that I had to use a somewhat different value for the position since with 0.2 there are dimension too large errors.

If you want just a single arrow, consider e.g.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{braids}
\usetikzlibrary{decorations.markings,hobby,knots,celtic}

\begin{document}
\tikzset{
  knot diagram/every strand/.append style={
    line width=3pt,violet
  },
}

\begin{tikzpicture}[use Hobby shortcut,
 add arrow/.style={postaction={decorate}, decoration={
  markings,
  mark=at position 0.5 with {\arrow[line width=3pt]{<}}}}]
\begin{knot}[
  consider self intersections=true,
%  draft mode=crossings,
  ignore endpoint intersections=false,
  flip crossing=3,
  rotate=180
]
\strand ([closed]0,0) .. (1.5,1) .. (.5,2) [add arrow,violet] .. (-.5,1) .. (.5,0) .. (0,-.5) .. (-.5,0) .. (.5,1) .. (-.5,2) .. (-1.5,1) .. (0,0);
%\redraw{2}{(1,1)}
\end{knot}
\path (0,-.7);
\end{tikzpicture}
\end{document}

enter image description here

Note that this works by accident here.

  • Thank you! Is there a way to add an arrow to a single segment (ie. not add arrows at every single strand, because it can make some graphs look slightly confusing, especially in the crossing areas)? – JpW Feb 03 '19 at 13:52
  • 1
    @JpW I added a possible way. Alternatively one could mark some positions on the last stretch and then use these positions to draw the path with an arrow on top. –  Feb 03 '19 at 15:28