TransWikia.com

How can I subtract 1 from the number of columns to repeat in array environment?

TeX - LaTeX Asked on July 30, 2021

I was trying to create an environment for an augmented matrix and came across this answer, which gave me this code

newenvironment{amatrix}[1]{%
  left(begin{array}{@{}*{#1}{c}|c@{}}
}{%
  end{array}right)
}

used as

begin{amatrix}{2}
   1 & 2 & 3   a & b & c
 end{amatrix}

It works great, but it drives me nuts that the argument is one fewer than the total number of columns in the augmented matrix. I tried changing the #1 to #1-1, but that does not seem to work. The closest thing I could find was the calc package, but that only works in certain circumstances, and this does not seem to be one of them.

So my question is: is there a way to either redefine the amatrix environment so that the argument matches the total number of columns in the augmented matrix? An even better solution would be one where I don’t have to put in an argument at all, but I don’t want to be greedy here.

One Answer

This addresses your requirement of specifying the number of columns. numexpr#1-1 removes 1 from the input:

enter image description here

documentclass{article}

newenvironment{amatrix}[1]{%
  left(begin{array}{@{} *{numexpr#1-1}{c} | c @{}}
}{%
  end{array}right)
}

begin{document}

[
  begin{amatrix}{3}
    1 & 2 & 3 
    a & b & c
  end{amatrix}
]

end{document}

Answered by Werner on July 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP