[Tex/LaTex] Array with labeling columns

arrayshorizontal alignmentmath-modematrices

Is there an intelligent way to label (or name) columns in a matrix? I would like to have something like

\[M=\left[\begin{array}{c|cc}
1 & 2 & 3\\
4 & 5 & 6
\end{array}\right],N=\left[\begin{array}{c|cc}
7 & 8 & 9\\
10 & 11 & 12
\end{array}\right]\]
\[A \ B \ C \ D \ E \ F\]

where A, B,…, F are the labels (or rather names) of the first, second, …, sixth columns, respectively. What I want is to label A be exactly below the first column, label B be below the second column, etc., of course, nicely aligned. So far I have forced some extra spaces before the labels manually, and also experimented with the \phantom command.

Best Answer

The kbordermatrix package does a neat job in typesetting a matrix with indices. It has a format similar to (La)TeX's \bordermatrix.

enter image description here

\documentclass{article}
\usepackage{kbordermatrix}% http://www.hss.caltech.edu/~kcb/LaTeX.shtml
\newcommand{\noindex}{\hspace*{-0.8em}}%
\begin{document}
\[
  M=\kbordermatrix{%
      & A &        & B & C \\
    1 & 1 & \vrule & 2 & 3 \\
    2 & 4 & \vrule & 5 & 6
  },\quad
  N=\kbordermatrix{%
    \noindex &  D &        &  E &  F \\
    \noindex &  7 & \vrule &  8 &  9 \\
    \noindex & 10 & \vrule & 11 & 12
  }
\]
\end{document}

The vertical alignment with respect to the equation/expression is maintained well.

Related Question