I have the following tikz picture:
\documentclass{book}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node(x1) {$x_1$};
\node(x2) [right of = x1] {$x_2$};
\node(x3) [right of = x2]{$x_3$};
\node(x4) [right of = x3]{$x_4$};
\draw [->] (x1) -- (x2) ;
\draw [->] (x2) -- (x3) ;
\draw [->] (x3) -- (x4) ;
\node(y1) [below of = x1]{$y_1$};
\node(y2) [right of = y1] {$y_2$};
\node(y3) [right of = y2] {$y_3$};
\node(y4) [right of = y3] {$y_4$};
\draw [->] (y1) -- (x1) ;
\draw [->] (y2) -- (x2) ;
\draw [->] (y3) -- (x3) ;
\draw [->] (y4) -- (x4) ;
\end{tikzpicture}
\end{document}
I want the arrows to be longer. When I use "shorten >= -5pt" for example, in the draw command in the square brackets, the arrows become longer, but they go over the nodes. Is there a way to make everything more spacious, in addition to lengthening the arrows?
Also, is there a way to insert another node to the left of one of the vertical arrows? (or more specifically, how do I state "below of" or "left of" etc. for an arrow, and not a node?) I tried \draw(arr1) to label the arrow, and then later put a node to the left of arr1, but I get an error.
Best Answer
You shouldn't use
below of = node
. It is deprecated (see Difference between "right of=" and "right=of" in PGF/TikZ). Instead use thepositioning
library from tikz. It allows you to writeright = 1.5cm of node
. You may vary or leave out the distance.To label a path, just add
node[left] {label 1}
behind the--
. You may addpos=value
with a value between 0 and 1 to the node options to specify the position on the path.Example
(your modified code)
Results in: