[Tex/LaTex] Specify the length of the arrow in TikZ

tikz-pgf

This should be an easy one. Instead of specifying where the start and finish of the arrow should be, I want to specify how long the arrow should be. It might sound like the same thing, but when you have nodes of unknown lengths between several arrows, it is not the same thing, because I'm no longer sure what the exact starting point of the arrow is when there is a node before it.

This example should make it clearer. What I want is a set length for each arrow, and the nodes should simply be placed where the arrows start and end.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \node[left] at (0,0) (Step 1) {Step 1};
    \draw [very thick, ->] (Step 1) -- (2,0);
    \node[right] at (2,0) (Step 2) {Step 2};
    \draw [very thick, ->] (Step 2) -- (4,0);
    \node[right] at (4,0) (Step 3) {Step 3};
\end{tikzpicture}
\end{document}

enter image description here

PS. I know there's a question with the same question as this one (How to specify the arrow length in TikZ?), but it's way more complicated than what I'm trying to accomplish here.

Best Answer

If you want to specify the length you can use ++. So, if you to draw an arrow that is 3cm long use ++(3.0cm,0) as shown in the red arrow.

If your desire is to only draw fixed length arrows and place nodes following the arrows, let tikz figure out the location of the nodes by using node (not \node) as part of the \draw (as opposed to a separate \node). Be careful to start the drawing from one end of the node (below I used east). Otherwise the center of the node is used.

enter image description here

Notes:

  • This is probably the simplest way to specify a length, as long as you want horizontal, or vertical lines. If you want to specify the length along a certain vector than you should refer to How to specify the arrow length in TikZ?

Code:

\documentclass{article}
\usepackage{tikz}
\usepackage{siunitx}

\newcommand{\FixedLengthArrow}{2,0}
\begin{document}
The black arrows are \SI{2}{\centi\meter} long:\bigskip

\begin{tikzpicture}
    \node[left] at (0,0) (Step 1) {Step 1};
    \draw [very thick, ->] (Step 1.east) -- ++(\FixedLengthArrow)
        node[right] (Step 2) {NeXT Step 2};
    \draw [very thick, ->] (Step 2.east) -- ++(\FixedLengthArrow)
        node[right]  (Step 3) {Step 3};
        
    %% To draw a line which is 3cm long
    \draw [ultra thick, red, ->] (0,-1) -- ++(3.0cm,0) node [above, pos=0.5] {This is \SI{3}{\centi\meter}};
\end{tikzpicture}
\end{document}