3

I tried making a vertical line in a matrix and I found two workarounds:

\documentclass{article}\usepackage{amsmath}\makeatletter\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%  \hskip -\arraycolsep  \let\@ifnextchar\new@ifnextchar  \array{#1}}\makeatother\begin{document}\[  \begin{bmatrix}[cccc|c]   1 & 0 & 3 & -1 & 0 \\   0 & 1 & 1 & -1 & 0 \\   0 & 0 & 0 & 0 & 0 \\\end{bmatrix}\]\[\left(\begin{array}{cccc|c}1 & 0 & 3 & -1 & 0 \\0 & 1 & 1 & -1 & 0 \\0 & 0 & 0 & 0 & 0 \\\end{array}\right)\]\end{document}

But I wanted to use this on the following matrix:

\begin{pmatrix} -2 & 2 & -1 \\2 & -3 & 1 \\2& -1 & 1\end{pmatrix}

Also with zeros at the end of every line. But having a negative in very column doesn't seem to work.

F. Pantigny's user avatar
F. Pantigny
52.4k4 gold badges60 silver badges99 bronze badges
asked2 days ago
Oliver Braunsberger's user avatar
New contributor
Oliver Braunsberger is a new contributor to this site. Take care in asking for clarification, commenting, and answering.Check out ourCode of Conduct.
2
  • 2
    Sorry, but I don't understand your question. What hinders you from using it in yourpmatrix? It's just other values, but otherwise basically the same as yourbmatrix. And what do you mean with "But having a negative in very column doesn't seem to work"?Commented2 days ago
  • 2
    Look that your macro is the same of Torbjørn T.tex.stackexchange.com/questions/33519/…Commented2 days ago

4 Answers4

8

Withnicematrix (≥ 7.4).

\documentclass{article}\usepackage{nicematrix}\NewDocumentEnvironment{MyMatrix}{}  {\begin{bNiceMatrix}[r,vlines=-1]}  {\end{bNiceMatrix}}\begin{document}\[\begin{MyMatrix}   1 & 0 & 3 & -1 & 0 \\   0 & 1 & 1 & -1 & 0 \\   0 & 0 & 0 & 0 & 0 \\\end{MyMatrix}\]\end{document}

Output of the above code

answered2 days ago
F. Pantigny's user avatar
7

Withtabularray:

\documentclass{article}\usepackage{tabularray}% the next line adds +pmatrix, +bmatrix... environments, similar to pmatrix, bmatrix...% but they accept optionals arguments like tblr environment\UseTblrLibrary{amsmath} \begin{document}\[\begin{+pmatrix}[colspec={ccc|c}] -2 & 2 & -1 & 0\\2 & -3 & 1 & 0\\2& -1 & 1 & 0\end{+pmatrix}\]\end{document}

result with the +pmatrix environment

answered2 days ago
quark67's user avatar
1
  • 1
    Nice and easy one+1Commentedyesterday
6

It is not very clear what doesn't seem to work from your question. You can surely use the same construction as in the code you provided. If the alignment in the presence of negative numbers is the problem, you can use right-aligned columns.

\documentclass{article}\usepackage{amsmath}\makeatletter\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%  \hskip -\arraycolsep  \let\@ifnextchar\new@ifnextchar  \array{#1}}\makeatother\begin{document}\[\begin{pmatrix}[ccc|c] -2 & 2 & -1 & 0\\2 & -3 & 1 & 0\\2& -1 & 1  & 0\end{pmatrix}\]\[\begin{pmatrix}[rrr|r] -2 & 2 & -1 & 0\\2 & -3 & 1 & 0\\2& -1 & 1  & 0\end{pmatrix}\]\end{document}

enter image description here

answered2 days ago
invictus's user avatar
3
  • Look that this macro is the same of Torbjørn T.tex.stackexchange.com/questions/33519/…Commented2 days ago
  • 1
    @Sebastiano, that's probably where the OP has got it. I just used what was in his question.Commented2 days ago
  • It was unusual for a new user to be able to create a complex macro. Best regards.Commentedyesterday
3

You can usespalign package: see the blank spaces. The default matrices are with the rounded brackets.

\documentclass{article}\usepackage{spalign}  \begin{document}\spaligndelims{[}{]}\[\spalignaugmat{-2 2 -1 0; 2 -3 1 0; 2 -1, 1 0}\]\end{document}

enter image description here

answered2 days ago
Sebastiano's user avatar

You mustlog in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.