[Tex/LaTex] Vertically shift down an edge

tikz-arrowstikz-pgf

I'm trying to learn TikZ. I would like an edge between two nodes but vertically shifted down a bit.

Why is this not working? Seems to only shift down on one side.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations, arrows}

\begin{document}

\begin{tikzpicture}
 \draw (0,0) -- (10,0);

  \foreach \x in {0,2,4,7,9}
      \draw (\x cm,3pt) -- (\x cm,-3pt);

% draw nodes
\draw (0,0) node[below=3pt](A) {$ 0 $} node[above=3pt] {$   $};
\draw (1,0) node[below=3pt](B) {$  $} node[above=3pt] {$ Y_{i1} $};

\draw (2,0) node[below=3pt](C) {$ t_{i1} $} node[above=3pt] {$  $};
\draw (3,0) node[below=3pt](D) {$  $} node[above=3pt] {$ Y_{i2} $};

\draw (4,0) node[below=3pt](E) {$ t_{i2} $} node[above=3pt] {$  $};
\draw (5.5,0) node[below=3pt](F) {$  $} node[above=3pt] {$ Y_{i3} $};

\draw (7,0) node[below=3pt](G) {$ t_{i3} $} node[above=3pt] {$  $};
\draw (8,0) node[below=3pt](H) {$  $} node[above=3pt] {$ Y_{i3} $};

\draw (9,0) node[below=3pt](I) {$ t_{i4} $} node[above=3pt] {$  $};


%\draw[latex'-latex'] (A) -- (C);
\draw[latex'-latex'] ([yshift=-5cm]A) -- ([yshift=-5cm]C);
\draw[latex'-latex'] (C) -- (E);
\draw[latex'-latex'] (E) -- (G);

\end{tikzpicture}
\end{document}

enter image description here

Best Answer

For example, the arrow can be shifted the following way. As anchor point for the shift, the example uses the north * anchors, to avoid a slanted line because of the different heights of the nodes.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc, arrows}

\begin{document}

\begin{tikzpicture}[
  >=latex',
]
  \draw
    (0,0) -- (10,0)

    \foreach \x in {0,2,4,7,9} {
      (\x cm,3pt) -- (\x cm,-3pt)
    }

    % draw nodes
    (0,0) node[below=3pt](A) {$ 0 $}
    (1,0) node[above=3pt] {$ Y_{i1} $}

    (2,0) node[below=3pt](C) {$ t_{i1} $}
    (3,0) node[above=3pt] {$ Y_{i2} $}

    (4,0) node[below=3pt](E) {$ t_{i2} $}
    (5.5,0) node[above=3pt] {$ Y_{i3} $}

    (7,0) node[below=3pt](G) {$ t_{i3} $}
    (8,0) node[above=3pt] {$ Y_{i3} $}

    (9,0) node[below=3pt](I) {$ t_{i4} $}
  ;

  %\draw[latex'-latex'] (A) -- (C);
  \draw[<->] ($(A.north east) - (0, 1em)$) -- ($(C.north west) - (0, 1em)$);
  \draw[<->] (C) -- (E);
  \draw[<->] (E) -- (G);

\end{tikzpicture}
\end{document}

Result

If you want to correct the first arrow and move the left side down to get a horizontal line, then this can be achieved much easier via a \vphantom:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}

\begin{tikzpicture}[
  >=latex',
]
  \draw
    (0,0) -- (10,0)

    \foreach \x in {0,2,4,7,9} {
      (\x cm,3pt) -- (\x cm,-3pt)
    }

    % draw nodes
    (0,0) node[below=3pt](A) {$ 0\vphantom{t_{i1}} $}
    % Now node A has the same height and depth as node C
    (1,0) node[above=3pt] {$ Y_{i1} $}

    (2,0) node[below=3pt](C) {$ t_{i1} $}
    (3,0) node[above=3pt] {$ Y_{i2} $}

    (4,0) node[below=3pt](E) {$ t_{i2} $}
    (5.5,0) node[above=3pt] {$ Y_{i3} $}

    (7,0) node[below=3pt](G) {$ t_{i3} $}
    (8,0) node[above=3pt] {$ Y_{i3} $}

    (9,0) node[below=3pt](I) {$ t_{i4} $}
  ;

  \draw[<->] (A) -- (C);
  \draw[<->] (C) -- (E);
  \draw[<->] (E) -- (G);

\end{tikzpicture}
\end{document}

Result