16

I am trying to make a table with four columns: three of the columns are to be center aligned, and one is to be aligned by decimal places ( using S[table-format=3.2]). Here is my code:

\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{c c S[table-format=3.2] c}
\toprule
\multicolumn{4}{c}{SI Prefixes} \\
%\hline \hline
\midrule \midrule
Prefix & Symbol & Multiplication Factor & $\ldots$ in Scientific Notation \\
\midrule
giga & G & 1000000000 & $10^9$ \\
mega & M & 1000000 & $10^6$ \\ 
kilo & k & 1000 & $10^3$ \\
deca & D & 10 & $10^1$ \\
\rowcolor{gray!20} - & - & 1 & $10^0$ \\
deci & d & 0.1 & $10^{-1}$ \\
centi & c & 0.01 & $10^{-2}$ \\
milli & m & 0.001 & $10^{-3}$ \\
micro & $\mu$ & 0.000001 & $10^{-6}$ \\
nano & n & 0.000000001 & $10^{-9}$ \\
\bottomrule
\end{tabular}

\end{document}

However, here is my result:

enter image description here

The columns are overlapping, and I cannot figure out how to fix it. I can't think of a way to set the width of the third column, as that would fix the issue, but to my understanding, you can only fix the width by doing something like p{5cm}; the S type will not allow that.

akenny430
  • 1,389
  • 4
    you need {...} around the heading so it isn't parsed as a number but main issue is you have specified a format of 3.2 so 2 decimal places but your numbers are 0.000000001 which have rather more than 2 digits after the point. Use a format that matches your data – David Carlisle Jan 04 '19 at 15:59
  • How would I format it then? Sorry, I've never used siunitx before. The max amount of digits is 9, so would I put 3.9? – akenny430 Jan 04 '19 at 16:03
  • 1
    It just hit me, the number left of . is the number of digits left of the decimal and same with the right. So I should put 10.9. – akenny430 Jan 04 '19 at 16:07
  • 3
    Slightly off-topic: The shortened form of \deca (\deka works too...) is da, not D. – Mico Jan 04 '19 at 16:15
  • Good point... I was not aware of this – akenny430 Jan 04 '19 at 16:41
  • 1
    Two years late and slightly off-topic but I think you might want to include hecto- (h) 100 – Henk Metselaar Jan 16 '21 at 03:53
  • 2
    Still later: I think, in the line concerning the "micro" Prefix: the \mu should be printed in upright font, I guess? At least, it looks strange to see an italic \mu while the rest of the prefix symbols are upright. – Jan May 12 '21 at 07:30
  • Just curious: Would it be possible, to prepare the table contents by using siunitx capabilities, to use the same input in the second til fourth column, while siunitx prints either the symbol, the number or the scientic repesentation of the number. So first line would read in the input as Giga & \giga & \giga & \giga \\? – Jan May 12 '21 at 07:35

1 Answers1

18

Update, March 2022: I wrote the answer shown below in early 2019, when version 2.xx of the siunitx package still roamed the earth. If you wish to compile the answer code under version 3.xx of the siunitx package, I suggest you load the siunitx package with the option v2=, i.e., as \usepackage{siunitx}[=v2]. Please see How to convert the macro \si in the new version 3 of siunitx for additional details.


As David Carlisle has already pointed out in a comment, you must (a) change S[table-format=3.2] to S[table-format=10.9] and (b) encase the string Multiplication Factor in curly braces, to keep it from being interpreted by siunitx.

In addition, you may want to (c) write \si{\micro} instead of $\mu$ in the second column. The text-mu and math-mu glyphs look quite different in most fonts. Finally, since you're using the siunitx package, why not (d) use the S column type for the final column as well and input e9 thru e-9 instead of the more cumbersome $10^9$ thru $10^{-9}$?

A separate observation: the standard short form of deca (or deka) is da, not D. For sure, both \si{\deca} and \si{\deka} produce da.

enter image description here

\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\begin{document}
\noindent
\begin{tabular}{l c S[table-format=10.9] S[retain-zero-exponent=true]}
\toprule
\multicolumn{4}{c}{SI Prefixes} \\
\addlinespace %\midrule
Prefix & Symbol & {Multiplication Factor} & {\dots\ in Scientific Notation} \\
\midrule
giga  & \si{\giga} & 1000000000 & e9 \\
mega  & \si{\mega} & 1000000    & e6 \\ 
kilo  & \si{\kilo} & 1000       & e3 \\
deca  & \si{\deca} & 10         & e1 \\ % "\deka" works too
\rowcolor{gray!20}  -- & -- & 1 & e0 \\
deci  & \si{\deci} & 0.1        & e-1 \\
centi & \si{\centi}& 0.01       & e-2 \\
milli & \si{\milli}& 0.001      & e-3 \\
micro & \si{\micro}& 0.000001   & e-6 \\
nano  & \si{\nano} & 0.000000001& e-9 \\
\bottomrule
\end{tabular}
\end{document}
Mico
  • 506,678
  • 1
    This code does not seem to work any longer on TeXLive 21. It produces the error Package siunitx Error: Found prefix part with no unit.. – TeX Apprentice Mar 04 '22 at 02:23
  • @TeXApprentice - Thanks for bringing this issue to my attention. Please see the update I posted at the start of the answer. – Mico Mar 04 '22 at 02:38