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 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

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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}
share|improve this answer

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.