答案1
以下是使用三种不同的选项\bordermatrix
,kbordermatrix
和blkarray
:
\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}
答案2
该软件包nicematrix
中有解决此类问题的工具。
\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}