# Add upper brace on matrix with good alignement on each parameter

From this upper brace, I try to put a brace over the first 9 columns the 9 parameters below. I would like to align them with the 9 first columns of matrix, each one of this parameter aligned with each corresponding columns of matrix:

$\Omega_{b,0} h \Omega_{m,0} n_{s} \Omega_{\text{DE}} w_{0} w_{a} \sigma_{8} \gamma:$

Here what I have done:

% Matrix with brace
\newcommand\overmat[2]{%
\makebox[0pt][l]{$\smash{\color{white}\overbrace{\phantom{% \begin{matrix}#2\end{matrix}}}^{\text{\color{black}#1}}}$}#2}
\newcommand\bovermat[2]{%
\makebox[0pt][l]{$\smash{\overbrace{\phantom{% \begin{matrix}#2\end{matrix}}}^{\text{#1}}}$}#2}

\begin{bmatrix}
\overmat{$\Omega_{b,0} h \Omega_{m,0} n_{s} \Omega_{\text{DE}} w_{0} w_{a} \sigma_{8} \gamma$}{ h^2 & 2&h\Omega_{b,0} &0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 2h\Omega_\text{m,0} & h^2 & 0 & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & 1 & 0 & 0 & 0 & 0&  0 & 0& 0 & 0 & 0 & 0 & 0 & 0 \\
\end{bmatrix}


and the result is:

As you can see, the parameters are not aligned with each of columns, everything is concentrated on the 3 first columns and I don't understand the reason.

How to perform a right alignment and with a brace stretched on all the 9 first columns.

UPDATE 1:

Here is the suggestion of F. Pantigny:

\documentclass{article}
\usepackage{nicematrix}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

$\begin{bNiceArrayRC}{*9C}% [code-after= {\begin{tikzpicture} \draw [decorate,decoration = brace] ([yshift=1.5mm]1-1.north west) to ([yshift=1.5mm]1-8.north east) ; \end{tikzpicture} }] a & b & \Omega_{m,0} & d & e & f & g & h \\[1.5mm] 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 2h\Omega_{m,0} & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ \end{bNiceArrayRC}$

\end{document}


It is almost that I wanted to get. The only point is that I would like to shift "the brace and the parameters" slightly to the top.

Naively, I tried to increase yshift=1.5mmand [1.5mm]to 4mm :

\documentclass{article}
\usepackage{nicematrix}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{xspace}

\begin{document}

$\begin{bNiceArrayRC}{*9C}% [code-after= {\begin{tikzpicture} \draw [decorate,decoration = brace] ([yshift=4mm]1-1.north west) to ([yshift=4mm]1-8.north east) ; \end{tikzpicture} }] a & b & \Omega_{m,0} & d & e & f & g & h \\[4mm] 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 2h\Omega_{m,0} & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ \end{bNiceArrayRC}$

\end{document}


But the result is bad :

Indeed, this is not the brace and parameters which are shifted to the top but this is the content of matrix.

How to shift instead the brace and parameters to the top ?

Regards

• Suppress the option [4mm] of the first \\  and put \rule[-6mm]{0mm}{0mm} (that is a strut) in the first cell. – F. Pantigny Jan 27 at 20:24

## 1 Answer

Maybe a solution with nicematrix which will put a Tikz node behind each cell of the matrix and then let you use the commands of Tikz to draw the brace.

\documentclass{article}
\usepackage{nicematrix}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

$\begin{bNiceArrayRC}{*9C}% [code-after= {\begin{tikzpicture} \draw [decorate,decoration = brace] ([yshift=1.5mm]1-1.north west) to ([yshift=1.5mm]1-8.north east) ; \end{tikzpicture} }] a & b & \Omega_{m,0} & d & e & f & g & h \\[1.5mm] 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 2h\Omega_{m,0} & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ \end{bNiceArrayRC}$

\end{document}


• Thanks, is there a way to put the brace a little more higher over the first row (I mean slightly higher as respect of the left-top corner of matrix) ? – youpilat13 Jan 26 at 17:46
• the solution in tex.stackexchange.com/questions/108009/… can't be applied in my case ? since I want to align each parameter on each column ? – youpilat13 Jan 26 at 17:46
• Yes, \overmat can't be used here because you want the parameters aligned with the colums. I have modified my code to move the brace upwards (1.5 mm, which appears three times in the modified code). – F. Pantigny Jan 26 at 18:12
• unfortunately, at the compilation, I get the following error : ! LaTeX Error: Environment bNiceArrayRC undefined. : what's wrong ? However, I have both nicematrix and tikz installed on my computer. – youpilat13 Jan 26 at 18:38
• I have donwloaded the nicematrix package ( with nicematrix.dtx and nicematrix.ins files) but where to put them ? I am on MacOS 10.13.5 High Sierra. – youpilat13 Jan 26 at 18:57