I wish to draw square box array side by side, but my code below still has gap between square box. My math is wrong?
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\def\m{25pt}
\tiny\begin{tikzpicture}[
square/.style={draw,regular polygon,regular polygon sides=4,minimum size=\m,fill=gray!50},
outer sep=0,inner sep=0]
\def\w{6}
\def\h{4}
\pgfmathsetmacro\uw{int(\w/2)}
\pgfmathsetmacro\uh{int(\h/2)}
%Y
\foreach \x in {1,...,\w}
\foreach \y in {1,...,\h}
{\pgfmathtruncatemacro{\label}{(\y-1) * \w + \x}
\node [square] (Y\x,\y) at (\x*\m,-\y*\m) {Y\label};
}
%U
\foreach \x in {1,...,\uw}
\foreach \y in {1,...,\uh}
{\pgfmathtruncatemacro{\label}{(\y-1) * \uw + \x}
\node [square,fill=blue!50] (U\x,\y) at (\x*\m,-\y*\m- \h*\m) {U\label};
}
%V
\foreach \x in {1,...,\uw}
\foreach \y in {1,...,\uh}
{\pgfmathtruncatemacro{\label}{(\y-1) * \uw + \x}
\node [square,fill=yellow!50] (V\x,\y) at (\x*\m,-\y*\m - \h*\m-\uh*\m) {V\label};
}
\end{tikzpicture}
\end{document}




minimum width=35ptthis will fix your MWE, but if you subsequently change\mthen you need to change this adjustment...so this is a work-around rather than a fix. – Oct 19 '16 at 06:15regular polygonshape? If you userectangle, you will obtain what you wish ... – Zarko Oct 19 '16 at 06:26