5

I have made a custom matrix environment for using Gauss Jordan elimination, I need a vertical bar between the two halves of my matrix.

Here is what I have slopped together

\newenvironment{gjmatrix}[1] {
    \left[\begin{array} { @{}*{#1}{c}|@{}*{#1}{c}@{} }
} {
    \end{array}\right]
}

This is almost perfect. But it doesn't give me enough spacing after the bar. Lack of spacing.

Could someone help me out? How do I adjust this so it has proper and uniform spacing with everything else.

1
  • 1
    Welcome to TeX.SE.
    – Mico
    Oct 1 at 14:14

2 Answers 2

4

I suggest you change |@{} to |, i.e., get rid of the @{} particle that follows |. If keeping | is a bit too terse for you taste, you could also write |@{\hspace{\arraycolsep}}, to make explicit which operation is supposed to take place immediately after |.

If you are surmising that @{} means "don't insert whitespace or anything else" and that omitting @{} means "perform the default operation" (which happens to be to insert whitespace, in the amount of \arraycolsep), you would be entirely correct. :-)

enter image description here

\documentclass{article}
\usepackage{array} % optional, but recommended
\newenvironment{gjmatrix}[1]{% 
   \left[ \begin{array}{ @{} *{#1}{c} | *{#1}{c} @{} }}{%  
   \end{array} \right]}

\begin{document}
\[
\begin{gjmatrix}{3}
  -1 &  2 & -2 & 1 & 0 & 0 \\
   0 &  1 & -1 & 0 & 1 & 0 \\
  -3 & -1 &  0 & 0 & 0 & 1
\end{gjmatrix}
\]
\end{document}
3

You have @{} after |, so you're suppressing the standard intercolumn space before the column following the vertical line.

I suggest a slightly different approach, because you can also use Gauss-Jordan also on augmented matrices having fewer (or even more) columns after the line than before it.

\documentclass{article}

\NewDocumentEnvironment{gjmatrix}{mO{#1}}
 {\left[\begin{array}{ @{} *{#1}{c} | *{#2}{c} @{} }}
 {\end{array}\right]}

\begin{document}
\[
\begin{gjmatrix}{3}
  -1 &  2 & -2 & 1 & 0 & 0 \\
   0 &  1 & -1 & 0 & 1 & 0 \\
  -3 & -1 &  0 & 0 & 0 & 1
\end{gjmatrix}
\qquad
\begin{gjmatrix}{3}[2]
  -1 &  2 & -2 & 1 & 0 \\
   0 &  1 & -1 & 0 & 1 \\
  -3 & -1 &  0 & 0 & 0
\end{gjmatrix}
\]

\[
\begin{gjmatrix}{4}
  -1 &  2 & -2 & 1 & 1 & 0 & 0 & 0\\
   0 &  1 & -1 & 0 & 0 & 1 & 0 & 0\\
  -1 &  2 & -2 & 0 & 0 & 0 & 1 & 0\\
  -3 & -1 &  0 & 0 & 0 & 0 & 0 & 1
\end{gjmatrix}
\qquad
\begin{gjmatrix}{4}[1]
  -1 &  2 & -2 & 1 & 0 \\
   0 &  1 & -1 & 0 & 1 \\
  -1 &  2 & -2 & 0 & 0 \\
  -3 & -1 &  0 & 0 & 0
\end{gjmatrix}
\]

\end{document}

The trailing optional argument is the number of columns after the line and defaults to the same number as in the mandatory argument.

enter image description here

You must log in to answer this question.

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