5

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

2
  • 3
    Unrelated: You can set row 2 to math mode(row{2}={mode=math}). Then you won't need to use $$ in every column.
    – Imran
    Jan 6, 2022 at 21:05
  • @Imran That's a good point. I was not sure if I could use it here, because of the S-column and because of the \lambda in the first cell. But it does indeed work. Jan 7, 2022 at 11:42

1 Answer 1

5

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

1
  • Thank you. I was not sure where the triple escape was needed. But it makes sense that the \SetCell cmd should not be escape but rather the non-numerical input. Jan 7, 2022 at 11:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .