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.

1

3 Answers 3

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}

4
  • Just flip the indexes to the bottom (OP's request).
    – Werner
    Commented Oct 7, 2011 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
    Commented Oct 7, 2011 at 6:31
  • @Mats: Are you referring to the case when the column indexes are at the top, or bottom, or both?
    – Werner
    Commented Oct 7, 2011 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
    Commented Oct 7, 2011 at 7:47
0

Here is a solution with the environments of nicematrix.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\NiceMatrixOptions
  {
    code-for-first-row = \scriptstyle , 
    code-for-first-col = \scriptstyle , 
  }

$M = 
\begin{bNiceArray}{c|cc}[first-col,first-row]
  & A & B & C \\
1 & 1 & 2 & 3 \\
2 & 4 & 5 & 6 
\end{bNiceArray}$,\qquad
$N = 
\begin{bNiceArray}{c|cc}[first-row]
D & E & F \\
7 & 8 & 9 \\
10 & 11 & 12
\end{bNiceArray}$

\end{document}

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .