TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to renew the bmatrix environment to have alignment?

I would like the following vectors to show aligned:

\begin{bmatrix}
 -0.505 & \\
 -0.141 & \\
 0.144 & \\
 0.839 & \\
\end{bmatrix}
share|improve this question

Example with matrix environment. Work also for bmatrix

Taken from here. Article by Stefan Kottwitz.

This code produces unaligned numbers:

\[
  \begin{pmatrix}
    1 &  2 &  1 \\
    0 & -2 & -3 \\
    0 & 3 &  -2
  \end{pmatrix}
\]

enter image description here

However, the environment can be renewed to support alignment:

\makeatletter
\renewcommand*\env@matrix[1][c]{\hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{*\c@MaxMatrixCols #1}}
\makeatother

Now it is possible to do:

\[
  \begin{pmatrix}[r]
    1 &  2 &  1 \\
    0 & -2 & -3 \\
    0 & 3 &  -2
  \end{pmatrix}
\]

which outputs:

enter image description here

share|improve this answer
5  
which is already build into the bmatrix* environment, which is available through the mathtools package – daleif Jun 17 '13 at 11:04
    
What I like about Alan's answer is that it allows me to choose the default (by replacing [c] with [r] in the definition, say). – Martin Argerami Nov 4 '15 at 22:31

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.