One of my textbooks notates Markov transition matrices this way with 1 and 2 denoting states:

How can I reproduce this matrix in LaTeX?
One of my textbooks notates Markov transition matrices this way with 1 and 2 denoting states:

How can I reproduce this matrix in LaTeX?
[EDITED to resolve the equation axis properly]
\documentclass{article}
\usepackage{amsfonts}
\usepackage{scalerel}
\begin{document}
\def\x{\begin{array}{c}x\\x\end{array}}
\(
\let\svarraycolsep\arraycolsep
\renewcommand\arraystretch{1.4}
\arraycolsep 0.4ex
\begin{array}{c}
\\
\mathbb{P}=\quad\\
\\
\end{array}
\begin{array}{c}
\\
{\scriptstyle 1}\\
{\scriptstyle 2}\\
\\
\end{array}
\begin{array}{c}
\\
\scalerel*[1.5ex]{(}{\x}\\
\\
\end{array}
\begin{array}{c}
{\scriptstyle 1}\\
1-a\\
b\\
\\
\end{array}
\begin{array}{c}
{\scriptstyle 2}\\
a\\
1-b\\
\\
\end{array}
\begin{array}{c}
\\
\scalerel*[1.5ex]{)}{\x}\\
\\
\end{array}
\mathrm{is~the~answer}
\arraycolsep\svarraycolsep
\renewcommand\arraystretch{1.0}
\)
\end{document}

P= between rows 2 and 3 of the matrix construction. If you add constructions on either side of this it will vertically align with the middle row (row 2), which would make P= seem off-axis.
– Werner
May 01 '13 at 19:02
kbordermatrixpackage is not on CTAN, but it can handle this beautifully. See the duplicate link. You can also change the delimiters, as described in thekbordermatrixdocumentation. – Werner May 01 '13 at 18:33