Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

You shouldn't use below of = node. It is deprecated (see Difference between "right of=" and "right=of" in PGF/TikZ). Instead use the positioning library from tikz. It allows you to write right = 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 add pos=value with a value between 0 and 1 to the node options to specify the position on the path.

Example

(your modified code)

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{positioning}

\begin{document}
    \begin{tikzpicture}
        \node(x1) {$x_1$};
        \node(x2) [right = 1.5cm of x1] {$x_2$};
        \node(x3) [right = 1.5cm of x2]{$x_3$};
        \node(x4) [right = 1.5cm of x3]{$x_4$};

        \draw [->] (x1) -- (x2) ;
        \draw [->] (x2) -- (x3) ;
        \draw [->] (x3) -- (x4) ;


        \node(y1) [below = 2 of x1]{$y_1$};
        \node(y2) [below = 2 of x2] {$y_2$};
        \node(y3) [below = 2 of x3] {$y_3$};
        \node(y4) [below = 2 of x4] {$y_4$};

        \draw [->] (y1) -- node[left, pos=0.2] {beginning} (x1) ;
        \draw [->] (y2) -- node[left, pos=.8] {ending} (x2) ;
        \draw [->] (y3) -- node[left] {label 3} (x3) ;
        \draw [->] (y4) -- node[left] {label 4} (x4) ;
    \end{tikzpicture}
\end{document}

Results in:

result

share|improve this answer
add comment

Remarks

You can specify the default distance between node, which are placed using right of=, left of=, etc using the key node distance=<length>.

To place a node along a path, just insert it after the lineto-operation, i.e.

\draw (0,0) -- node {on the path} (4,0);

If you want the text to be sloped with your path, use the sloped key as an option to the node.

Read more about node placement in the TikZ Documentation in section 16.8 on page 190. You might also be interested in the Tutorial "A Petri-Net for Hagen", which investigates in nodes and can be found in chapter 3 on page 40.

Implementation

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[node distance=2.5cm]
    \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) -- node[sloped,below] {(y1) $\to$ (x1)} (x1) ;
    \draw [->] (y2) -- node[sloped,below] {(y2) $\to$ (x2)} (x2) ;
    \draw [->] (y3) -- node[sloped,below] {(y3) $\to$ (x3)} (x3) ;
    \draw [->] (y4) -- node[sloped,below] {(y4) $\to$ (x4)} (x4) ;
\end{tikzpicture}
\end{document}

Output

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.