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 have a table with values exported from a statistics software, where the values are formatted like this (see example below):

Some (very small ones) are in scientific notation, some are in "normal" decimal notation.

\begin{tabular}{r}
3,158722 \\
-0,00061 \\
6,28E-05 \\
0,000303 \\
1,67E-04 \\
0,000175 \\
-0,00017 \\
0,000025 \\
-0,00012 \\
-7,7E-05 \\
-0,00042 \\
-0,0005 \\
0,128871 \\
-0,00689 \\
0,004255 \\
-0,00245 \\
0,010475 \\
0,007083 \\
0,000852 \\
0,004583 \\
-0,00042 \\
0,002032 \\
-0,00111 \\
0,000556 \\
12,53887 \\
0,0024 \\
-0,00387 \\
0,002836 \\
-0,00052 \\
-0,00022 \\
5,41E-05 \\
-0,00063 \\
3,17E-04 \\
0,000187 \\
-0,08153 \\
-0,07881 \\
0,316826 \\
0,001066 \\
0,009783 \\
-0,02701 \\
0,006054 \\
0,004167 \\
\end{tabular}%
  • How can I define a number formatting that makes sense?
  • Is it possible with siunitxto combine decimal and scientific notation in one column?
    If yes, how can I define when the scientific notation is used and when not?
share|improve this question
    
Do you have the input in the form you list above (i.e. with the difference between scientific and 'plain' numbers built-in)? –  Joseph Wright Jul 4 '11 at 12:02
    
I'm not sure if I understand your question. The output in the example is exactly as I get it from the statistics software - partly "plain" and partly scientific notation. It seems that the number of characters per line is limited, so the applications chooses the "best" way to display the number. However, thanks to your question, I've just found (I forgot) that I could influence that format and make it consistens (purely decimal or scientific), if it would make things easier for siunitx. –  Martin Jul 4 '11 at 12:12

1 Answer 1

up vote 2 down vote accepted

While siunitx is good at aligning a series of numbers in a similar format, it is less good for this type of mixed input. My initial thought would be

\documentclass{article}
\usepackage{siunitx}

    \begin{document}
    \begin{tabular}{S[table-format = -1.6e1, table-align-exponent = false]}
    3,158722 \\
    -0,00061 \\
    6,28E-05 \\
    0,000303 \\
    1,67E-04 \\
    0,000175 \\
    -0,00017 \\
    0,000025 \\
    -0,00012 \\
    -7,7E-05 \\
    -0,00042 \\
    -0,0005 \\
    0,128871 \\
    -0,00689 \\
    0,004255 \\
    -0,00245 \\
    0,010475 \\
    0,007083 \\
    0,000852 \\
    0,004583 \\
    -0,00042 \\
    0,002032 \\
    -0,00111 \\
    0,000556 \\
    12,53887 \\
    0,0024 \\
    -0,00387 \\
    0,002836 \\
    -0,00052 \\
    -0,00022 \\
    5,41E-05 \\
    -0,00063 \\
    3,17E-04 \\
    0,000187 \\
    -0,08153 \\
    -0,07881 \\
    0,316826 \\
    0,001066 \\
    0,009783 \\
    -0,02701 \\
    0,006054 \\
    0,004167 \\
    \end{tabular}
    \end{document}

but this will have too much space on the right margin. Perhaps a new option is needed in siunitx to handle this case.

One alternative approach is to use a strategy similar to the dcolumn package, making both , and E active in math mode:

\documentclass{article}
\usepackage{array}
\newbox\tabboxa
\newbox\tabboxb
\newcommand*\tabalignstart{%
  \setbox\tabboxa=\hbox{$-1$}%
    \setbox\tabboxa=\hbox to \wd\tabboxa
      \bgroup
        $
        \lccode`\~=`\,\relax
        \mathcode`\,="8000%
        \lowercase{\def~}%
          {%
              $%
            \egroup
            \setbox\tabboxb=\hbox
              \bgroup
                $
                \lccode`\~=`\E\relax
                \mathcode`\E="8000%
                \lowercase{\def~}####1####2####3%
                  {\times 10^{####1####3}}%
                  .
          }%
        \hfill
}
\newcommand*\tabalignstop{%
    $
    \hfil
  \egroup
  \box\tabboxa
  \box\tabboxb
}

    \begin{document}
    \begin{tabular}{>{\tabalignstart}l<{\tabalignstop}}
    3,158722 \\
    -0,00061 \\
    6,28E-05 \\
    0,000303 \\
    1,67E-04 \\
    0,000175 \\
    -0,00017 \\
    0,000025 \\
    -0,00012 \\
    -7,7E-05 \\
    -0,00042 \\
    -0,0005 \\
    0,128871 \\
    -0,00689 \\
    0,004255 \\
    -0,00245 \\
    0,010475 \\
    0,007083 \\
    0,000852 \\
    0,004583 \\
    -0,00042 \\
    0,002032 \\
    -0,00111 \\
    0,000556 \\
    12,53887 \\
    0,0024 \\
    -0,00387 \\
    0,002836 \\
    -0,00052 \\
    -0,00022 \\
    5,41E-05 \\
    -0,00063 \\
    3,17E-04 \\
    0,000187 \\
    -0,08153 \\
    -0,07881 \\
    0,316826 \\
    0,001066 \\
    0,009783 \\
    -0,02701 \\
    0,006054 \\
    0,004167 \\
    \end{tabular}
    \end{document}

Of course, the problem then is that there are no digit separators.

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.