0

I set tables' background to {RGB}{245,246,246} in tabularray package, but the content from @{} in the table below didn't change to that colour, so it is still the original white. So is there a way to make that color change with tabularray package?

\documentclass{article}
\usepackage{tabularray,xcolor}
\UseTblrLibrary{siunitx}
\definecolor{tablebackground}{RGB}{245,246,246}
\SetTblrInner[talltblr]{cells={bg=tablebackground}}
\begin{document}
\begin{table}
\begin{talltblr}{colspec={X[c] X[c,si={table-format=2.2\%}]@{\ $\sim$\ }S[table-format=2.2\%] }}
1&11.11\% &55.56\%\\
2&5.12\% &21.2\%\\
3&6.78\% &2.1\%\\
4&75.5\%&\\
\end{talltblr}
\end{table}
\end{document}

enter image description here

L.J.R.
  • 10,932
Y. zeng
  • 1,885

2 Answers2

1

The setting cells={bg=tablebackground} only set background colors for all cells. But column specifier @ will put its content \ $\sim$\ in the border. You may try to write

@{\colorbox{tablebackground}{\ $\sim$\ }}

but it won't work since the background color desen't fill the whole height. And it will cause an error which is an expansion bug of tabularray.

Therefore you may try to \llap and \clap the border text to zero width:

\documentclass{article}
\usepackage{tabularray,xcolor}
\UseTblrLibrary{siunitx}
\definecolor{tablebackground}{RGB}{245,246,246}
\SetTblrInner[talltblr]{cells={bg=tablebackground}}
\begin{document}
\begin{table}[!htp]
\begin{talltblr}{
  X[c] X[c,si={table-format=2.2\%}] @{\llap{$\sim$\ }} S[table-format=2.2\%]
}
  1 & 11.11\% &  55.56\% \\
  2 &  5.12\% &  21.2 \% \\
  3 &  6.78\% &   2.1 \% \\
  4 & 75.5 \% &          \\
\end{talltblr}
\end{table}
\begin{table}[!htp]
\begin{talltblr}{
  X[c] S[table-format=2.2\%] !{\clap{$\sim$}} S[table-format=2.2\%]
}
  1 & 11.11\% &  55.56\% \\
  2 &  5.12\% &  21.2 \% \\
  3 &  6.78\% &   2.1 \% \\
  4 & 75.5 \% &          \\
\end{talltblr}
\end{table}
\end{document}

enter image description here

L.J.R.
  • 10,932
  • Hello, if change \begin{talltblr}{ X[c] X[c,si={table-format=2.2\%}] @{\llap{\ $\sim$\ }} S[table-format=2.2\%] } to \begin{talltblr}{ X[c] S[table-format=2.2\%] @{\llap{\ $\sim$\ }} S[table-format=2.2\%] }. It is weird. Is there another way to change backgroud color of @{}? – Y. zeng Jun 26 '22 at 02:59
  • @Y.zeng See my updated answer. – L.J.R. Jun 26 '22 at 06:51
  • Hello. What's the function of \clap in !{\clap{$\sim$}} and why did you add a ! here? – Y. zeng Jun 26 '22 at 07:12
  • @Y.zeng \llap, \clap and \rlap are three overlap boxes, see https://tex.stackexchange.com/questions/83930 . – L.J.R. Jun 26 '22 at 07:57
  • @Y.zeng For the difference between @ and ! specifiers in tables, see https://www.learnlatex.org/en/lesson-08 – L.J.R. Jun 26 '22 at 07:59
  • Thanks a lot. I will check that. – Y. zeng Jun 26 '22 at 10:27
0

A way to solve this problem is using vline{} = {}{text=$\sim$}:

\documentclass{article}
\usepackage{tabularray,xcolor}
\UseTblrLibrary{siunitx}
\definecolor{tablebackground}{RGB}{245,246,246}
\SetTblrInner[talltblr]{cells={bg=tablebackground}}
\begin{document}
\begin{table}
\begin{talltblr}{colspec={X[c,1.5] X[r,si={table-format=2.2\%},0.2] X[l,si={table-format=2.2\%},0.2]},vline{3} = {1-4}{text=\clap{$\sim$}}}
1&11.11\% &55.56\%\\
2&5.12\% &21.2\%\\
3&6.78\% &2.1\%\\
4&75.5\%&\\
\end{talltblr}
\end{table}
\end{document}

But I don't know how to adjust table width to \textwidth and why @{} color is not the same as the table's. enter image description here

Y. zeng
  • 1,885