3

I am trying to typeset some examples of Gaussian eliminations in LaTeX. I found the gauss package really simple to use, but couldn't figure out how to put a vertical line in between columns. Here is what I have so far (just a regular matrix)

\documentclass[a4paper,12pt]{article}
\usepackage{gauss}
\usepackage{amsmath,amssymb}

\begin{document} $\begin{gmatrix}[p] 2 & 0 & 1 & 1 & 0 & 0 \ 0 & 1 & 0 & 0 & 1 & 0 \ 0 & 0 & 3 & 0 & 0 & 1 \rowops \mult{0}{\cdot \frac{1}{2}} \end{gmatrix}$ \end{document}

I would like it to be like this. Ignore the red color of the pen.

Sebastiano
  • 54,118
  • Your code doesn't compile: Missing $ inserted.. Could you extend your code fragment into a working document we can copy and paste please? It helps people help you and is a polite thing to do, I understand you are new so do not worry about not knowing – JamesT Apr 04 '23 at 07:18
  • 1
    Maybe you will be interested in the following LaTeX package : gaussenv – F. Pantigny Apr 04 '23 at 08:31

4 Answers4

4

You can use https://tex.stackexchange.com/a/146730/4427

\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] 2 & 9 & 1 & \BAR & 1 & 0 & 0 \ 0 & 1 & 0 & \BAR & 0 & 1 & 0 \ 0 & 0 & 3 & \BAR & 0 & 0 & 1 \rowops \mult{0}{\cdot \frac{1}{2}} \end{gmatrix} ] \end{document}

enter image description here

egreg
  • 1,121,712
3

Unfortunately, gauss package does not provide for the use of vertical lines separating columns. I simply used a trick using \bigl| for 3 times.

\documentclass[a4paper,12pt]{article}
\usepackage{gauss}
\usepackage{amsmath,amssymb}

\begin{document} $\begin{gmatrix}[p] 2 & 0 & 1 &\bigl| & 1 & 0 & 0 \ 0 & 1 & 0 &\bigl| & 0 & 1 & 0 \ 0 & 0 & 3 &\bigl| & 0 & 0 & 1 \rowops \mult{0}{\cdot \frac{1}{2}} \end{gmatrix}$ \end{document}

enter image description here

Sebastiano
  • 54,118
2

As an alternative, may I suggest taking a look at the nicematrix package? I used to work with gauss in the way egreg has suggested above until I discovered nicematrix, and I have never looked back :-). It can do what you want and also offers a host of other options. Here is a suggested solution for your question:

\documentclass[a4paper,12pt]{article}
\usepackage{nicematrix}
\usepackage{amsmath,amssymb}

\begin{document} $\begin{pNiceArray}{ccc|ccc}[last-col] 2 & 0 & 1 & 1 & 0 & 0 & \cdot \frac{1}{2}\ 0 & 1 & 0 & 0 & 1 & 0 \ 0 & 0 & 3 & 0 & 0 & 1 \end{pNiceArray}$ \end{document}

enter image description here

0

An alternative without to use gauss package but the simple functions of amsmath.

\documentclass[a4paper,12pt]{article}

\usepackage{amsmath,amssymb}

\begin{document} [\left(\begin{array}{ccc|ccc} 2 & 0 & 1 & 1 & 0 & 0 \ 0 & 1 & 0 & 0 & 1 & 0 \ 0 & 0 & 3 & 0 & 0 & 1 \end{array}\right)\begin{matrix} | \cdot \frac 12 \ \ \ \end{matrix}] \end{document}

enter image description here

Sebastiano
  • 54,118