Write a pmatrix such that each line and column could be labeled

matrices

There were many cases of how to write block diagonal matrix. However, how to write a pmatrix such that the line and column could be labeled?

enter image description here

Best Answer

This is very easy with nicematrix:

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\[
\begin{pNiceMatrix}[last-col,last-row]
a_{1} & a_{2} & l_{1} \\
a_{3} & a_{4} & l_{2} \\
c_{1} & c_2
\end{pNiceMatrix}
\]

\end{document}

This requires several LaTeX runs at the beginning, but the typesetting will soon stabilize.

enter image description here