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.
- 2Sorry, but I don't understand your question. What hinders you from using it in your
pmatrix? 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"?Skillmon– Skillmon2025-12-14 20:33:00 +00:00Commented2 days ago - 2Look that your macro is the same of Torbjørn T.tex.stackexchange.com/questions/33519/…Sebastiano– Sebastiano2025-12-14 22:27:18 +00:00Commented2 days ago
4 Answers4
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}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}- 1
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}- Look that this macro is the same of Torbjørn T.tex.stackexchange.com/questions/33519/…Sebastiano– Sebastiano2025-12-14 22:22:22 +00:00Commented2 days ago
- 1@Sebastiano, that's probably where the OP has got it. I just used what was in his question.invictus– invictus2025-12-15 05:46:22 +00:00Commented2 days ago
- It was unusual for a new user to be able to create a complex macro. Best regards.Sebastiano– Sebastiano2025-12-15 14:12:47 +00:00Commentedyesterday
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}You mustlog in to answer this question.
Explore related questions
See similar questions with these tags.




