Siunitx – Resolving SetCell from Tabularray S Column Issue

siunitxtabularray

I'd like to get the \SetCell command from tabularray to work in my tabular. I prefer to write my tabulars with tabularray as it can usually save you time and can make configuration easier, but the \SetCell does not seem to work as intended.

The normal tabular seems to work. I have also tried with non-escaping the \SetCell but I only seem to get errors that way. Right now it looks as though the \SetCell is not doing anything.

MWE:

\documentclass{scrartcl}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{tabularray}
\UseTblrLibrary{booktabs,siunitx}

\begin{document}
    \begin{tblr}{
        % hlines, vlines,
        colspec={Q[si={table-format=3.1},c]*{4}{Q[si={table-format=2.1},c]}},
        }
        \toprule
            & {{{\SetCell[c=2]{c} Technetium}}} & &  {{{\SetCell[c=2]{c} Molybdän}}} & \\ \cmidrule[lr]{2-3} \cmidrule[lr]{4-5}
            {{{$\lambda$\,/\,\unit{\nm}}}} & {{{$\phi_1$}}} & {{{$\phi_2$}}} & {{{$\phi_1$}}} & {{{$\phi_2$}}} \\
        \midrule
            663,0 & 12,1 & 14,4 & 13,1 & 16,9 \\
            670,0 & 10,9 & 12,9 & 11,8 & 15,7 \\
            678,0 & 9,1 & 11,4 & 10,3 & 14,6 \\
            684,0 & 8,2 & 10,2 & 9,5 & 13,5 \\
        \bottomrule
    \end{tblr}
    \sisetup{table-format=2.1}
        \begin{tabular}{S[table-format=3.1]*{4}{S}}
            \toprule
                & \multicolumn{2}{c}{Technetium} & \multicolumn{2}{c}{Molybdän} \\ \cmidrule(lr){2-3} \cmidrule(lr){4-5}
                {$\lambda \mathbin{/} \unit{\nano\meter}$} & {$\phi_1$} & {$\phi_2$} & {$\phi_1$} & {$\phi_2$} \\
            \midrule
                663.0 & 12.1 & 14.4 & 13.1 & 16.9 \\
                670.0 & 10.9 & 12.9 & 11.8 & 15.7 \\
                678.0 & 9.1 & 11.4 & 10.3 & 14.6 \\
                684.0 & 8.2 & 10.2 & 9.5 & 13.5 \\
            \bottomrule
         \end{tabular}
\end{document}

Beispiel

Best Answer

You have to place the \SetCell[c=2]{c} in front of the triple curly braces. tabularray also supports the column type S, so you can simplify your colspec definition.

\documentclass{scrartcl}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{tabularray}
\UseTblrLibrary{booktabs,siunitx}

\begin{document}
    tabularray\\
    \begin{tblr}{
            % hlines, vlines,
            colspec={S[table-format=3.1]*{4}{S[table-format=2.1]}},
        }
        \toprule
        & \SetCell[c=2]{c}{{{Technetium}}} & & \SetCell[c=2]{c} {{{Molybdän}}} & \\
        \cmidrule[lr]{2-3} \cmidrule[lr]{4-5}
        {{{$\lambda$\,/\,\unit{\nm}}}} & {{{$\phi_1$}}} & {{{$\phi_2$}}} & {{{$\phi_1$}}} & {{{$\phi_2$}}} \\
        \midrule
        663,0 & 12,1 & 14,4 & 13,1 & 16,9 \\
        670,0 & 10,9 & 12,9 & 11,8 & 15,7 \\
        678,0 & 9,1 & 11,4 & 10,3 & 14,6 \\
        684,0 & 8,2 & 10,2 & 9,5 & 13,5 \\
        \bottomrule
    \end{tblr}
    \vspace{1cm}
    
    \sisetup{table-format=2.1}
    tabular\\
    \begin{tabular}{S[table-format=3.1]*{4}{S}}
        \toprule
        & \multicolumn{2}{c}{Technetium} & \multicolumn{2}{c}{Molybdän} \\ \cmidrule(lr){2-3} \cmidrule(lr){4-5}
        {$\lambda \mathbin{/} \unit{\nano\meter}$} & {$\phi_1$} & {$\phi_2$} & {$\phi_1$} & {$\phi_2$} \\
        \midrule
        663.0 & 12.1 & 14.4 & 13.1 & 16.9 \\
        670.0 & 10.9 & 12.9 & 11.8 & 15.7 \\
        678.0 & 9.1 & 11.4 & 10.3 & 14.6 \\
        684.0 & 8.2 & 10.2 & 9.5 & 13.5 \\
        \bottomrule
    \end{tabular}
\end{document}

tabular output