Horizontal Line in Array
You're missing the vertical line |
in the column specification and a \multicolumn{1}{r}
for the element in the top left corner:
\documentclass{article}
\begin{document}
\[
\left(
\begin{array}{ r | *{3}{r} }
\multicolumn{1}{r}{2} & 2 & -1 & 3 \\
\cline{2-4}
0 & 1 & 3 & 4 \\
0 & 1 & 3 & 4 \\
0 & 3 & 9 & 6 \\
0 & 1 & 3 & -2
\end{array}
\right)
\]
\end{document}
For a more evenly distributed spacing around the last three columns, consider using \phantom{-}2
in the first row:
\documentclass{article}
\begin{document}
\[
\left(
\begin{array}{ r | *{3}{r} }
\multicolumn{1}{r}{2} & \phantom{-}2 & -1 & 3 \\
\cline{2-4}
0 & 1 & 3 & 4 \\
0 & 1 & 3 & 4 \\
0 & 3 & 9 & 6 \\
0 & 1 & 3 & -2
\end{array}
\right)
\]
\end{document}
With nicematrix
. The environments of nicematrix
create PGF/Tikz nodes under the rows, columns and cells and the array and it's possible to use them to draw whatever you want with Tikz.
\documentclass{article}
\usepackage{nicematrix}
\usepackage{tikz}
\begin{document}
\[
\begin{pNiceMatrix}[r,right-margin,columns-width=auto]
2 & 2 & -1 & 3 \\
0 & 1 & 3 & 4 \\
0 & 1 & 3 & 4 \\
0 & 3 & 9 & 6 \\
0 & 1 & 3 & -2
\CodeAfter
\tikz \draw ([xshift=4pt]row-6-|col-2) |- (row-2-|col-5) ;
\end{pNiceMatrix}
\]
\end{document}