Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
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 '12 at 20:07
2  
A minimal example would certainly bring light into the darkness. –  Thorsten Donig Feb 29 '12 at 20:44
add comment

3 Answers

up vote 3 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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