Tables – Creating a Table with Variable Column Separation to Span Full Width with Tabularray

siunitxtablestabularray

I need to make the following code work so that I can get a table with an automatic calculation of column separation based on the number of columns to make it fit the whole \linewidth.

\documentclass[a4paper]{article}
\usepackage{booktabs,mathtools,siunitx}


\usepackage{tabularray}
\UseTblrLibrary{booktabs,siunitx}
\sisetup{
    table-format = 2.2,
    round-precision = 2,
    round-mode = places,
    round-integer-to-decimal = true
}

\begin{document}
        
    \begin{tblr}{
            colsep = 0 mm,
            colspec = {@{\extracolsep{\fill}} *{2}{>{$\relax}X<{$}} *{4}{S}},
            row{1} = {font=\boldmath\bfseries},
        }
        \toprule
        & \delta [deg] & {{{5}}} & {{{10}}} & {{{15}}} & {{{20}}} \\
        \midrule
        \Gamma = x^2 & \beta [deg] & 1 & 2 & 3 & 4 \\
        \bottomrule
    \end{tblr}

\end{document}

Best Answer

Maybe what you want is a both X and S column? Just write X[si] in tabularray.

PS: tabularray package doesn't support the usage of @{\extracolsep{\fill}}, and normally you don't need it.

\documentclass[a4paper]{article}
\usepackage{booktabs,mathtools,siunitx}

\usepackage{tabularray}
\UseTblrLibrary{booktabs,siunitx}
\sisetup{
    table-format = 2.2,
    round-precision = 2,
    round-mode = places,
    round-integer-to-decimal = true
}

\begin{document}

Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text
      
\begin{center}
\begin{tblr}{
  colspec = {*{2}{>{$\relax}X<{$}}*{4}{X[si]}},
  row{1} = {font=\boldmath\bfseries},
  vlines,
}
  \toprule
                 & \delta [deg] & {{{5}}} & {{{10}}} & {{{15}}} & {{{20}}} \\
  \midrule
    \Gamma = x^2 & \beta [deg]  & 1       & 2        & 3        & 4        \\
  \bottomrule
\end{tblr}
\end{center}

Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text

\end{document}

enter image description here