3

How can I right-align columns and increase spacing between rows in gmatrix? For example, I would like to do that in the following matrix:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{gauss}   

\begin{document}
\[
 \begin{gmatrix}[b]
1&\frac72&\frac12\\
0&-\frac{29}2&-\frac12
 \rowops
 \mult{1}{\cdot \left(-\frac2{29}\right)}
 \end{gmatrix}
\]

\end{document}

3 Answers 3

1

The gauss package uses low level methods for typesetting the matrix.

This works, the settings are exaggerated settings for displaying the result.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{gauss}

\begin{document}
\[
\linespread{3}\selectfont
\addtolength{\arraycolsep}{20pt}
\begin{gmatrix}[v]
 1 & 0 & 5 & 7 & 2 \\
 3 & 1 & 1 & 5 & 1 \\
 1 & 0 & -7 & 1 & 4 \\
 4 & 3 & 6 & 5 & 4\\
 1 & 7 & 9 & 4 & 3 \\
 0 & 0 & 8 & 0 & -1
\rowops
 \add[-3]01
 \add[-1]02
 \swap34
 \mult5{\cdot   0}
 \add[x^2-1]53
\colops
 \swap01
 \mult3{\cdot   1}
 \add[0]24
\end{gmatrix}
\]

\end{document}

Adjust the argument to \linespread and the argument to \addtolength to suit.

enter image description here

If you want right alignment, add

\makeatletter\def\g@post{\relax$}\makeatother

to the settings before \begin{gmatrix}.

Here's an interface for doing the settings in a simpler way. I define a new xgmatrix environment which takes an optional argument with a set of key-value pairs:

  • type corresponds to the optional argument to gmatrix for setting the fences

  • right sets right alignment of columns; if not specified, center alignment is used

  • spread is the \linespread factor

  • colsep sets the intercolumn space

Here's the code:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{gauss}
\usepackage{xparse}

\ExplSyntaxOn
\keys_define:nn { gauss }
 {
  type .tl_set:N = \l_gauss_type_tl,
  type .initial:n = {},
  right .code:n = \tl_set:cn { g@post } { \relax$ },
  right .value_forbidden:n = true,
  spread .tl_set:N = \l_gauss_spread_tl,
  spread .initial:n = 1,
  colsep .dim_set:N = \l_gauss_colsep_dim,
  colsep .initial:n = \arraycolsep,
 }
\NewDocumentEnvironment{xgmatrix}{O{}}
 {
  \keys_set:nn { gauss } { #1 }
  \linespread{\l_gauss_spread_tl}\selectfont
  \setlength{\arraycolsep}{\l_gauss_colsep_dim}
  \begin{gmatrix}[\l_gauss_type_tl]
 }
 {
  \end{gmatrix}
 }
\ExplSyntaxOff

\begin{document}
\[
\begin{xgmatrix}[spread=3,colsep=20pt,right,type=v]
 1 & 0 & 5 & 7 & 2 \\
 3 & 1 & 1 & 5 & 1 \\
 1 & 0 & -7 & 1 & 4 \\
 4 & 3 & 6 & 5 & 4\\
 1 & 7 & 9 & 4 & 3 \\
 0 & 0 & 8 & 0 & -1
\rowops
 \add[-3]01
 \add[-1]02
 \swap34
 \mult5{\cdot   0}
 \add[x^2-1]53
\colops
 \swap01
 \mult3{\cdot   1}
 \add[0]24
\end{xgmatrix}
\]

\end{document}
1
  • It looks like the combination of \vspace with \makeatletter\def\g@post{\relax$}\makeatother will give me what I was looking for. Thank you for your help. Nov 4, 2016 at 19:39
1

You could do it with a TABstack instead. Horizontal gap between matrix entries, as well as vertical baselineskip between rows, is easily specified, as shown in the MWE.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{gauss}   
\usepackage{tabstackengine}
\stackMath
\begin{document}
\centering
GMATRIX:
\[
 \begin{gmatrix}[b]
1&\frac72&\frac12\\
0&-\frac{29}2&-\frac12
 \rowops
 \mult{1}{\cdot \left(-\frac2{29}\right)}
 \end{gmatrix}
\]
TABSTACK:
\[
\setstackgap{L}{1.4\baselineskip}
\setstacktabbedgap{1.2em}
\abovebaseline[-\dp\strutbox]{\bracketMatrixstack[r]{
1&\frac72&\frac12\\
0&-\frac{29}2&-\frac12
}}
\mid\cdot\left(-\textstyle\frac2{29}\right)
\]
\end{document}

enter image description here

For OP's 2nd problem type:

\documentclass{article} 
\usepackage[T1]{fontenc} 
\usepackage[utf8]{inputenc} 
\usepackage{gauss}
\usepackage{tabstackengine}[2016-10-04]
\stackMath
\newcommand\leftlooparrow[1][]{\kern3pt%
  \Shortstack[r]{{\leftarrow}\mkern-7mu{-}%
    \rlap{\abovebaseline[.5pt]{\scriptscriptstyle\,#1}}\\
    \rule{.5pt}{1\dimexpr\Lstackgap}\mkern2mu% WHERE 1 REPLACED WITH HOW MANY ROWS
    \mkern-.5mu\\ 
    {-}\mkern-4mu{-}}%
}
\begin{document} 
\centering
GMATRIX:
\[ 
\begin{gmatrix}[b] 
1&\frac72&\frac12\\ 0&1&-\frac1{29} 
\rowops \add[\cdot \left(-\frac 72\right)]{1}{0} 
\end{gmatrix} 
\] 
TABSTACK:
\[
\setstackgap{L}{1.4\baselineskip}
\setstackgap{S}{-3.1pt}
\setstacktabbedgap{1.2em}
\abovebaseline[-\dp\strutbox]{\bracketMatrixstack[r]{
1&\frac72&\frac12\\
0&1&-\frac1{29}
}}
\leftlooparrow[+]\cdot\left(-\textstyle\frac7{2}\right)
\]
\end{document}

enter image description here

5
  • Thank you for your quick response and a solution to the posted question. It is important for me to have other functions from gauss. Are they available in TABstack? In particular, I need to be able to do the following. \documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{gauss} \begin{document} [ \begin{gmatrix}[b] 1&\frac72&\frac12\\ 0&1&-\frac1{29} \rowops \add[\cdot \left(-\frac 72\right)]{1}{0} \end{gmatrix} ] \end{document} Nov 4, 2016 at 15:37
  • I apologize for the above. I am not sure how to add TEX code to my comment. Nov 4, 2016 at 15:40
  • @PiotrMikusinski Please see edit. Nov 4, 2016 at 16:06
  • It looks perfect, but unfortunately it does not tex on my computer. I get the following message: Argument of \reserved@a has an extra }. Nov 4, 2016 at 19:22
  • @PiotrMikusinski Perhaps you need to upgrade the stackengine and tabstackengine packages, which were recently upgraded. Nov 4, 2016 at 21:15
1

A simple \vspace at the relevant space is enough. You also can define a mygmatrix environment (or patch gmatrix) in dorder to locally redefine \mathstrut:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{gauss}

\newenvironment{mygmatrix}{\def\mathstrut{\vphantom{\big(}}\gmatrix}{\endgmatrix}

\begin{document}%
\[\
 \begin{gmatrix}[b]
1 &{\frac72} & \frac12\vspace{3pt}\\
0 & \frac{29}2 &
 \rowops
 \mult{1}{\cdot \bigl(-\frac2{29}\bigr)}
 \end{gmatrix}
\]

\[
 \begin{mygmatrix}[b]
1 &{\frac72} & \frac12\vspace{3pt}\\
0 & \frac{29}2 &
 \rowops
 \mult{1}{\cdot \bigl(-\frac2{29}\bigr)}
 \end{mygmatrix}
\]

\end{document} 

enter image description here

2
  • I like the \vspace solution. Do you have something equally simple to right-align the columns? Nov 4, 2016 at 19:34
  • Unfortunately no. The package code is beyond my abilities.
    – Bernard
    Nov 4, 2016 at 19:47

You must log in to answer this question.

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