# Labelling a matrix using a brace in latex

Hey, I want to add two braces as labels for a matrix. I am able to add the top brace label "r". But when I add the bottom "m - r" label, it becomes branched. Here's my code in Latex.

$R = \raisebox{0.5em}{r \left\{ \rule[2em]{0pt}{0pt} \right. } \raisebox{-2em}{m - r \left\{ \rule[0.5em]{0pt}{0pt} \right. } \left[ \begin{array}{ccc|cccc} 1 & & & b_{1, r + 1} & b_{1, r + 2} & \ldots & b_{1n}\\ & \ddots & & \ldots & \ldots & \ddots & \ldots \\ & & 1 & b_{r, r + 1} & b_{r, r + 2} & \ldots & b_{rn} \\ \hline & O & & & O & & \end{array} \right]$

• Welcome to TeX.SE. Hope nicematrix may complete your expectation Commented Jun 1, 2023 at 12:29
• I know the site is about TeX questions, but IMHO this would be a great opportunity to ask yourself what you really want/need to say. The display without the braces makes it pretty clear that there are n columns and the "identity bit" is r x r. So you could omit braces and write the passage as "...the m x n matrix <display>R=...</display>. If you feel this is not clear enough, add, "where the first r rows begin with an r x r identity matrix and the remaining m-r rows are entirely zero". It's not obligatory to write everything in symbols. Commented Jun 1, 2023 at 23:41
• BTW re my previous comment: I tried to write things like $m\times n$ but it did not render properly. Is mathmode not recognised in comments on this site? Or did I do something wrong? Commented Jun 1, 2023 at 23:47

Here is a solution with nicematrix. Note the use of \cdots and \vdots. Also the O in the bottom right quadrant is centered in the block, not in its own column.

\documentclass{article}

\usepackage{nicematrix}

\begin{document}
$R = \begin{bNiceArray}{ccc|cccc}[first-col, margin] \Block{3-1}{\scriptstyle {r\hspace{2mm}}} & 1 & & & b_{1, r + 1} & b_{1, r + 2} & \cdots & b_{1n}\\ & & \ddots & & \vdots & \vdots & \ddots & \vdots \\ & & & 1 & b_{r, r + 1} & b_{r, r + 2} & \cdots & b_{rn} \\ \hline \scriptstyle {m-r\hspace{2mm}} & & O & & \Block{1-4}{O} & & & \CodeAfter \SubMatrix\{{1-1}{3-7}.[left-xshift=3mm] \SubMatrix\{{4-1}{4-7}.[left-xshift=3mm] \end{bNiceArray}.$
\end{document}


As an alternative, you can use the tikz libraries decorations.pathreplacing and calligraphy together with nicematrix to draw the braces. This has the advantage of giving the braces the same thickness regardless of their length, but nicematrix ignores the braces and their labels when creating space for the matrix, so additional space must be placed manually. I used \hspace{7mm} in the code below.

Also (optional), shorten <= does not work with the calligraphic brace, so the endpoints should use yshift to shorten the braces.

\documentclass{article}

\usepackage{nicematrix, tikz}
\usetikzlibrary{decorations.pathreplacing, calligraphy}
\tikzset{mybrace/.style={thick, decorate, decoration={calligraphic brace, amplitude=2pt, raise=2mm}}}

\begin{document}
$R = \hspace{7mm} \begin{bNiceArray}{ccc|cccc}[margin] 1 & & & b_{1, r + 1} & b_{1, r + 2} & \cdots & b_{1n}\\ & \ddots & & \vdots & \vdots & \ddots & \vdots \\ & & 1 & b_{r, r + 1} & b_{r, r + 2} & \cdots & b_{rn} \\ \hline & O & & \Block{1-4}{O} & & & \CodeAfter \tikz{ \draw[mybrace]([yshift=1pt]4-|1)--node[left=2mm]{\scriptstyle r}([yshift=-1pt]1-|1); \draw[mybrace]([yshift=1pt]5-|1)--node[left=2mm]{\scriptstyle m-r}([yshift=-1pt]4-|1); } \end{bNiceArray}.$
\end{document}

• Thanks a ton! It is a perfect replica of the expected output. I guess I have a lot to explore in the nice matrix package. Commented Jun 1, 2023 at 14:56
• Could it be possible to have "same looking" for the braces? Commented Jun 1, 2023 at 14:56
• @JustAnAveragePerson nicematrix is a great package. Commented Jun 1, 2023 at 14:57
• @projetmbc: The only way I can think of is to use the calligraphic brace decoration from the TikZ calligraphy library. Commented Jun 1, 2023 at 15:18
• @projetmbc: I added a solution with calligraphic brace. Commented Jun 2, 2023 at 2:07