# How to write a pmatrix such that each line and column could be labeled?

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?

• Welcome to TSE. Did you try to do a searcho for matrix and label? Aug 8 '21 at 18:14
• You can see the blkarray package. Aug 8 '21 at 18:26
• @Bernard is there a way to just use amsmath etc.? there's been to many packages and some of them were not quite compatible with each other. Aug 8 '21 at 18:30
• It has no incompatibility I know of. It's a small package which loads array, and it works fine within amsmath. Aug 8 '21 at 18:41
• @Bernard blkarray isn't based on array package at all it is a completely separate tabular implementation (and 2227 lines long, although a lot comments of course) Aug 8 '21 at 20:40

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.