15

I want to draw an arrow tip to every node/coordinate in a path. But tikz draws them only to the first and last point. Is there an option for that purpose? Or have I to splitt the path into its single parts?

Here is an example:

enter image description here

\documentclass{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    % What should I add to this:
    \draw  [|<->|] (0.4,2.4) to node[right] {$L$} ++(0,-1.5)
            to node[right] {$d$} ++(0,-1)
            to node[right] {$h$} ++(0,-1);
    % To get:
    \draw  [|<->|] (0.8,2.4) to node[right] {$L$} (0.8,0.9);
    \draw  [|<->|] (0.8,0.9) to node[right] {$d$} (0.8,-0.1);
    \draw  [|<->|] (0.8,-0.1) to node[right] {$h$} (0.8,-1.1);

    \end{tikzpicture}
\end{document}
1
  • 2
    I am pretty sure you have to split the path in separate parts. You can of course use a for loop to draw the separate paths, minimizing the amount of repetitive code. – Roelof Spijker Nov 15 '11 at 17:36
11

Your first command only creates one path and TikZ will apply the arrowheads to the end of that path. So you need to create separate paths for the individual bits. One relatively quick way to insert subpaths into a statement is the edge command:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \path[|<->|]
             (0.4,2.4) edge node[right] {$L$} +(0,-1.5)
            ++(0,-1.5) edge node[right] {$d$} +(0,-1)
            ++(0,-1)   edge node[right] {$h$} +(0,-1);
    \end{tikzpicture}
\end{document}

The only drawback is that edge doesn't advance the current position, so that you have to repeat the coordinates. Also you need to use \path instead of \draw to avoid the drawing of an empty path with arrowheads.

1
  • Fair enough, I hoped there is a way with out repeating the values. But is at least better then to calculate the coordinates by hand. Thanks! – quinmars Nov 16 '11 at 11:56

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.