39

Possible Duplicate:
What's the best way make an “augmented” coefficient matrix?

I am trying to make a vertical line in a matrix in LaTeXiT. I have read that it should be possible using the following:

\begin{bmatrix}{cccc|c}
1 & 0 & 3 & -1 & 0 \\
0 & 1 & 1 & -1 & 0 \\
0 & 0 & 0 & 0 & 0 \\
\end{bmatrix}

But when doing so, this is my output:

enter image description here

0

2 Answers 2

67

The bmatrix environment does not provide this facility (see section 4.1 of the amsmath package documentation). You can use the array environment instead.

\[
\left[
\begin{array}{cccc|c}
1 & 0 & 3 & -1 & 0 \\
0 & 1 & 1 & -1 & 0 \\
0 & 0 & 0 & 0 & 0 \\
\end{array}
\right]
\]
6
  • 17
    Possibly adding @{} at the sides: @{}cccc|c@{}, so as to give a similar result to bmatrix.
    – egreg
    Commented Nov 3, 2011 at 9:33
  • Thank you very much. The output of this is just like a bmatrix.
    – SimonBS
    Commented Nov 3, 2011 at 9:43
  • 4
    @egreg: Could you explain how the @{} works? I see that it has the effect of reducing the whitespace between the [ and ] and the matrix contents.
    – user001
    Commented Mar 13, 2012 at 17:30
  • 3
    With @{...} you tell LaTeX to put ... in place of the default intercolumn space, which is applied also at the start and end of the tabular.
    – egreg
    Commented Mar 13, 2012 at 17:37
  • 1
    @user3123159 \left( and \right) should do.
    – egreg
    Commented Jun 1 at 8:57
45

That won't work with the matrix environment from amsmath, however Stefan Kottwitz wrote about a workaround for this on his blog.

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
  \hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{#1}}
\makeatother
\begin{document}
\begin{equation}
  \begin{bmatrix}[cccc|c]
   1 & 0 & 3 & -1 & 0 \\
   0 & 1 & 1 & -1 & 0 \\
   0 & 0 & 0 & 0 & 0 \\
\end{bmatrix}
\end{equation}
\end{document}

enter image description here

10
  • 20
    @barbarabeeton This would be a nice addition for amsmath, wouldn't it?
    – egreg
    Commented Nov 3, 2011 at 9:36
  • @Chou It's up to the person asking the question to decide which answer was most helpful for him or her. It's not always the highest voted answer that is accepted. Commented Jun 21, 2015 at 7:37
  • I know the rules here. You may take my words as an indirect praise; for your work helped me. :) By the way, I was not aware of the number of votes til your comment coming out.
    – Yes
    Commented Jun 21, 2015 at 9:30
  • The double-backslash line-break indicators seem to have morphed into single-backslash spacers. You may want to edit the code a bit.
    – Mico
    Commented Jan 23, 2017 at 12:18
  • 1
    @user3123159 The example in my answer worked fine when I tested it on Overleaf just now, so I would guess there is something else causing the problem. I suggest you make a small, complete example demonstrating the problem and ask a new question. Commented Feb 2 at 16:13

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