-1

enter image description here

The color doesn't really matter thanks

CarLaTeX
  • 62,716

3 Answers3

4

If it's important to assign the same width to all four columns, whether or not they contain - ("minus") symbols, I suggest you employ the wr column type that's provided by the array package and measure the width of the cell that has the largest natural width. If the same-width-for-all-columns criterion is not important, just use the r column type for all four columns.

enter image description here

Either way, do make sure to apply math mode rather than text mode to the entries of the matrix -- this is done in code shown below by employing array environments -- and to suppress the default whitespace padding (via @{} particles) at the edges of the matrices.

\documentclass{article}
\usepackage{calc}  % for '\widthof' macro
\usepackage{array} % for 'w' column type and '\newcolumntype' macro)
\newcolumntype{R}{wr{\widthof{$-1$}}}

\begin{document} [ \left(\begin{array}{@{} {3}{R} | R @{}} 2 & 1 & 3 & 1 \ 4 & 4 & 9 & -4 \ -2 & 5 & 3 & -1 \end{array}\right) \qquad % same matrix, but with 'r' column type \left(\begin{array}{@{} {3}{r} | r @{}} 2 & 1 & 3 & 1 \ 4 & 4 & 9 & -4 \ -2 & 5 & 3 & -1 \end{array}\right) ] \end{document}

Mico
  • 506,678
4

With {pNiceArray} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\[
\begin{pNiceArray}{*3r|r}
 2 & 1 & 3 &  1 \\
 4 & 4 & 9 & -4\\
-2 & 5 & 3 & -1
\end{pNiceArray}
\]
\end{document}

Output of the above code

F. Pantigny
  • 40,250
2
\documentclass{article}
\usepackage{amsmath}
\begin{document}

\[
\left(\begin{array}{*3r|r}
 2 & 1 & 3 &  1 \\
 4 & 4 & 9 & -4\\
-2 & 5 & 3 & -1
\end{array}\right)
\]
\end{document}

enter image description here

user187802
  • 16,850
  • 4
    To make the result look more like a "standard" typeset matrix, you may also want to suppress the whitespace padding at the left-hand and right-hand edges of the matrix. This may be done easily by changing \begin{array}{*3r|r} to \begin{array}{@{}*3r|r@{}}. – Mico Oct 01 '22 at 07:32
  • 2
    no, I may not ... – user187802 Oct 01 '22 at 07:50
  • 1
    @Mico thanks for the explanation the meaning of @{} – Black Mild Oct 02 '22 at 06:43