5

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?

2
  • So, are you trying to cote dimensions? (like technical drawings) if so, check this out: tex.stackexchange.com/q/14901/114143 Commented Sep 27, 2016 at 13:16
  • Hmyeah that's a nice command, but I was really looking for something very simple. :)
    – Geert F
    Commented Sep 30, 2016 at 9:10

1 Answer 1

9

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

3
  • I think the OP wants to have arrows on both ways: not like --->--->---> but like <----><----><---->. Commented Sep 27, 2016 at 19:10
  • 1
    Just replace "->" in the .style with "<->".
    – Derek
    Commented Sep 27, 2016 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? Commented Jul 7, 2019 at 17:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .