# Why are the ticks of my axis displaced to the left?

I'm trying to make a timeline in a tikzpicture. However, the ticks of my timeline are displaced to the left. Can someone please help me fix this?

\begin{tikzpicture}[x=2cm,y=2ex]

%draw horizontal line
\draw (1,0) -- (6,0);

%draw vertical line
\foreach \x in {1,2,3,4,5,6}
\draw (\x cm, 3pt) -- (\x cm,-3pt);

%draw nodes
\draw (1,0) node[below=3pt] {$1$} node[above=14pt] {RD};
\draw (2,0) node[below=3pt] {$2$} node[above=3pt] {Defendant enters market};
\draw (3,0) node[below=3pt] {$3$} node[above=14pt] {Lawsuit};
\draw (4,0) node[below=3pt] {$4$} node[above=3pt] {PI Decision};
\draw (5,0) node[below=3pt] {$5$} node[above=14pt] {Final Decision};
\draw (6,0) node[below=3pt] {$6$} node[above=3pt] {Final Pay-offs};
\end{tikzpicture}

-
Welcome to TeX.sx! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). – Jubobs Apr 8 '13 at 23:27
Replace \draw (\x cm, 3pt) -- (\x cm,-3pt); by \draw (\x, 3pt) -- (\x,-3pt);. – Jubobs Apr 8 '13 at 23:33
As @Jubobs hints, you force x values without a unit to be x=2cm but use cm in the \foreach loop, this is always evaluated to be \x cm regardless of the x= setting. – Qrrbrbirlbel Apr 9 '13 at 0:32

Instead of unit vector changes you might use scales which without transform shape option don't affect the nodes. You can also shorten the code while you are at it...

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}[xscale=2]
\def\mylist{{"RD","Defendant enters market","Lawsuit",
"PI Decision","Final Decision","Final Pay-offs"}}

\draw (1,0) -- (6,0);

\foreach \x[count=\xi from 0] in {1,...,6}{
\draw (\x cm, 3pt) -- (\x cm,-3pt)   node[below=3pt] at (\x,0) {$\x$}
\pgfextra{\pgfmathparse{Mod(\x,2)==0?"3pt":"14pt"}}
node [above=\pgfmathresult] {\pgfmathparse{\mylist[\xi]}\pgfmathresult};
}
\end{tikzpicture}
\end{document}


-
Shorten - and make it illegible... – Tomas Lycken Apr 9 '13 at 0:57
@TomasLycken There are only two nodes and one draw there, I mean come on :) – percusse Apr 9 '13 at 0:58
Great, thanks a lot all of you! – Rasmus Apr 9 '13 at 4:39

You must be consistent with using cm units or no units. Either specify each node as (1 cm,0), etc. (which results in overlapping labels), or (as Jubobs suggests) remove the cm units in the foreach loop. This yields:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=2cm,y=2ex]

%draw horizontal line
\draw (1,0) -- (6,0);

%draw vertical line
\foreach \x in {1,2,3,4,5,6}
\draw (\x, 3pt) -- (\x,-3pt);

%draw nodes
\draw (1,0) node[below=3pt] {$1$} node[above=14pt] {RD};
\draw (2,0) node[below=3pt] {$2$} node[above=3pt] {Defendant enters market};
\draw (3,0) node[below=3pt] {$3$} node[above=14pt] {Lawsuit};
\draw (4,0) node[below=3pt] {$4$} node[above=3pt] {PI Decision};
\draw (5,0) node[below=3pt] {$5$} node[above=14pt] {Final Decision};
\draw (6,0) node[below=3pt] {$6$} node[above=3pt] {Final Pay-offs};
\end{tikzpicture}
\end{document}


in which everything lines up properly. The problem is that, since you specified x=2cm in the environment options, "bare" coordinates (without units) are multiples of x (2cm), whereas if you specify units, you get what you ask for. (This mismatch doesn't show up by default, since initially the x-vector is 1cm.)

Note that there are two different coordinate systems in TikZ specified by (x,y) pairs. The xyz system is used when there are no dimensions (units of length), as in (2,3). As you've seen, these are factors which multiply the x and y vectors, whose values can be specified. The canvas system is used when dimensions are supplied, as in (2 cm, 7 pt). When you mix systems (as you did), these are the rules (from the TikZ manual):

Note: It is possible to use coordinates like (1,2cm), which are neither canvas coordinates nor xyz coordinates. The rule is the following: If a coordinate is of the implicit form (⟨x⟩,⟨y⟩), then ⟨x⟩ and ⟨y⟩ are checked, independently, whether they have a dimension or whether they are dimensionless. If both have a dimension, the canvas coordinate system is used. If both lack a dimension, the xyz coordinate system is used. If ⟨x⟩ has a dimension and ⟨y⟩ has not, then the sum of two coordinate (⟨x⟩,0pt) and (0,⟨y⟩) is used. If  ⟨y⟩ has a dimension and ⟨x⟩ has not, then the sum of two coordinate (⟨x⟩,0) and (0pt,⟨y⟩) is used.

Note furthermore: An expression like (2+3cm,0) does not mean the same as (2cm+3cm,0). Instead, if ⟨x⟩ or ⟨y⟩ internally uses a mixture of dimensions and dimensionless values, then all dimensionless values are "upgraded" to dimensions by interpreting them as pt. So, 2+3cm is the same dimension as 2pt+3cm.

-