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).
3 Answers
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.
- 757,742
- 43,767
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,137
-
Thanks a lot, this is the answer that really answers the question asked. – Martin Argerami Mar 24 '21 at 23:04
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
arrayjust to align elements in formulas you should consider other options such asalign, andalignat.
Code:
\documentclass{article}
\begin{document}
\noindent
Spacing with array:
\[
\begin{array}{r@{}l}
a &{}= b
\end{array}
\]
And without array:
\[
a = b
\]
\end{document}
- 223,288
eqnarrayenvironment or thatarrayenvironment to simulate an equation array? If its the former, please read\eqnarrayvs\alignand useamsmath's\aligninstead. Please clarify. – Werner Feb 29 '12 at 20:07