1

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}
1

2 Answers 2

2

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

10
  • How to center the cells of the first row starting from the third column? Also, is there an automatic way to write [deg] in text mode so that only the math expressions are written in math mode?
    – Diaa
    Sep 9, 2021 at 9:08
  • 1
    with use of X[c,si]
    – Zarko
    Sep 9, 2021 at 9:12
  • @Zarko How can I make the left separation of the first column equal to the right separation of the last column equal to zero?
    – Diaa
    Sep 9, 2021 at 9:21
  • Add @{} to the beginning and the end of colspec.
    – L.J.R.
    Sep 9, 2021 at 9:34
  • @Diaa, adding @{} as mentioned in comment of L.J.R. But in this case content of the left cell will touch to the left table border. This problem you can eliminate b< omitting vertical lines or reduce by use defining first column as >{$\relax}X[c]<{$}.
    – Zarko
    Sep 9, 2021 at 9:41
1

enter image description here

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


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

\begin{document}
        
    \begin{tabular}{@{\extracolsep{\fill}} *{2}{>{$\relax}c<{$}} *{4}{S}}
        \toprule
        & \delta [deg] & {{{5}}} & {{{10}}} & {{{15}}} & {{{20}}} \\
        \midrule
        \Gamma = x^2 & \beta [deg] & 1 & 2 & 3 & 4 \\
        \bottomrule
    \end{tabular}

\end{document}
1
  • ...can you explain how this answers the question?
    – Werner
    Sep 8, 2021 at 23:48

You must log in to answer this question.

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