Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

\draw [decoration={
             markings,
             mark=at position 0.4 with \arrow{>}}
       ,postaction=decorate]
       (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:

\newcommand\arrowdata[2]{decoration={
             markings,
             mark=at position #1 with \arrow{#2}}
       ,postaction=decorate}

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?

share|improve this question

1 Answer 1

up vote 10 down vote accepted

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={%
      decoration={%
         markings,
         mark=at position #1 with \arrow{#2}},
         postaction=decorate}
      }%
}

The use it like:

\draw [arrow data={0.3}{>}] (A) to (B);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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