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}

L.J.R.
  • 10,932
Diaa
  • 9,599

2 Answers2

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

L.J.R.
  • 10,932
  • 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 09 '21 at 09:08
  • 1
    with use of X[c,si] – Zarko Sep 09 '21 at 09: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 09 '21 at 09:21
  • Add @{} to the beginning and the end of colspec. – L.J.R. Sep 09 '21 at 09: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 09 '21 at 09:41
  • colspec = { @{} *{2}{>{$\relax}X[l, 0.7]<{$}} *{4}{X[1.1, c, si]} @{} } gets this https://i.ibb.co/sChzs4p/image.png – Diaa Sep 09 '21 at 09:42
  • @L.J.R. Is my last comment an issue to be resolved later? – Diaa Sep 09 '21 at 20:18
  • What is the problem there? – L.J.R. Sep 09 '21 at 21:31
  • colspec = { @{} *{2}{>{$\relax}X[l, 0.7]<{$}} *{4}{X[1.1, c, si]} @{} } should remove the right space between the last column and the rightmost margin, which is not what I got as shown here https://i.ibb.co/sChzs4p/image.png – Diaa Sep 10 '21 at 11:57
  • No, because you are centering the cells. You may use right alignment for the last column instead. – L.J.R. Sep 10 '21 at 12:38
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}{&gt;{$\relax}c&lt;{$}} *{4}{S}}
    \toprule
    &amp; \delta [deg] &amp; {{{5}}} &amp; {{{10}}} &amp; {{{15}}} &amp; {{{20}}} \\
    \midrule
    \Gamma = x^2 &amp; \beta [deg] &amp; 1 &amp; 2 &amp; 3 &amp; 4 \\
    \bottomrule
\end{tabular}

\end{document}

js bibra
  • 21,280