I would like to create a matrix with rows and columns being labeled. I would like the matrix elements to be right aligned, the row labels being displayed to the right of the matrix, and the column labels above the matrix. I tried:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[american,ngerman]{babel}
\begin{document}
% does work:
$\bordermatrix{%
& 1 & 2 \cr
1 & x1 & x2 \cr
2 & x3 & x423 \cr
3 & x5 & x6
}$
% does not work (see error below):
% $\bordermatrix*{%
% x1&x2&1\cr
% x3&x4&2\cr
% x5&x6&3\cr
% 1&2 6 }$
\end{document}
% ERROR: Misplaced alignment tab character &.
% --- TeX said ---
% l.17 x1&
% x2&1\cr
% --- HELP ---
% The special character &, which should be used only to separate items
% in an array or tabular environment, appeared in ordinary text. You
% probably meant to type \&.
To get at least the row labels displayed at the correct side of the matrix, I
wanted to use the starred version of \bordermatrix
, but that did not work (as
opposed to given in Voss's mathmode guide). Also, the matrix entries are not
right aligned. How can I create such a matrix? Is there a way to do this with amsmath
?
UPDATE
Thanks to the link by Werner, a minimal example is this:
\documentclass{article}
\usepackage{blkarray}
\newcommand{\matindex}[1]{\mbox{\scriptsize#1}}
\begin{document}
\[
A=\begin{blockarray}{rrl}
\matindex{1} & \matindex{2} & \\
\begin{block}{(rr)l}
\,100 & b\phantom{\,} & \matindex{row 1} \\
2 & 12 & \matindex{row 2} \\
e & f & \matindex{ABDC} \\
\end{block}
\end{blockarray}
\]
\end{document}
It's just a quick hack to get a bit more horizontal space between the parentheses and the matrix entries.
\matrix
command?\,
in a\phantom
, since it is only white space anyway. I've added an answer to reflect some possible spacing alternatives.