2

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

4
  • 1
    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
2

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.

3
  • This... seems... the... same... as... mine... – Werner Mar 16 '18 at 22:10
  • 1
    @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
2

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:

enter image description here

\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}
1
  • I personally prefer something smaller than \arraycolsep. Maybe .5\arraycolsep. – Werner Mar 16 '18 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.