7

I want to present my results in a table and let siunitx format the data automatically. Generally, I would use something like

\num[
    scientific-notation = true,
    round-mode = figures,
    round-precision = 1
]{0.400911111}

and, if needed, I could always change the precision or whatever. In a table with a bunch of data, this would result in some hundreds of lines of code and wouldn't be readable anymore. That's why I'm now using siunitx's S column row with these exact settings.

This also works great, but unfortunately, it limits me because now, I can't change the precision for one number so easily.

In the table of the MWE, for example, I need to display to display the concentration of the second value with a decimal place. The third value even needs two. The rest of the table shouldn't have any decimal place.

In the MWE you see my approach too, which does work, but looks awful. How is dis done right or, at least, how could I align those two cells like all the other ones (integers underneath each other)?

table-format does not seem to bring a solution to this issue.

MWE

\documentclass{article}

\usepackage[table]{xcolor}
\usepackage{tabu}
\usepackage{siunitx}

\begin{document}

\begin{table}[htb!]
    \caption{Foo bar}
    \label{tab:foo-bar}

    \centering
    \taburowcolors[1] {white .. gray!10}
    \begin{tabu}[t]{|
        S[
            scientific-notation = true,
            round-mode = figures,
            round-precision = 1
        ]
        S[
            scientific-notation = true,
            round-mode = figures,
            round-precision = 1
        ]
        S[
            scientific-notation = true,
            round-mode = figures,
            round-precision = 1
        ]
        S[
            scientific-notation = true,
            round-mode = figures,
            round-precision = 1
        ]
    |}
        \hline
        {$c$ [\si{mol\per\liter}]}
            & {$\Delta c$ [\si{\percent}]}
            & {$\ln c$ [\si{\ln(mol\per\liter)}]}
            & {$\Delta\ln c$ [\si{\ln(mol\per\liter)}]}\\
        \hline
        0.03
            & 2.0000
            & -3.5066
            & 0.0408\\
        0.02
            & 4.0800
            & -3.9120
            & 0.0602\\
        {\num[
            scientific-notation = true,
            round-mode = figures,
            round-precision = 2
        ]{0.015}}
            & 6.0244
            & -4.1997
            & 0.0811\\
        {\num[
            scientific-notation = true,
            round-mode = figures,
            round-precision = 3
        ]{0.0125}}
            & 8.1078
            & -4.3820
            & 0.1047\\
        0.01
            & 10.4689
            & -4.6052
            & 0.1277\\
        \hline
    \end{tabu}
\end{table}

\end{document}
9

You can use \sisetup{round-precision=...} before and after the number to change the value temporarily:

\documentclass{article}

\usepackage[table]{xcolor}
\usepackage{tabu}
\usepackage{siunitx}

\begin{document}

\begin{table}[htb!]
    \caption{Foo bar}
    \label{tab:foo-bar}

    \centering
    \taburowcolors[1] {white .. gray!10}
    \begin{tabu}[t]{|
        S[
            scientific-notation = true,
            round-mode = figures,
            round-precision = 1,
            table-format=1.2e-1
        ]
        S[
            scientific-notation = true,
            round-mode = figures,
            round-precision = 1
        ]
        S[
            scientific-notation = true,
            round-mode = figures,
            round-precision = 1
        ]
        S[
            scientific-notation = true,
            round-mode = figures,
            round-precision = 1
        ]
    |}
        \hline
        {$c$ [\si{mol\per\liter}]}
            & {$\Delta c$ [\si{\percent}]}
            & {$\ln c$ [\si{\ln(mol\per\liter)}]}
            & {$\Delta\ln c$ [\si{\ln(mol\per\liter)}]}\\
        \hline
        0.03
            & 2.0000
            & -3.5066
            & 0.0408\\
        0.02
            & 4.0800
            & -3.9120
            & 0.0602\\
        \sisetup{round-precision=2}0.015\sisetup{round-precision=1}
            & 6.0244
            & -4.1997
            & 0.0811\\
        \sisetup{round-precision=3}0.0125\sisetup{round-precision=1}
            & 8.1078
            & -4.3820
            & 0.1047\\
        0.01
            & 10.4689
            & -4.6052
            & 0.1277\\
        \hline
    \end{tabu}
\end{table}

\end{document}

enter image description here

| improve this answer | |
  • Well, that was quite an easy method. I thought that way too complicated. Thanks a lot! – Sam May 15 '18 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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