3

The matrix is not being layed out correctly. It should be a 2x3 matrix. What's wrong with the code?

MWE:

\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}

output

ps: if you know a better way to have a 2x2 matrix inside a big matrix like this, let me know too :P

  • Oh, I see the problem is the collision between the tabular \\ and the matrix \\ ... not sure if there is a "row replacement=\\\" or some such .. – Ricardo Cruz Apr 4 '15 at 20:34
3

Remove the extra \\ after the node closing semicolon and it works

\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.