11

I want to add a multitude of marks to a single path. However, sometimes these marks are heavily misplaced. For example, the blue arrows should be a little bit ahead of the red ones.

\begin{tikzpicture}
    \draw plot[smooth, tension=.7] coordinates { (5*0.02109, 5*-0.12607)(5*0.2274, 5*-0.1806)(5*0.4037, 5*-0.02751)(5*0.536, 5*0.4091)(5*0.768, 5*0.2045)(5*0.7262, 5*-0.02055)(5*0.8538, 5*-0.1366) }
        [postaction={decorate}, decoration={markings,
            % Red arrows
            mark=between positions 0.1 and 0.9 step 0.25 with {\arrow[red, line width=1mm]{>};},
            % Blue arrows
            mark=between positions 0.2 and 0.9 step 0.25 with {\arrow[blue, line width=1mm]{>};}
        }]
        ;
\end{tikzpicture}

enter image description here

  • While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Dec 11 '11 at 4:43
  • 4
    Have you tried adding a second postaction? Any number are allowed, and they are executed in order. – Ryan Reich Dec 11 '11 at 5:07
  • 4
    Incidentally, the problem with the original code was that you were marking the path with marks out of order and this is Expressly Forbidden in the manual. Splitting the decoration in two circumvents this restriction as in involves a double-pass on the path. – Loop Space Dec 11 '11 at 8:22
  • @AndrewStacey, I found it now that you mentioned it, page 328. It's a little hard to notice that sentence when you're just skimming the manual for the information you need. – David Dec 11 '11 at 17:48
  • I agree that it's an obscure detail and my comment was purely to ensure that the explanation is on this page somewhere as otherwise it's not clear to others why your original code doesn't work. I think it's a good question and a neat solution. – Loop Space Dec 11 '11 at 19:11
14

Ryan Reich's (thanks!) comment was the solution: multiple postactions. Note that every "decoration block" needs its own decorate postaction.

\begin{tikzpicture}
    \draw plot[smooth, tension=.7] coordinates { (5*0.02109, 5*-0.12607)(5*0.2274, 5*-0.1806)(5*0.4037, 5*-0.02751)(5*0.536, 5*0.4091)(5*0.768, 5*0.2045)(5*0.7262, 5*-0.02055)(5*0.8538, 5*-0.1366) }
        [postaction={decorate, decoration={markings,
            % Red arrows
            mark=between positions 0.1 and 0.9 step 0.25 with {\arrow[red, line width=1mm]{>};}
        }}]
        [postaction={decorate, decoration={markings,
            % Blue arrows
            mark=between positions 0.2 and 0.9 step 0.25 with {\arrow[blue, line width=1mm]{>};}
        }}]
        ;
\end{tikzpicture}

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.