I would like to display a matrix surrounded by square brackets that has row and column labels outside the square brackets. In LaTeX, I would use blockarray
like the following:
\documentclass[preview]{standalone}
\usepackage{blkarray}
\begin{document}
\begin{blockarray}{rcc}
& C1 & C2 \\
\begin{block}{r[cc]}
R1 & -1 & 0 \\
R2 & -1 & 0 \\
\end{block}
\end{blockarray}
\end{document}
With the result:
I've been able to reproduce something similar in ConTeXt using block matrices, but I can't figure out how to go one step further and align two columns across different blocks:
\starttext
\definemathmatrix[smatrix][left={\left[}, right={\right]}]
\definemathmatrix[omatrix][left={\phantom{[}}, right={\phantom{]}}]
\startformula
\startmatrix
\NC
\NC
\startomatrix[n=2]
\NC C1 \NC C2 \NR
\stopomatrix
\NR
\NC
\startmatrix[n=1]
\NC R1 \NR
\NC R2 \NR
\stopmatrix
\NC
\NC % Need an extra \NC, might be a bug
\startsmatrix[n=2]
\NC -1 \NC 0 \NR
\NC -1 \NC 0 \NR
\stopsmatrix
\NR
\stopmatrix
\stopformula
\stoptext
With the result:
It's actually not too bad, but the column labels are not aligned with the actual columns and this becomes more obvious with more complex column values.
I can hack together alignment using phantom
elements, but is there a more general method to get column labels?