[Tex/LaTex] Vertical space in bmatrix

amsmathhorizontal alignmentmatricesvertical alignment

I have matrices with dense expressions in them and I'd like to loosen the matrix brackets a little. I'd like to be able to control the horizontal distance from bracket to first letter (both sides) and the vertical distance between the expressions. Vertically I'd like to only change the size below a row, unlike arraystretch does.

Consitency thereby is very important, so local solutions are no good for me. I tried arraystretch and % \setlength{\extrarowheight}{10pt}, but those add extra space upon and below each line. I'd like an output similar to the following (preferably tunable), for all matricies in the document.

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\horizontaldistance{2pt}
\vertical_distance{5pt}

\[
\begin{bmatrix}
  \horizontaldistance s'^{\mathrm{T}} \horizontaldistance    \\[vertical_distance]
  \horizontaldistance I_{p\times p} \horizontaldistance
\end{bmatrix}
\]

\end{document}

My goal would be, that I do not have to write the distances explicitly into the matrix, but that ALL bmarix instances at once have the same distances!

Best Answer

REVISED SOLUTION (for global automation):

Here one employs TABstacks in lieu of the bmatrix environment.

Here one controls global settings of \setstackgap{L}{} for vertical spacing of baselines, \setstacktabbedgap{} for horizontal spacing inside the matrices, and \lrgap for the spacing at the left and right extremities of the vectors/matrices.

\documentclass{article}
\usepackage{tabstackengine}
\stackMath
\setstackgap{L}{24pt}
\setstacktabbedgap{4pt}
\def\lrgap{\kern6pt}
\def\xbracketVectorstack#1{\left[\lrgap\Vectorstack{#1}\lrgap\right]}
\def\xbracketMatrixstack#1{\left[\lrgap\tabbedCenterstack{#1}\lrgap\right]}
\begin{document}
\[
\xbracketVectorstack{
  s'^{\mathrm{T}}  \\
  I_{p\times p}   
}=
\xbracketMatrixstack{
  A & B \\
  C & D   
}
\xbracketVectorstack{
  s'^{\mathrm{T}}  \\
  I_{p\times p}   
}
\]
\end{document}

enter image description here

ORIGINAL SOLUTION

Attempting to achieve the goal with the minimal changes to the OP's code.

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\def\horizontaldistance{\kern2pt}
\def\verticaldistance{5pt}

\[
\begin{bmatrix}
  \horizontaldistance s'^{\mathrm{T}} \horizontaldistance    \\[\verticaldistance]
  \horizontaldistance I_{p\times p}   \horizontaldistance
\end{bmatrix}
\]

\end{document}