2

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:

result

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 :

bad shifting

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

2 Answers2

3

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}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

$\begin{bNiceArray}{*{9}{c}}[first-row] 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 \ \CodeAfter \tikz \draw [decorate,decoration = brace] ([yshift=1.5mm]1-1.north west) to
([yshift=1.5mm]1-8.north east) ; \end{bNiceArray}$

\end{document}

enter image description here

F. Pantigny
  • 40,250
  • 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) ? –  Jan 26 '19 at 17:46
  • the solution in https://tex.stackexchange.com/questions/108009/add-overbrace-to-describe-a-column-of-matrix can't be applied in my case ? since I want to align each parameter on each column ? –  Jan 26 '19 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 '19 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. –  Jan 26 '19 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. –  Jan 26 '19 at 18:57
0

The version 6.4 of nicematrix (2021/11/23) provides new commands \OverBrace and \UnderBrace available in the \CodeAfter to address that kind of situation. The braces are braces of standard LaTeX (that is to say constructed with the current mathematical font) and not braces of Tikz.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

$\begin{bNiceArray}{*{9}{c}}[first-row,margin] 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 \ \CodeAfter \OverBrace{1-1}{1-8}{}[shorten,yshift=2pt] \end{bNiceArray}$

\end{document}

As usual with nicematrix, you need several compilations.

Output of the above code

F. Pantigny
  • 40,250