# Add symbols to a given matrix

I would like to add symbols and labels to a given matrix. To specify what I an looking for, I will provide some graphical examples below.

Basically, I just want to attach data to a matrix in a way that it is properly aligned. For example, We could add some keys indicating the dimensions of the matrix

Or maybe we could add some labels to the columns

In any case, I would like to know how to align certain data with data inside a given matrix.

If you would like to help, I will provide to you the code of both matrices.

\text{det}\begin{pmatrix} a_0 & a_1 & \dots & a_{n-1} & a_n & 0 & \dots & 0\\ 0 & a_0 & \dots & a_{n-2} & a_{n-1} & a_n & \dots & 0 \\  &  & \ddots &  &  &  & \ddots & \\ 0 & 0 & \dots & a_0 & a_1 & a_2 & \dots & a_n \\ b_0 & b_1 & \dots & b_{m-1} & b_m & 0 & \dots & 0 \\ 0 & b_0 & \dots & b_{m-2} & b_{m-1} & b_m & \dots & 0\\ & & \ddots & & & & \ddots & & \\ 0 & 0 & \dots & b_0 & b_1 & b_2 & \dots & b_m \end{pmatrix}

\text{det}\begin{pmatrix} -a & 0 & \dots & 0 & 0 & 1 & \dots & 0\\ 0 & -a & \dots & 0 & 0 & 0 & \dots & 0 \\ \vdots & \vdots & \ddots & \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \dots & -a & 0 & 0 & \dots & 1 \\ 0 & 0 & \dots & 0 & n & 0 & \dots & 0 \\ 0 & 0 & \dots & 0 & 0 & n & \dots & 0\\ \vdots & \vdots & \ddots & \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \dots & 0 & 0 & 0 & \dots & n \end{pmatrix}=(-a)^{n-1}n^n


With nicematrix it is rather easy and you can use the same tool to do both matrices.

\documentclass[fleqn]{article}
\usepackage{nicematrix}
\usetikzlibrary{decorations.pathreplacing,calligraphy}
\begin{document}
$\det\begin{pNiceArray}{CCCCCCCC}% [create-medium-nodes, code-after = {\begin{tikzpicture}[name suffix = -medium] \draw[thick,decorate, decoration={calligraphic brace,amplitude=3pt,raise=1em}] (1-8.north east) -- (4-8.south east) node[midway,right=1.2em]{m files}; \draw[thick,decorate, decoration={calligraphic brace,amplitude=3pt,raise=1em}] (5-8.north east) -- (8-8.south east) node[midway,right=1.2em]{n files}; \end{tikzpicture}}] a_0 & a_1 & \Cdots & a_{n-1} & a_n & 0 & \Cdots & 0\\ 0 &a_0 & \Cdots & a_{n-2} & a_{n-1} & a_n & \Cdots & 0 \\ & & \Ddots & & & & \Ddots & \\ 0 & 0 & \Cdots & a_0 & a_1 & a_2 & \Cdots & a_n \\ b_0 & b_1 & \Cdots &b_{m-1} & b_m & 0 & \Cdots & 0 \\ 0 & b_0 & \Cdots & b_{m-2} & b_{m-1} & b_m & \Cdots & 0\\ & & \Ddots & & & & \Ddots & \\ 0 & 0 & \Cdots & b_0 & b_1 & b_2 & \Cdots & b_m \\ \end{pNiceArray}$

\bigskip

$\det\begin{pNiceArray}{CCCCCCCC}% [create-medium-nodes,first-row, code-after = {\begin{tikzpicture}[name suffix = -medium] \foreach \X in {4,5,6} {\draw[rounded corners] ([xshift=-1pt]0-\X.north west) |- ([yshift=-1pt]0-\X.south east);} \end{tikzpicture}}] & & & n-1 & k & n+1 & &\\ -a & 0 & \Cdots & 0 & 0 & 1 & \Cdots & 0\\ 0 & -a & \Cdots & 0 & 0 & 0 & \Cdots & 0 \\ \Vdots & \Vdots & \Ddots & \Vdots & \Vdots & \Vdots & \Ddots & \Vdots \\ 0 & 0 & \Cdots & -a & 0 & 0 & \Cdots & 1 \\ 0 & 0 & \Cdots & 0 & n & 0 & \Cdots & 0 \\ 0 & 0 & \Cdots & 0 & 0 & n & \Cdots & 0\\ \Vdots & \Vdots & \Ddots & \Vdots & \Vdots & \Vdots & \Ddots & \Vdots \\ 0 & 0 & \Cdots & 0 & 0 & 0 & \Cdots & n \end{pNiceArray}=(-a)^{n-1}n^n$
\end{document}