Automatically format results in siunitx table (S column)

Sam 05/15/2018. 1 answers, 97 views
siunitx

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}

1 Answers


samcarter 05/15/2018.

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


HighResolutionMusic.com - Download Hi-Res Songs

1 Martin Garrix

Yottabyte flac

Martin Garrix. 2018. Writer: Martin Garrix.
2 Alan Walker

Diamond Heart flac

Alan Walker. 2018. Writer: Alan Walker;Sophia Somajo;Mood Melodies;James Njie;Thomas Troelsen;Kristoffer Haugan;Edvard Normann;Anders Froen;Gunnar Greve;Yann Bargain;Victor Verpillat;Fredrik Borch Olsen.
3 Sia

I'm Still Here flac

Sia. 2018. Writer: Sia.
4 Blinders

Breach (Walk Alone) flac

Blinders. 2018. Writer: Dewain Whitmore;Ilsey Juber;Blinders;Martin Garrix.
5 Dyro

Latency flac

Dyro. 2018. Writer: Martin Garrix;Dyro.
6 Cardi B

Taki Taki flac

Cardi B. 2018. Writer: Bava;Juan Vasquez;Vicente Saavedra;Jordan Thorpe;DJ Snake;Ozuna;Cardi B;Selena Gomez.
7 Bradley Cooper

Shallow flac

Bradley Cooper. 2018. Writer: Andrew Wyatt;Anthony Rossomando;Mark Ronson;Lady Gaga.
8 Halsey

Without Me flac

Halsey. 2018. Writer: Halsey;Delacey;Louis Bell;Amy Allen;Justin Timberlake;Timbaland;Scott Storch.
9 Lady Gaga

I'll Never Love Again flac

Lady Gaga. 2018. Writer: Benjamin Rice;Lady Gaga.
10 Kelsea Ballerini

This Feeling flac

Kelsea Ballerini. 2018. Writer: Andrew Taggart;Alex Pall;Emily Warren.
11 Mako

Rise flac

Mako. 2018. Writer: Riot Music Team;Mako;Justin Tranter.
12 Dewain Whitmore

Burn Out flac

Dewain Whitmore. 2018. Writer: Dewain Whitmore;Ilsey Juber;Emilio Behr;Martijn Garritsen.
13 Bradley Cooper

Always Remember Us This Way flac

Bradley Cooper. 2018. Writer: Lady Gaga;Dave Cobb.
14 Little Mix

Woman Like Me flac

Little Mix. 2018. Writer: Nicki Minaj;Steve Mac;Ed Sheeran;Jess Glynne.
15 Charli XCX

1999 flac

Charli XCX. 2018. Writer: Charli XCX;Troye Sivan;Leland;Oscar Holter;Noonie Bao.
16 Rita Ora

Let You Love Me flac

Rita Ora. 2018. Writer: Rita Ora.
17 Diplo

Electricity flac

Diplo. 2018. Writer: Diplo;Mark Ronson;Picard Brothers;Wynter Gordon;Romy Madley Croft;Florence Welch.
18 Jonas Blue

Polaroid flac

Jonas Blue. 2018. Writer: Jonas Blue;Liam Payne;Lennon Stella.
19 Lady Gaga

Look What I Found flac

Lady Gaga. 2018. Writer: DJ White Shadow;Nick Monson;Mark Nilan Jr;Lady Gaga.
20 Avril Lavigne

Head Above Water flac

Avril Lavigne. 2018. Writer: Stephan Moccio;Travis Clark;Avril Lavigne.

Related questions

Hot questions

Language

Popular Tags