Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
1  
If the first part of the ratio is always 1: then the answer is yes. –  Qrrbrbirlbel Mar 13 '13 at 22:11
    
Yes, that is the case. What setting do I need to look at? –  Darling Mar 13 '13 at 22:16

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.