I was trying to use \newcommand inside tikz and matrix environment. See the following code:
\documentclass[border={0pt 0pt 0pt 0pt}]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, positioning, shapes, shapes.geometric, shapes.arrows, }
\usepackage{array}
\newcommand{\Block}[3]{
\ifnum #1=1
{ \begin{tikzpicture}[auto, ]
\node[draw, fill=gray, rectangle, thick, text centered, rounded corners =3pt, minimum height=1em, align=center, text=black, minimum width=6em, ] (#2) {#3};
\end{tikzpicture}
}
%\else
% { \begin{tikzpicture}[auto, ]
% \node[fill=gray, rectangle, thick, text centered, rounded corners =3pt, minimum height=1em, align=center, text=black, minimum width=6em, ] (#2) {#3};
% \end{tikzpicture}
% }
\fi
}
\begin{document}
\begin{tikzpicture} [
auto,
block1/.style = { rectangle, , thick, draw,
text width=15em, text centered,
rounded corners, minimum height=1em },
]
%%%% WORKS
\matrix [column sep=5.mm, row sep=12mm] {
\node [block1] (p00) {00}; & \node [block1] (p01) {01}; & \node [block1] (p02) {02}; \\
\node [block1] (p10) {10}; & \node [block1] (p12) {12}; & \node [block1] (p12) {12}; \\
};
\\
%%%%%%% Does not work
% \matrix [column sep=5.mm, row sep=12mm] {
% \Block {1}{p00}{00}; & \Block {1}{p01}{01}; & \Block {1}{p02}{02}; \\
% \Block {1}{p11}{11}; & \Block {1}{p11}{11}; & \Block {1}{p12}{12}; \\
% };
\end{tikzpicture}
\end{document}
The first matrix works as expected (see image), whereas the second doesn't (the positioning gets messed up). My question is, how should I modify the \newcommand such that it works (in the similar way of the former)?


