# bordermatrix with more space between rows when there are fractional elements

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}$


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}


One option would be to use kbordermatrix instead (the package is not on CTAN, but can be downloaded following the provided link); in this way, you automatically get square brackets instead of parentheses as delimiters, and you can use the standard \$<length>] syntax; a little example: \documentclass{article} \usepackage{kbordermatrix} \usepackage{etoolbox} \let\bbordermatrix\bordermatrix \patchcmd{\bbordermatrix}{8.75}{4.75}{}{} \patchcmd{\bbordermatrix}{\left(}{\left[}{}{} \patchcmd{\bbordermatrix}{\right)}{\right]}{}{} \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}\qquad \mathbf{P}=\kbordermatrix{ & 0 & 1 & 2 \\ 0 & 0 & \frac{1}{2} & \frac{1}{2} \\[1ex] 1 & \frac{1}{2} & 0 & \frac{1}{2} \\[1ex] 2 & \frac{1}{2} & \frac{1}{2} & 0\\[0.3ex]}$

\end{document}