16

It is trivial to make matrices like so:

\begin {pmatrix} s & t & a \\ c & k & x \\ cha & n & ge \end {pmatrix}

It is not so trivial to impose labels on the rows and columns as done in page 410 here. I would like to do this. For example, the matrix in 11.6:

enter image description here


Note: I am aware of this thread but this is not what I'm looking for.

Ahaan S. Rungta
  • 448
  • 1
  • 4
  • 16

2 Answers2

26

Here are three different option using \bordermatrix, kbordermatrix and blkarray:

enter image description here

\documentclass{article}
\usepackage{amsmath,kbordermatrix,blkarray}

\renewcommand{\kbldelim}{(}
\renewcommand{\kbrdelim}{)}

\begin{document}
\[
  \mathbf{P} = 
    \bordermatrix{ & H & Y & D \cr
      H & .8 & .2 & .0 \cr
      Y & .3 & .4 & .3 \cr
      D & .2 & .1 & .7 } \qquad
  \mathbf{P} = 
    \kbordermatrix{ & H & Y & D \\
      H & .8 & .2 & .0 \\
      Y & .3 & .4 & .3 \\
      D & .2 & .1 & .7 } \qquad
  \mathbf{P} = 
    \begin{blockarray}{cccc}
        & H & Y & D \\
      \begin{block}{c(ccc)}
        H & .8 & .2 & .0 \\
        Y & .3 & .4 & .3 \\
        D & .2 & .1 & .7 \\
      \end{block}
    \end{blockarray}
\]

\end{document}
Werner
  • 603,163
0

The package nicematrix has tools to address that kind of problem.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

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

[ \mathbf{P} = \begin{pNiceMatrix}[first-col,first-row] & H & Y & D \ H & .8 & .2 & .0 \ Y & .3 & .4 & .3 \ D & .2 & .1 & .7 \ \end{pNiceMatrix} ]

\end{document}

Output of the above code

F. Pantigny
  • 40,250