[Tex/LaTex] bmatrix vs \left[…\right]

equationsmatrices

I following code produces matrices as given in image

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

\begin{equation}
\left[ {\begin{array}{*{20}{c}} \mathbf{y}_1 \\ \vdots \\ \mathbf{y}_s \\ \vdots \\ \mathbf{y}_S \end{array}} \right] = 
        \begin{bmatrix}         \mathbf{y}_1 \\ \vdots \\ \mathbf{y}_s \\ \vdots \\ \mathbf{y}_S \end{bmatrix}
\end{equation}

\end{document}

To me the matrix produced by bmatrix (on the right) is a bit congested, is there a way to produce a spacious matrix (like in the left) using bmatrix?

Just curious 🙂

Thanks
enter image description here

Best Answer

If you really want the space like in array, use array:

\renewenvironment{bmatrix}
  {\left[\array{*{\value{MaxMatrixCols}}{c}}}
  {\endarray\right]}

Full example

\documentclass{article}

\usepackage{amsmath}

\renewenvironment{bmatrix}
  {\left[\array{*{\value{MaxMatrixCols}}{c}}}
  {\endarray\right]}

\begin{document}

\[
  \left[
    \begin{array}{ c }
      \mathbf{y}_1 \\ \vdots \\ \mathbf{y}_s \\ \vdots \\ \mathbf{y}_S
    \end{array}
  \right] =
  \begin{bmatrix}
    \mathbf{y}_1 \\ \vdots \\ \mathbf{y}_s \\ \vdots \\ \mathbf{y}_S
  \end{bmatrix}
\]

\end{document}

enter image description here

But, please, don't: the standard \arraycolsep is really too much. Maybe

\renewenvironment{bmatrix}
  {\left[\hspace{-.5\arraycolsep}\array{*{\value{MaxMatrixCols}}{c}}}
  {\endarray\hspace{-.5\arraycolsep}\right]}

which would yield

enter image description here

Actually, in order to get the same behavior as the standard bmatrix, one should add a small bit of code:

\makeatletter
\renewenvironment{bmatrix}
  {\left[\let\@ifnextchar\new@ifnextchar\array{*{\value{MaxMatrixCols}}{c}}}
  {\endarray\right]}
\makeatother

This allows a row to begin with [ without taking special precautions.