5

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

enter image description here

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{equation} \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{equation}

\end{document}

2 Answers2

5

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}

Output of the above code

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
  }
F. Pantigny
  • 40,250
0

In recent versions of nicematrix (≥ 6.3 of 2021-10-18), you can use the commande \RowStyle and its key bold.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\NiceMatrixOptions{code-for-first-row= \RowStyle[bold]{}}

$\begin{pNiceArray}{ccc}[first-row] \text{Text} & a+b & c+d \ 1 & a+b & c+d \ 2 & a+b & c+d \ \end{pNiceArray}$

\end{document}

As usual with nicematrix, you need several compilations.

Output of the above code

F. Pantigny
  • 40,250
  • I would have made an edit to the existing answer. – egreg Jul 06 '22 at 17:48
  • Is it possible to have something like "code for each cell", not only first one? I could have defined a new column type, but for NiceMatrix amount of of columns is arbitrary and changes by adding\removing &. – antshar Jul 09 '22 at 07:22
  • @antshar: With the latest version of nicematrix (v 6.11 of 2022-07-16), there is a key matrix/columns-type available in \NiceMatrixOptions to fix the default column type used by {pNiceMatrix}, {bNiceMatrix}, etc. – F. Pantigny Jul 18 '22 at 15:15
  • @F.Pantigny thanks! – antshar Jul 18 '22 at 17:29