0

I need to align numbers as 99.88%~9.8% in tables in LaTeX:

\documentclass{article}
\usepackage{siunitx,amsmath,tabularray}
\UseTblrLibrary{booktabs, siunitx}
\begin{document}
\begin{table}
\begin{talltblr}{colspec={X[c] X[c,si={table-format=2.2\%}]}}
1&{{{$11.11\%\sim55.56\%$}}}\\
2&{{{$5.12\%\sim21.2\%$}}}\\
3&{{{$6.78\%\sim2.1\%$}}}\\
\end{talltblr}
\end{table}
\end{document}

The result is:

enter image description here

Is there a way to align them with si={table-format=2.2%\sim2.2%}?

Y. zeng
  • 1,885

1 Answers1

2

Putting them in {{{}}} would disable the effect of the siunitx library, so I don't you want to do that.

I would just put the two sides of \sim in their own columns, and use the @{} operator to put the \sim between the columns. This precludes using X as the colspec, unfortnately, however, as this makes the columns too wide, but it's not clear why you would want that much space for them anyway.

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\begin{document}
\begin{table}
\begin{tblr}{colspec={Q[c] S[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\%\\
\end{tblr}
\end{table}
\end{document}

tblr aligned at \sim

frabjous
  • 41,473
  • Hello. Thanks for your reply. May you teach me how to set \sim symbol's color to {RGB}{245,246,246}? – Y. zeng Jun 25 '22 at 04:47
  • In this particular case you could do @{\textcolor[RGB]{245,246,246}{\ $\sim$\ }}, but that's far too light on a white background and almost unreadable. You've asked a number of questions on this site and not answered any. Time to start trying to answer simple questions like that for yourself. – frabjous Jun 25 '22 at 14:20
  • Okay. I am writing my thesis. I will read several books about latex within two months and then I will answer questions here. I test these codes in https://tex.stackexchange.com/questions/648880/settblrinnertblrcells-bg-cant-change-the-background-color-in-tabularr, but there is an error. I can't adjust the table's color to {RGB}{245,246,246}. – Y. zeng Jun 26 '22 at 00:45
  • You've also been here long enough to know "there is an error" is a useless thing to say. Anyway, discuss that issue is that topic, not here. – frabjous Jun 26 '22 at 12:31
  • Okay. Thanks a lot! – Y. zeng Jun 27 '22 at 00:13