8

How do I change \arraycolsep for a single environment? E.g., I have \arraycolsep set so that the white spacing on either side of "=" in the equation array environment is not excessive. However, this brings the columns of matrices in the bmatrix environment closer together as well. I would like to redefine the matrix (bmatrix) environment so that it calls upon a local definition of \arraycolsep that is different than the one used globally (for equation arrays).

Werner
  • 603,163
Jared
  • 123

3 Answers3

7

You can use the etoolbox package to make adjustments to environments.

\documentclass{article}
\usepackage{amsmath}
\usepackage{etoolbox}
\AtBeginEnvironment{bmatrix}{\setlength{\arraycolsep}{50pt}}
\begin{document}
\[
\begin{bmatrix}
1 & 2 \\
3 & 4
\end{bmatrix}
\quad
\begin{pmatrix}
1 & 2 \\
3 & 4
\end{pmatrix}
\]
\end{document}

The alteration takes place inside a group, so it will be undone when the environment ends.

Of course, as @Werner has pointed out, the solution to problems with eqnarray is to use the align environment from the amsmath package instead.

David Carlisle
  • 757,742
Ian Thompson
  • 43,767
6

You can explicitly set the column separation for them. To keep the spacing uniform in the document, you could specify the dimension in the preamble and then just use \BigColSep:

\documentclass{article}
\def\BigColSep{\setlength{\arraycolsep}{50pt}}
\begin{document}

\[
\begingroup\BigColSep
\begin{array}{cc}
a & b 
\end{array}
\endgroup
\]

\end{document}

The \begingroup and \endgroup are only required if you mix some other arrays in this particular math display. If it consists only of bmatrix, they aren't needed.

Frg
  • 1,137
3

If you are trying to adjust the \arraycolsep only to obtain the correct spacing around the = sign (or other math operators), then you should consider an alternate approach: Use @{} to eliminate the inter column spacing, and add and extra {} before the equal sign. Compare the output of the two and you will see that the match.

Notes:

  • As others have mentioned if you are using array just to align elements in formulas you should consider other options such as align, and alignat.

Code:

\documentclass{article}
\begin{document}
\noindent
Spacing with array:
\[
\begin{array}{r@{}l}
    a &{}= b 
\end{array}
\]
And without array:
\[
  a = b
\]
\end{document}
Peter Grill
  • 223,288