7

I have a table with number formatting through siunitx. In one column, I have values which show an improvement (or worsening) of one approach over another. To make it really clear, that I'm giving a delta there, I would like to explicitly show the + character for positive values (only for that one column). However, when I write it in my code, it is not rendered.

Minimal working example:

\documentclass[ngerman]{scrbook}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{l *{3}{S[table-format=2.2]}}
    \hline
    {\textbf{Data}} &
    {\textbf{Baseline}} &
    {\textbf{Magic}} &
    {\textbf{$\Delta$}} \\ \hline
    Data A & 34.56 & 45.67 & +11.11 \\ % + character not rendered :(
    Data B & 76.54 & 98.76 & +22,22 \\
    Data C & 45.67 & 34.56 & -11,11 \\ \hline
\end{tabular}
\end{document}

Gives:

tableExample

Instead, I would like +11.11 and +22.22 in the last column. Any hints appreciated.

9

You want retain-explicit-plus.

\documentclass[ngerman]{scrbook}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{l *{3}{S[table-format=2.2,retain-explicit-plus]}}
    \hline
    {\textbf{Data}} &
    {\textbf{Baseline}} &
    {\textbf{Magic}} &
    {\textbf{$\Delta$}} \\ \hline
    Data A & 34.56 & 45.67 & +11.11 \\ % + character not rendered :(
    Data B & 76.54 & 98.76 & +22,22 \\
    Data C & 45.67 & 34.56 & -11,11 \\ \hline
\end{tabular}
\end{document}

enter image description here

8

Torbjørn has explained how to fix the problem but I would typeset the table as follows:

\documentclass{scrbook}

\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{center}
\begin{tabular}{
       l
  *{2}{S[table-format = 2.2]}
       S[table-format = -2.2, retain-explicit-plus]
}
  \toprule
    \multicolumn{1}{c}{{\textbf{Data}}} &
    {\textbf{Baseline}}                 &
    {\textbf{Magic}}                    &
    {$\Delta$}                      \\
  \midrule
    Data~A & 34.56 & 45.67 & +11.11 \\
    Data~B & 76.54 & 98.76 & +22.22 \\
    Data~C & 45.67 & 34.56 & -11.11 \\
  \bottomrule
\end{tabular}
\end{center}

\end{document}

output1

Notice the use of table-format = -2.2 (instead of table-format = 2.2) to get the proper centering in the last column.

Also, notice the use of booktabs to get proper horizontal lines in the table.

Update

In case you also want a bold delta, you can use the following:

\documentclass{scrbook}

\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{center}
\begin{tabular}{
       l
  *{2}{S[table-format = 2.2]}
       S[table-format = -2.2, retain-explicit-plus]
}
  \toprule
    \multicolumn{1}{c}{{\textbf{Data}}} &
    {\textbf{Baseline}}                 &
    {\textbf{Magic}}                    &
    {$\mathbf{\Delta}$}             \\
  \midrule
    Data~A & 34.56 & 45.67 & +11.11 \\
    Data~B & 76.54 & 98.76 & +22.22 \\
    Data~C & 45.67 & 34.56 & -11.11 \\
  \bottomrule
\end{tabular}
\end{center}

\end{document}

output2

  • Totally agree, the example given above was intentionally limited to only the necessary packages. – qqilihq May 19 '14 at 9:16

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.