6

My apologies first as it may be that if i spent a sufficient amount of time playing and reading the siunitx manual, that I might be able to figure this out. About an hour has failed to yield the answer though.

I have a tabular environment and an S column. I wish for all the numbers in this column to be surrounded by () and written in italics (though the () themselves would not be in italics). I'd like this to happen while the alignment features of siunitx are still in operation.

I have tried the bracket-numbers=true option in combination with defining [...,open-bracket=(, close-bracket=),...] in this siunitx package options. Even for stand alone numbers \num[bracket-numbers=true]{12345} this does not appear to provide parenthesis.

Also for the italics part, I can put my number in \textit{1.2345} in the column, and this will work, but to my mind lacks elegance, e.g. it does not keep the specified alignment, just treats it as text.

Does any one have a solution. Many thanks

2 Answers 2

4

Second approach

This approach avoids abusing the nature of digits!

\documentclass{article}
\usepackage{siunitx}
\DeclareRobustCommand\tnote[1]{\textsuperscript{\emph{#1}}}
\begin{document}
\begin{tabular}{
  S[math-rm=\mathit]
  S[math-rm=\mathit,table-format=1.3,table-align-text-post = false,
    input-open-uncertainty=,input-close-uncertainty=]
  }
1&(1.23)\tnote{a}\\
2&(2.012)\tnote{b}
\end{tabular}
\end{document}

First approach

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{
  S[math-rm=\mathit]
  S[math-rm=\mathit,table-format=2.3,input-symbols=()]
  }
1&(1.23)\\
2&(2.012)
\end{tabular}
\end{document}

which is a slight refinement of egreg's solution. I can't at the moment thing of a way to auto-include the parentheses.

(The bracket-numbers option is about cases where the output may be ambiguous, and therefore brackets are used to keep it mathematically correct.)

7
  • I'm liking this, it has generated a rather strange artifact though: by adding spaces in between groups of three digits.. (3.8415) seems to become (3.841 5). In the case of a 3 digit decimal e.g. (3.898), it also does this: (3.898 ). The table-format=1.4. I have another problem connected with addin a \tnote{a} onto numbers (given that they are not all of the same length). Do you have an idea how to work this?
    – aghsmith
    Commented May 31, 2011 at 17:00
  • 1
    @user1269: The best I can suggest with digit separation is to turn it off: group-digits = false. On the alignment of material after the cell contents, look at the table-align-text-post option (again, you seem to want this set false). I should add that of course this is all something of an abuse of the system!
    – Joseph Wright
    Commented May 31, 2011 at 17:06
  • :P Abuse feels good. Seems to do just what I wanted. Thanks Joseph. I have a few remarks though. I will put them in comments in a few moments.
    – aghsmith
    Commented May 31, 2011 at 17:31
  • 1. Perhaps the space that appears before the ) with just 3 digits (1.234 ), when grouping is turned on is a bug? 2. Why does digit grouping only apply when I use the parenthesis (though I was able to turn it off via your method)? 3. Another possible bug: if I use the parenthesis and have table-align-text-post=true with \tnote{a} then the "a" appears inside the text... i.e. where is would have been if there were no parenthesis and if grouping was turned off (whether it is or isn't turned off). This is despite having the the table-space-text-pre={(} and post parameters set.
    – aghsmith
    Commented May 31, 2011 at 17:33
  • @user1269: Please see my updated approach to the entire problem. On the question of spacing, when you set anything as an input-symbol it is treated as a digit for spacing purposes. Thus in my first approach (1.234) 'appears' to have four digits after the decimal.
    – Joseph Wright
    Commented May 31, 2011 at 17:47
3

Try this:

\begin{tabular}{S[math-rm=\mathit]
  >{{(}}S[math-rm=\mathit,
          table-format=1.3]<{{)}}}
1&1.232\\
2&2.012
\end{tabular}
1
  • The italic problem is solved, I actually tried some variation of \mathit but didn't have it quite right. I'm not quite happy with the parenthesis aspect of it. Some of my numbers don't have the same number of decimal places and the method here will put the () on the outside of the column leaving a gap. e.g. (1.23 ). Thanks for this though
    – aghsmith
    Commented May 31, 2011 at 15:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .