1

I have a couple of different methods to solve a diven problem and I want to compare them in a table. My aim is it to automatically add the relative deviation.

I got some problems using siunitx within a table, but I solved it using this.

Now my problem is, that my last column should have an explicit (plus) sign. When I use something like (did not use my automatic calculation in here, as the error occurs even without it)...

\documentclass{article}
\usepackage{siunitx} 

\begin{document}        

\begin{tabular}{lSSS} 
\hline
\hline
\textbf{Type} & \textbf{before} & \textbf{after} & \textbf{change}\\
& $\left[\frac{m^3}{h}\right]$ & $\left[\frac{m^3}{h}\right]$ & $\left[\%\right]$\\
\hline
Method A & 10.05 & 22.84 & \num[explicit-sign=+]{127.26}
\hline
\hline
\end{tabular}

\end{document}  

...I get the following error message.

> Argument of \num has an extra }.

Does anybody has an idea, why it did not work? Or what to do to make it work?

I cannot use explicit-sign=+ within \sisetup as I only want my last column to have the explicit sign.

Thanks for your help.

0

2 Answers 2

4

You can use \begin{tabular}{lSSS[explicit-sign=+]} ....

BTW: non-numerical input in S-type columns should be escaped by putting the material in braces: {\textbf{before}}. Also: since you're using siunitx already you should use it for the units as well. In my example below I also use booktabs for nicer table rules.

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

\sisetup{per-mode=symbol}

\begin{document}

\begin{tabular}{lSSS[explicit-sign=+,table-format=3.2]}
  \toprule
    {\textbf{Type}} & {\textbf{before}} &
    {\textbf{after}} & {\textbf{change}} \\
    & {\si{\cubic\metre\per\hour}} & {\si{\cubic\metre\per\hour}}
    & {\si{\percent}} \\
  \midrule
    Method A & 10.05 & 22.84 & 127.26 \\
    Method A & 10.05 & 22.84 & 127.26 \\
  \bottomrule
\end{tabular}

\end{document}

enter image description here

2
  • How embarassing - this is indeed a simple solution. Do you have any idea why in-row-soluation does not work? Thank you anyways! At this moment I'm changing all my tables to siunitx-tables, so I'll take your other advices regarding the units, non-numerical input and tables rules.
    – Hackbard_C
    Aug 5, 2014 at 9:56
  • 1
    Simply put: cell contents in S columns already are parsed by a \num equivalent. Using \num in such a cell is a bit like \num{\num{...}} which you probably wouldn't expect to work...
    – cgnieder
    Aug 5, 2014 at 9:59
1

It is enough to write {+}. I took the opportunity to load booktabsto improve the look of horizontal rules, defining a \doubletoprule and a doublebottomrule commands.

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

\newcommand\doubletoprule{%
\toprule
\specialrule{0.025em}{0.6\doublerulesep}{\belowrulesep}}%
\newcommand\doublebottomrule{%
\specialrule{0.025em}{\aboverulesep}{0.6\doublerulesep}
\bottomrule}%

\begin{document}

\begin{tabular}{@{\hskip5pt}lSSS@{\hskip-5pt}}
\doubletoprule
\textbf{Type} & {\textbf{before}} & {\textbf{after}} & {\textbf{change  }}\\
& {$\Bigl [\mfrac{m^3}{h}\Bigr ]$} & {$\Bigl[\mfrac{m^3}{h}\Bigr]$} & {$\bigl[ \,\%\,\bigr]$} \\
\cmidrule(l{2pt}r{4pt}){1-4}
Method A & 10.05 & 22.84 & {+} 127.26\\
Method B & 10.05 &- 22.84 & - 127.26\\
\specialrule{0.025em}{\aboverulesep}{0.6\doublerulesep}
\bottomrule
\end{tabular}

\end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .