If I want to draw a curve with an arrow somewhere along its length (say 40% along), I can write this:

\draw [decoration={
             mark=at position 0.4 with \arrow{>}}
       (A) to (B);

If I want to draw lots of curves with the same decoration, I can put most of this in a scope and reduce how much I have to type for each path.

However, if I want to draw lots of curves with different parameters - say, each one needs to have the arrow at a different position, and the choice of < or > could vary between curves. Then it seems I have a lot of typing to do for each curve.

What I'd like to do is define something like this:

             mark=at position #1 with \arrow{#2}}

Then I can draw my arrows with ease:

\draw [\arrowdata{0.3}{>}] (A) to (B);
\draw [\arrowdata{0.95}{<}] (C) to (D) to (E);

and so on. But, this doesn't work, and I don't understand the error messages that result. Clearly I'm being too naive in my understanding of how macros apply in TikZ. Can someone help me out?


Macros in style definitions don't work if they aren't expanded beforehand. You should define your own style instead.

\tikzset{arrow data/.style 2 args={%
         mark=at position #1 with \arrow{#2}},

The use it like:

\draw [arrow data={0.3}{>}] (A) to (B);

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.