[Tex/LaTex] bordermatrix with more space between rows when there are fractional elements

bordermatrix

I am using a modified version of \bordermatrix as defined here:
\bordermatrix with brackets [ ] instead of parentheses ( )

My matrices have fractional elements and I would like to add additional space between rows so the fractions don't touch. With usual matrices this can be done by putting [0.3em] at the end of each line, but that doesn't work with bordermatrix since it uses \cr instead of \\ for line breaks, and \cr seems not to take arguments.

\usepackage{etoolbox}
\let\bbordermatrix\bordermatrix
\patchcmd{\bbordermatrix}{8.75}{4.75}{}{}
\patchcmd{\bbordermatrix}{\left(}{\left[}{}{}
\patchcmd{\bbordermatrix}{\right)}{\right]}{}{}

\[\mathbf{P}=\bbordermatrix{& 0 & 1 & 2\cr
0 & 0 & \frac{1}{2} & \frac{1}{2}\cr
1 & \frac{1}{2} & 0 & \frac{1}{2}\cr
2 & \frac{1}{2} & \frac{1}{2} & 0}
\]

Best Answer

You can add a couple of patches:

\documentclass{article}
\usepackage{etoolbox}
\let\bbordermatrix\bordermatrix
\patchcmd{\bbordermatrix}{8.75}{4.75}{}{}
\patchcmd{\bbordermatrix}{\left(}{\left[}{}{}
\patchcmd{\bbordermatrix}{\right)}{\right]}{}{}

% Add some space between rows
\patchcmd{\bbordermatrix}{\begingroup}{\begingroup\openup1\jot}{}{}
% Add the same amount at the end
\makeatletter
\patchcmd{\bbordermatrix}
  {\vcenter{\kern-\ht\@ne\unvbox\z@\kern-\baselineskip}}
  {\vcenter{\kern-\ht\@ne\unvbox\z@\kern-\baselineskip\kern2pt}}
  {}{}
\makeatother

\begin{document}

\[
\mathbf{P}=\bbordermatrix{& 0 & 1 & 2\cr
0 & 0 & \frac{1}{2} & \frac{1}{2}\cr
1 & \frac{1}{2} & 0 & \frac{1}{2}\cr
2 & \frac{1}{2} & \frac{1}{2} & 0}
\]

\end{document}

enter image description here