I'm using siunitx and trying to get a decimal-aligned
column that contains values with units. The natural thing
seemed to be (working example)
\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{rS}
Zero point energy (\SI{0.18}{\eV})& \SI{0.18}{\eV}\\
Photon energy at \SI{226}{nm} (\SI{5.49}{}) & \SI{5.49}{}\\
Bond dissociation energy (\SI{-1.13}{})& \SI{-1.13}{}\\ \hline
Available for products (\SI{4.54}{\eV}) & \SI{4.54}{\eV}
\end{tabular}
\end{document}
I find several problems:
1) The number with a minus sign in the right column
causes an error:
Package siunitx Warning: Sign but no number for `-' on input line 1.
! Package siunitx Error: Invalid number format `-'.
See the siunitx package documentation for explanation.
Type H <return> for immediate help.
...
l.10 ...issociation energy & \SI{-1.13}{}\\ \hline
The number is printed without the minus sign in the output.
If I change the S column to an l column, that "invalid number format"
problem goes away
and I get nicely formatted values but of course they are not
aligned on decimal points.
Exactly the same entry on the left column has no problem.
If I make the value positive this problem goes away but the
next two remain.
2) The alignment is not correct; the values that have units
are not lined up with the two middle values that don't. I get the same
result if I use the \num{} macro for the two middle values.
3) The eV unit is crammed up against its two numbers with no
intervening space in the S column. In the left column the unit
is spaced correctly following the numerical value.
Am I not using the correct approach to get
decimal-aligned values in a column?
The log file includes
"C:\Program Files\MiKTeX 2.7\tex\latex\siunitx\siunitx.sty"
Package: siunitx 2009/09/21 v1.3a A comprehensive (SI) units package
Thanks,
George.
Everything within an S column is processed through the \num command in
siunitx, so the assumption is that you shouldn't have \SI commands
inside an S column, just the numbers themselves. This is why you get the
error, I think. (The assumption is based on the basic principle of good
table design that units should never go into table cells, but should be
column headings instead.)
In your example, perhaps you can put the units in the row label cell,
and then just put the values in the second S column like this:
\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{lS[tabnumalign=left,tabformat=-2.22]}
Zero point energy (\eV)& 0.18\\
Photon energy at \SI{226}{nm} & 5.49\\
Bond dissociation energy & -1.13\\ \hline
Available for products (\eV) & 4.54
\end{tabular}
\end{document}
Alan
Alan has it spot on. An S column is a column of *numbers* processed by
siunitx ("n" is already taken, so I had to pick something else). While
you can imagine doing something like what you want, it would be a pain
to code and very repetitive to use. If you really need a column of
numbers plus a column of units, then use one S and one s column:
\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{rS[tabformat=-2.2]s}
Zero point energy & 0.18 & \eV \\
Photon energy at \SI{226}{nm} & 5.49 & \\
Bond dissociation energy & -1.13 & \\ \hline
Available for products & 4.54 & \eV
\end{tabular}
\end{document}
Over all, I'd go with Alan's version (noting that the tabformat
statement should read "tabformat=-2.2").
--
Joseph Wright