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

\begin{tikzpicture}
\foreach \i [evaluate=\i as \ii using \i+5] in {1,2,3,4} {
    \node at (\i,0) {\ii};
}
\end{tikzpicture}

I like to print 6 7 8 9, but the above code prints 6.0 7.0 8.0 9.0. How can I control the precision in the evaluate statement?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

You can use the \pgfmathprintnumber{\ii} instead of \ii. See Section 66 in the PGF/TikZ manual for more information about the syntax.

share|improve this answer
2  
You could also say evaluate=\i as \ii using int(\i+5), then \ii will hold just the integer part. –  Jake Mar 4 '12 at 9:19
    
@Jake That's even better! Thanks. –  percusse Mar 4 '12 at 23:58
add comment

You can use the numprint package, and say:

\nprounddigits{0}\numprint{\ii}

An alternative is the number printing facility of the siunitx package. You have the \num macro, usable as follows:

\sisetup{round-mode = places}% in preamble    
\num[round-precision=0]{\ii}
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.