1

In Arrowhead angle in tikz a solution for the bad angling of arrowheads is given using the bending library.

My problem: in the "keyhole circuit" drawing

Keyhole circuit

produced with the code

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,bending}

\begin{document}
\begin{tikzpicture}
[decoration={markings,mark=at position 1.2cm with {\arrow[line width=1pt]{stealth}},mark=at position 8cm with {\arrow[line width=1pt]{stealth}},mark=at position 18.7cm with {\arrow[line width=1pt]{stealth}},mark=at position 20.65cm with {\arrow[line width=1pt]{stealth[flex=1]}}}]
\path[draw,line width=0.8pt,postaction=decorate] (10:0.5) -- +(2,0) arc (2:358:2.5) -- +(-2,0) arc (-9.5:-350.5:0.5);
\end{tikzpicture}

\end{document}

the flex=1 is ignored. Why? Where the flex=... is required? I've tried several positions. Almost all give errors.

  • In order to use flex with an effect you need to use arrows.meta and then Stealth[flex=1]. You do not load arrows.meta so the option does not even get parsed. The answer you are referring to is unfortunately not too accurate either. – Schrödinger's cat Sep 29 at 14:51
  • @Schrödinger'scat, I've added arrows.meta and changed [flex=1] to Stealth[flex=1]. The effect is a greater arrowhead and no angling correction. Do you want the new code and drawing? – Martín-Blas Pérez Pinilla Sep 29 at 14:59
  • 1
    The reason is that when you use decorations.markings in the usual way, the only thing that is known at the point you draw the arrow is the tangent and nothing beyond. In particular, the curvature is set to zero. So you need to make the arrow aware of the shape of the curve around this location, which is what the answer below does. – Schrödinger's cat Sep 29 at 15:03
1

You need to load arrows.meta to make use of flex, and then the correct syntax is Stealth[flex] rather than stealth[flex]. However, I would bend the arrows along the paths.

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,bending,arrows.meta}
\tikzset{% https://tex.stackexchange.com/a/430239
    arc arrow/.style args={%
    to pos #1 with length #2}{
    decoration={
        markings,
         mark=at position 0 with {\pgfextra{%
         \pgfmathsetmacro{\tmpArrowTime}{#2/(\pgfdecoratedpathlength)}
         \xdef\tmpArrowTime{\tmpArrowTime}}},
        mark=at position {#1-\tmpArrowTime} with {\coordinate(@1);},
        mark=at position {#1-2*\tmpArrowTime/3} with {\coordinate(@2);},
        mark=at position {#1-\tmpArrowTime/3} with {\coordinate(@3);},
        mark=at position {#1} with {\coordinate(@4);
        \draw[-{Stealth[length=#2,bend]}]       
        (@1) .. controls (@2) and (@3) .. (@4);},
        },
     postaction=decorate,
     },starc arrow/.style={arc arrow=to pos #1 with length 3.14mm}
}

\begin{document}
\begin{tikzpicture}
\path[draw,line width=0.8pt,postaction=decorate,starc arrow/.list={0.06,0.33,0.86,0.94}] (10:0.5) -- +(2,0) arc (2:358:2.5) -- +(-2,0) arc (-9.5:-350.5:0.5);
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.