矩阵布局不正确。它应该是 2x3 矩阵。代码有什么问题?
梅威瑟:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\newcommand{\agente}[3] { % \belongs
\node[draw,inner sep=0] {
\tabcolsep=0cm
\begin{tabular}{m{1em}m{1em}}
#1 & #2 \\
#3 & \\
\end{tabular}
}; \\
}
\def\semagente{\agente{}{}{}}
\begin{figure}[htb]
\centering
\begin{tikzpicture}
\tikzset{
}
\matrix[ampersand replacement=\&]{
\semagente \& \agente{\cellcolor{green} 5}{\cellcolor{orange} 2}{\cellcolor{red} 1} \& \semagente \\
\semagente \& \agente{\cellcolor{green} 5}{\cellcolor{orange} 2}{\cellcolor{red} 1} \& \semagente \\
};
\end{tikzpicture}
\end{figure}
\end{document}
附言:如果你知道更好的方法将 2x2 矩阵放在像这样的大矩阵中,也请告诉我 :P
答案1
\\
删除节点结束分号后多余的部分就可以了
\PassOptionsToPackage{table}{xcolor}
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\newcommand{\agente}[3] {%
\node[draw,inner sep=0] {\tabcolsep=0cm%
\begin{tabular}{m{1em}m{1em}}
#1 & #2 \\
#3 & \\
\end{tabular}
};}
\def\semagente{\agente{}{}{}}
\begin{document}
\begin{tikzpicture}
\matrix[ampersand replacement=\&]{
\semagente \& \agente{\cellcolor{green} 5}{\cellcolor{orange} 2}{\cellcolor{red} 1} \& \semagente \\
\semagente \& \agente{\cellcolor{green} 5}{\cellcolor{orange} 2}{\cellcolor{red} 1} \& \semagente \\
};
\end{tikzpicture}
\end{document}