\documentclass[tikz]{standalone} \usepackage{ifthen} \usepackage{intcalc} \begin{document} \begin{tikzpicture} \pgfkeys{/pgf/number format/.cd,fixed,precision=0} \draw[gray,step=2cm] (0,0) grid (20cm, 20cm) rectangle (0, 0); \foreach \y in {1,...,10} \foreach \x in {1,...,10} \pgfmathsetmacro{\p}{ifthenelse(\intcalcMod{\y}{2}==1, \x + (\y - 1) * 10, 10 * \y - \x + 1)} \node at (\x * 2cm - 1cm, \y * 2cm - 1cm) { \pgfmathprintnumber{\p} }; \end{tikzpicture} \end{document}