2

I'd like to align a list of ratios in a column of a table by the colon. Is this possible using siunitx?

For instance ratios like the following.

1:0.9

1:1.0125

1:0.99

egreg
  • 1,121,712
Darling
  • 3,597

1 Answers1

3

Helpful options are:

  • table-space-text-pre and
  • table-align-text-pre.

You need the set a dummy text with the -space- option, so siunitx can reserve the right space in front of the actual number.

The -align- option accepts true (default) or false and sets the alignment of the text (see example).

We only want 1.0 part so be typeset by siunitx, the 1 from 1: would confuse the parer; we need to hide it in braces: {1:} or {1}:.

As you can see in the last table, we can even use different numbers in front of : (though, as it currently stands, they will not be typeset by siunitx).

Code

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\sisetup{table-format=2.4,table-space-text-pre=1:}
\begin{tabular}{>{{1}:}S}
    0.9    \\
    1.0125 \\
    0.99   \\
    13.0 
\end{tabular}

\hrulefill

\begin{tabular}{>{{1}:}S[table-align-text-pre=false]}
    0.9    \\
    1.0125 \\
    0.99   \\
    13.0 
\end{tabular}

\hrulefill

\begin{tabular}{S}
    {1:}0.9    \\
    {2:}1.0125 \\
    {3:}0.99   \\
    {4:}13.0 
\end{tabular}
\end{document}

Output

enter image description here

Moriambar
  • 11,466
Qrrbrbirlbel
  • 119,821