When studying systems of linear equations, it's nice to remind people that the last column of the coefficient matrix holds the constants. This is often done in books by putting a vertical line between the last column and the next to last column. What is a good way to do this in LaTex?


One way to do this is implemented in the (free, in both senses!) online linear algebra textbook Linear Algebra by Jim Hefferon. It's written in LaTeX and is open-source so one can download the book and its attendant style files. One of them, called linalgjh.sty is about typesetting common linear algebra stuff such as augmented matrices and row reductions and the like. The code for the augmented matrices is:


and is used as:

   1 & 2 & 3 \\  a & b & c

(note that the argument is one less than the total number of columns). I guess that the @{}s at the start and end are to get the spacing right with the parentheses (mentioned by TH in a comment to fabikw's similar answer).

That style file has several other useful linear algebra macros that may be useful.

| improve this answer | |
  • 1
    This example doesn't work for me. pdflatex says Missing $ inserted. – Björn Lindqvist Mar 12 '17 at 14:27
  • 3
    For latex newbies (like me): You have to put the example inside \[ and \] latex codes. – Björn Lindqvist Mar 12 '17 at 14:40

If you build your own environment using array, you're on the safe side. I would extend an internal macro of amsmath using an optional argument.


  • It extends several matrix environments at the same time (matrix, pmatrix, bmatrix, Bmatrix, vmatrix, Vmatrix).

  • The names and meanings of those environments remain (not apmatrix etc.)

  • Spacing etc. is the same like in amsmath.

  • You could do more than just insert a vertical line (use color and alignment, for instance right aligned columns because of minus signs).

  • If you omit the optional argument, it acts exactly like the amsmath environment.


  • Since you redefine an internal macro, it might not work if the original package changes its code. But amsmath.sty has not been changed for more than 10 years. If there's a change in the matrices later, you could adjust your own macro.


Here's the redefinition, just put it in your preamble after loading amsmath:

\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
  \hskip -\arraycolsep

I had to use \makeatletter ... \makeatother because of the @ in macro names. The optional argument is the standard amsmath argument to \array. The original definition in amsmath is:

\def\env@matrix{\hskip -\arraycolsep
  \array{*\c@MaxMatrixCols c}}

So, there's not much that's been changed.


Simple augmented matrix:

  1 & 2 & 3\\
  4 & 5 & 9

More complex use, with different alignment, spacing and color:

  a & b & 1  &  4 \\
  c & d & -2 & -3


alt text

Just remove the optional argument in brackets and you will get the standard pmatrix or bmatrix.

I've used this code and examples in a blog post in 2008: An extension to amsmath matrix environments.

If you don't wish to redefine that internal macro, you could give it a different name and build your amatrix environment on it exactly the same way that amsmath does with pmatrix.

| improve this answer | |
  • 1
    From some quick testing it seems to do nothing to the starred versions of the matrix commands from mathtools.sty, but it's not like that matters much when you have full-featured array options available for all your matrix commands – kahen Nov 6 '11 at 2:27
  • I doubt anyone will see this, but is there a way to have a default alignment? E.g. Default to aligning the columns right even if no arguments are specified? If not, is there a way to specify general right alignment without putting as many r's as there are columns? – Gigi Bayte 2 Apr 21 at 11:20

If you are using an array to input the matrix, you just have to specify something like

 2 & 0 & 1\\  
 0 & 1 & 1  
| improve this answer | |
  • 2
    That's not a good way to do it. The spacing is wrong between the parentheses and the matrix. – TH. Aug 24 '10 at 4:42
  • Wouldn't \bigl and \bigr be better here? – user914 Aug 24 '10 at 5:17
  • 2
    As Andrew Stacey points out, @{} is all that's needed to fix up the spacing. That was eluding me. – TH. Aug 24 '10 at 7:27
  • I like that this answer does not require any unusual packages or difficult to understand hacks. – shuhalo Jan 19 at 23:39

The easybmat package provides a way to add all sorts of lines between cells in a matrix, including dashed lines which I seem to recall being popular in my undergraduate linear algebra text.

Edit: Here's an example. I'm actually not thrilled about the spacing.

a_{11} & a_{12} & b_1\\
a_{21} & a_{22} & b_2
| improve this answer | |

I would do something like this:

1 & 1 & 1 & 1 \\ 
8 & 4 & 2 & 1 \\ 
64 & 16 & 4 & 1 \\ 
| improve this answer | |
  • 1
    What's \centering doing? Also, $$ is best avoided in LaTeX; prefer \[..\]. – egreg Sep 3 '13 at 13:59
  • Without the \centering, the matrix would be aligned to the left. – qed Sep 3 '13 at 14:21
  • 3
    In math mode there is no alignment it's centered by default. See also tex.stackexchange.com/questions/503/why-is-preferable-to . – percusse Sep 3 '13 at 19:36
  • Indeed. But last time I used this, I could not have the matrix centered without using the \centering command. Very strange. – qed Sep 4 '13 at 13:52

If for some reason (e.g. you try to make augmented matrix in Pages) other answers do not work, you can make an augmented matrix with two matrices inside delimiters of your choice:

    1 & 2 & 3 \\
    1 & 2 & 3 \\
    1 & 2 & 3 \\
    1 & 2 & 3 \\
      4  \\
      4  \\
      4  \\
      4  \\

This code produces a matrix like this:
Matrix example

You can modify space between delimiters by adding \, or other spacers.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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