5

I don't know how to set all the labels on the same level.

\documentclass[french]{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[>=stealth,x=6cm,font=\footnotesize]

\draw [->] (0,0)--(1,0)  ;

\foreach \x in {0,1,...,12} {%
    \coordinate (\x) at (\x/12,0) ;
    \draw [very thin] (\x/12,+2pt)--(\x/12,-2pt) ;

    \pgfmathsetmacro\result{2 + \x / 10}
    \node[above=1pt]  at (\x)%
        {\pgfmathprintnumber[precision=1,fixed,use comma]{\result}};

    } ;

\end{tikzpicture}
\end{document}

enter image description here

alexwlchan
  • 5,417
Tarass
  • 16,912

1 Answers1

4

The problem is that the nodes with the comma are higher than those without, or specifically they have a larger depth, that is they go further below the baseline of the text. One way of fixing this is to set the text depth for the nodes:

\node[above=1pt,text depth=2pt]  at (\x)%
    {\pgfmathprintnumber[precision=1,fixed,use comma]{\result}};

(For an illustration of text depth see the second screenshot in this answer of mine to another question.)

enter image description here

\documentclass[10pt,a4paper,french]{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[>=stealth,x=6cm,font=\footnotesize]

\draw [->] (0,0)--(1,0)  ;

\foreach \x in {0,1,...,12} {%
    \coordinate (\x) at (\x/12,0) ;
    \draw [very thin] (\x/12,+2pt)--(\x/12,-2pt) ;

    \pgfmathsetmacro\result{2 + \x / 10}
    \node[above=1pt,text depth=3pt]  at (\x)%
        {\pgfmathprintnumber[precision=1,fixed,use comma]{\result}};

    } ;

\end{tikzpicture}
\end{document}
Torbjørn T.
  • 206,688