# How to get the bold math to work with code-for-first-row in NiceMatrix?

I want to get the first row to be bold as follows

The answer in \bfseries for math mode (whole table row in bold) suggests \rowstyle{\boldmath\textbf} for tabular which seems to work well. However, \RowStyle and code-for-first-row from NiceMatrix do not seem to work well with \boldmath\textbf unless these commands are placed before each entry in the table. Also, such solution does not work for \text which we use to place text in math mode. Is it possible to get a neat solution?

\documentclass{article}

\usepackage{nicematrix}

\begin{document}

$$\begin{NiceArray}{l l l}[first-row, code-for-first-row=] \text{\textbf{Item No}} & \boldmath\textbf f(t) & \boldmath\textbf F(s) \\ 1. & \delta(t) & 1 \\ \end{NiceArray}$$

\end{document}

• I'd say \mbox{\boldmath$f(t)$} or \bm{f(t)} with \usepackage{bm}. Sep 3, 2021 at 12:54
• Unrelated, any reason why the majority of your questions have no accepted answer? Sep 3, 2021 at 16:48

In {NiceArray} (and the similar environments such as {pNiceArray}), the tokens corresponding to the key code-for-first-row are inserted after the $ which starts math mode in the cell. But you can exit the math mode with the first symbol $, put whatever instructions you want (such as \bfseries) and start math mode once again with another symbol $. code-for-first-row =$\bfseries\mathversion{bold}$ Despite the appearances, the tokens between the symbols $ will not be in math mode!

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

$\begin{pNiceArray}{ccc}[first-row,code-for-first-row=$\bfseries\mathversion{bold}$] \text{Text} & a+b & c+d \\ 1 & a+b & c+d \\ 2 & a+b & c+d \\ \end{pNiceArray}$

\end{document}


If you want to set code-for-first-row with \NiceMatrixOptions, you should test for math mode in order to have the code valid in all the environments of nicematrix.

\NiceMatrixOptions
{
code-for-first-row =
\ifmmode $\bfseries\mathversion{bold}$
\else \bfseries\mathversion{bold}
\fi
}