\documentclass[border=10pt]{standalone} \usepackage{tikz} \usepackage{fontspec} \begin{document} \begin{tikzpicture} % Define dimensions \def\boxsize{1.5} % 1cm box size \def\gap{0.5} % 0.5mm gap between boxes \setmainfont{Ubuntu} \def\labelsize{7} % Size for the labels \pgfmathsetmacro{\gridsize}{(\boxsize + \gap)} % Create 10x10 grid of boxes \foreach \row in {0,...,9} { \foreach \col in {0,...,9} { % Calculate gray value (0 to 99) \pgfmathsetmacro{\grayval}{(100 - (\row * 10 + \col))} \pgfmathsetmacro{\grayscale}{(\grayval/100)} \pgfmathsetmacro{\graylabelraw}{1-\grayscale} \pgfmathprintnumberto[fixed,zerofill,precision=2,assume math mode]{\graylabelraw}{\graylabel} % Calculate position \pgfmathsetmacro{\x}{\col * \gridsize} \pgfmathsetmacro{\y}{9 - \row * \gridsize} % Invert Y to start from top % Draw box using proper grayscale \draw [fill=black!\grayval] (\x, \y) rectangle ++ (\boxsize, -\boxsize); % Add label (white text for dark boxes, black for light ones) \pgfmathsetmacro{\textcolor}{ifthenelse(\grayval > 50, "white", "black")} \node[text=\textcolor] at (\x + 0.5*\boxsize, \y-0.2*\boxsize) {\fontsize{\labelsize}{\labelsize}\selectfont\graylabel}; } } \end{tikzpicture} \end{document}