The color doesn't really matter thanks
- 62,716
- 311
-
Unless there's an extra requirement of same column width it's just math mode - What's the best way make an "augmented" coefficient matrix? - TeX - LaTeX Stack Exchange – user202729 Oct 01 '22 at 09:48
3 Answers
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.
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}
- 506,678
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}
- 40,250
\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}
- 16,850
-
4To 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
-
1



