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
  • I'd say \mbox{\boldmath$f(t)$} or \bm{f(t)} with \usepackage{bm}.
    – egreg
    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

1 Answer 1

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
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.