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?
[Tex/LaTex] What’s the best way make an “augmented” coefficient matrix
math-modematrices
Related Solutions
You can try the package systeme. Its documentation is in French, but there are many examples to play with.
Your example would be input as
\systeme{
2x + y + 3z = 10,
x + y + z = 6,
x + 3y + 2z = 13}
To get right alignment in the column of right hand sides, one has to manually modify the package code:
\makeatletter
\def\SYS@makesyspreamble@i#1{%
\ifnum#1<\SYS@preamblenum
\SYS@addtotok\SYS@systempreamble{\hfil$##$&\hfil$##$&}%
\expandafter\SYS@makesyspreamble@i\expandafter{\number\numexpr#1+\@ne\expandafter}%
\else
\SYS@addtotok\SYS@systempreamble{\hfil$##$&$##$&\hfil$##$\null}%
\ifSYS@extracol
\SYS@addtotok\SYS@systempreamble{&\SYS@extracolstart##\SYS@extracolend\hfil\null}%
\fi
\SYS@addtotok\SYS@systempreamble{\cr\SYS@strutup}%
\fi
}
\makeatother
The patch is simply changing $##$\hfil
into \hfil$##$
but, since this involves #
it's not possible to use etoolbox's \patchcmd
.
One can modify the distance between the lines by saying something like
\syslineskipcoeff{1.2}
and act on the column spacing with the parameter \tabskip
; so, for example,
\[
\syslineskipcoeff{1.2}\setlength{\tabskip}{3pt}
\systeme{
2x + y + 3z = 10,
x + y + z = 6,
x + 3y + 2z = 13}
\]
will spread out the equations both vertically and horizontally. The \syslineskipcoeff
can also be issued globally, in the preamble of the document; not the horizontal spacing, though, as \tabskip
influences all TeX tables, tabular
environments included.
The package can't support typing |
somewhere like in arrays. But we can emulate it:
\documentclass{article}
\usepackage{amsmath}
\usepackage{gauss}
% patch gauss macros for doing their work in `align'
% and other amsmath environments; see
% http://tex.stackexchange.com/questions/146532/
\usepackage{etoolbox}
\makeatletter
\patchcmd\g@matrix
{\vbox\bgroup}
{\vbox\bgroup\normalbaselines}% restore the standard baselineskip
{}{}
\makeatother
\newcommand{\BAR}{%
\hspace{-\arraycolsep}%
\strut\vrule % the `\vrule` is as high and deep as a strut
\hspace{-\arraycolsep}%
}
\begin{document}
\[
\begin{gmatrix}[p]
1 & 2 & \BAR & 3 \\
4 & 5 & \BAR & 6 \\
7 & 8 & \BAR & 9
\rowops
\swap{0}{1}
\mult{0}{\cdot 7}
\add[5]{1}{2}
\end{gmatrix}
\]
\end{document}
In other words, I create a new column that takes no horizontal space, where I place a bar.
Best Answer
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:
(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.