16

I would like to typeset row operations on a augmented matrix, but the "gauss"-package does not seem to support the vertical line just before the last column, any way to do this?

Thanks!

msx
  • 491
  • 4
  • 11

1 Answers1

18

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.

enter image description here

egreg
  • 1,121,712
  • 1
    I tried your solution, but there are gaps in the vertical line between the rows, sadly. – msx Nov 24 '13 at 18:44
  • @mhle This might depend on the material in the rows; without an example it's difficult to say. – egreg Nov 24 '13 at 19:05
  • here is an example,

    \documentclass[a4paper,twoside,12pt]{article}

    \usepackage{gauss}

    \newcommand{\BAR}{% \hspace{-\arraycolsep}% \strut\vrule % the \vrule is as high and deep as a strut \hspace{-\arraycolsep}% }

    \begin{document} \begin{align} \begin{gmatrix}[p] -1 & 0 & 1 &\BAR& 1 \ 1 & 1 &-2 &\BAR& 0 \ 0 & 1 & -1&\BAR& 0 \rowops \add{0}{1} \mult{0}{\cdot -1} \end{gmatrix} \end{align} \end{document}

    – msx Nov 24 '13 at 19:21
  • Hi @egreg, it seems to be the align environment that's the problem... – msx Nov 24 '13 at 20:03
  • @mhle Just yesterday I answered a question about gmatrix and align: http://tex.stackexchange.com/questions/146532/gauss-package-gmatrix-not-equivalent-to-corresponding-amsmath-environment Try the workaround there and you should get what you're looking for. – egreg Nov 24 '13 at 20:05
  • @egreg I think the matrix must be \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} Otherwise the code doesn't run. What I corrected is that the rows must be separated with \, not . – Veliko Jan 11 '17 at 19:42
  • 1
    @Veliko For some reason, many lines of code have been modified by the site. I'll fix it – egreg Jan 11 '17 at 20:31
  • Nice workaround. I wanted to make \BAR local to the gmatrix environment, so I tried to put the definition inside \apptocmd{gmatrix}{\newcommand{\BAR}...}{}{}. Didn't work. Do you know how I might do that? – Matthew Leingang Feb 19 '17 at 02:55
  • Never mind, it seems \pretocmd{gmatrix}{\newcommand{\BAR}... works fine. – Matthew Leingang Feb 19 '17 at 03:15