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).

2
  • 2
    Are you using the eqnarray environment or that array environment to simulate an equation array? If its the former, please read \eqnarray vs \align and use amsmath's \align instead. Please clarify.
    – Werner
    Feb 29, 2012 at 20:07
  • 3
    A minimal example would certainly bring light into the darkness. Feb 29, 2012 at 20:44

3 Answers 3

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.

0
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.

1
  • Thanks a lot, this is the answer that really answers the question asked. Mar 24, 2021 at 23:04
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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .