# bmatrix vs \left[…\right]

I following code produces matrices as given in image

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

$$\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{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

• Write \,y_\, for the first element (or whatever spacing command you please). – Bernard Mar 16 '18 at 17:09
• almost the only thing bmatrix does is remove that space so simpler to use left/right and matrix if you want the space – David Carlisle Mar 16 '18 at 17:22
• That’s the spacing most mathematics books use. By the way, why all those unnecessary braces? Typing \mathbf{y}_1 is simpler and yields the same output. – egreg Mar 16 '18 at 17:51
• I copied it from mathtype and modified it, math type puts so many braces. I should have removed them. – pkj Mar 16 '18 at 17:56

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}


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

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.

• This... seems... the... same... as... mine... – Werner Mar 16 '18 at 22:10
• @Werner Not at all. You're adding space that then gets removed. – egreg Mar 16 '18 at 22:12
• Tomato, tomato, tomato... – Werner Mar 16 '18 at 22:14

The definition of bmatrix uses \left[...\right] but also removes the exterior space inserted by the column separation of the internal array (as part of \env@matrix and \endmatrix; see amsmath.dtx). You can adjust this to suit your needs:

\documentclass{article}

\usepackage{amsmath}

\makeatletter
% Original definition of bmatrix
% \newenvironment{bmatrix}{\left[\env@matrix}{\endmatrix\right]}
\renewenvironment{bmatrix}
{\left[\hspace{\arraycolsep}\env@matrix}
{\endmatrix\hspace{\arraycolsep}\right]}
\makeatother

\begin{document}

$\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{document}

• I personally prefer something smaller than \arraycolsep. Maybe .5\arraycolsep. – Werner Mar 16 '18 at 17:10