4

I would like to draw a single path with relative coordinates, where every segment gets their arrow tips. I have tried

\draw[<->] (0,0) -- ++(1,0) -- ++(1,0) -- ++(1,0);

But of course, as is specified in the manual, this adds arrow tips to the first and last subpaths only, of course, so it becomes something like <------------>, whereas I would like it to be <---><---><--->. I have read Drawing an arrow tip to every node of a path and know that an edge will give me arrow tips on every edge, but then I can't use incremental coordinates. (I am actually trying to do the exact same thing that @quinmars is doing in that question.)

Since the answer to that question is 5 years old, I was hoping that either TikZ or somebody else may have an elegant solution to this?

5

For straight lines only, maybe a bit like this?

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{decorations}
\pgfdeclaredecoration{arrows}{draw}{
\state{draw}[width=\pgfdecoratedinputsegmentlength]{%
  \path [every arrow subpath/.try] \pgfextra{%
    \pgfpathmoveto{\pgfpointdecoratedinputsegmentfirst}%
    \pgfpathlineto{\pgfpointdecoratedinputsegmentlast}%
   };
}}
\tikzset{every arrow subpath/.style={->, draw, thick}}
\begin{document}
\begin{tikzpicture}
  \path [decoration=arrows, decorate](0,0) -- ++(1,0) -- ++(0,1) -- ++(45:1);
\end{tikzpicture}
\end{document}

enter image description here

  • I think the OP wants to have arrows on both ways: not like --->--->---> but like <----><----><---->. – Guilherme Zanotelli Sep 27 '16 at 19:10
  • 1
    Just replace "->" in the .style with "<->". – Derek Sep 27 '16 at 20:08
  • It there a way to modify this so that styles declared on the \path are inherited? For example, so that \path [decoration=arrows, decorate, green] would make the path green? – Jason Siefken Jul 7 at 17:31

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.