[Tex/LaTex] braces spanning few rows or columns of a matrix in latex

bracesmatrices

I am trying to put braces on matrix that cover just few rows or columns.

I have come kinda close for the columns but no idea for the rows.

This is the example I have been working on:

\documentclass{minimal}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
A = \begin{array}{c@{\!\!\!}l}
\left( \begin{array}[c]{ccc}
a1 & \cdots & aN\\
b1 & \cdots & bN\\
\vdots &  & \vdots\\
z1 & \cdots & zN \\

\end{array}  \right)

&
\begin{array}[c]{ll}
\left. \begin{array}{c} \vphantom{1cm}  \\ \vphantom{2*\vdots}
\\ \vphantom{1cm} \end{array} \right\} & \text{$n_1$ times} \\

\end{array}
\end{array}
\end{equation*}

\end{document}

which produces this:

enter image description here

Does anyone have any idea?

Best Answer

If you want to span only some rows, you can use nicematrix which will put a Tikz node behind each cell of the matrix and then use the commands of Tikz to draw the brace and its label.

\documentclass{minimal}
\usepackage{nicematrix,tikz}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{equation*}
A = \begin{pNiceMatrix}%
a1 &\Hdotsfor{2} & aN\\
b1 &\Hdotsfor{2} & bN\\
\Vdots & & & \Vdots\\
z1 & \Cdots &\Cdots & zN \\
\CodeAfter
   \tikz
   \draw [decorate,decoration = brace]
        ([xshift=3mm]2-4.north east) to node [auto = left] {$n_1$ times} 
        ([xshift=3mm]4-4.south east) ;
\end{pNiceMatrix}
\end{equation*}
\end{document}

enter image description here