16

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.

13

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.

10

You can use the blkarray package for this. It allows you to use blocks inside an array that can be formatted like independent arrays:

\documentclass{article}

\usepackage{blkarray}

\begin{document}

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

\end{document}

  • Just flip the indexes to the bottom (OP's request). – Werner Oct 7 '11 at 6:01
  • Well, on a second thought I don't like the vertical alignment of your solution. The matrix names M and N as well as the separating comma are aligned with the whole array (i.e. with its all three lines). – Mats Oct 7 '11 at 6:31
  • @Mats: Are you referring to the case when the column indexes are at the top, or bottom, or both? – Werner Oct 7 '11 at 7:05
  • 1
    I guess it does not matter where I place the indices. In either case, the equality sign is vertically aligned with the whole \blockarray environment, and not with the individual \block which represents the matrix, without its labelling. – Mats Oct 7 '11 at 7:47

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.