# use siunitx to report percentages in parentheses behind values

First time I am using siunitx to format a table of mine which works fine. Now I would like to add after each value the percentage of some (unreported) total. The values are 5-figure integers and the percentages should be rounded to one decimal.

My attempt so far has been to hijack the uncertainty-option, round to one decimal but use zero-decimal-to-integer to format the integers nicely, and add a percentage sign to the error. Using some trial-and-erro and other SE-pages, I arrived at

\documentclass{article}
\usepackage{siunitx}
\begin{document}

\begin{table}
\begin{tabular}{S[table-alignment=right,
round-mode=places,
round-precision=1,
table-format=5.3,
zero-decimal-to-integer,
input-symbols={()}]}
{title}         \\
11111(1.11)     \\
55555(55.55)     \\
\end{tabular}
\end{table}
\end{document}


which works but lacks two more elements.

1. The percentage sign: If I use (1.11{\percent}) I am surprised to get undefined control sequence.
2. An empty space before the open parenthesis: I though table-space-text-pre={(} would achieve this but it won't.

As I said, this is my first attempt at siunitx, so I am hoping I just misunderstand things. Also, I suspect that there is a more elegant way of achieving the same output but couldn't find it in the wealth of package options.

You simply have to add pair of braces around the contents of the parenthesis, in order to make it non-part of the aligned numbers:

\documentclass{article}
\usepackage{siunitx}
\newcommand{\mypc}[1]{\hfill(\SI{#1}{\percent})}

\begin{document}

\begin{table}
\begin{tabular}{S[table-alignment=right,
round-mode=places,
round-precision=1,
table-format=5.0,
zero-decimal-to-integer,
input-symbols={()\%},,
table-space-text-post={\enspace(11.1\,\%)},
table-align-text-post=true]}
{title} \\
11111 \mypc{1.11} \\
55555 \mypc{5.55} \\
55555 \mypc{55.55}
\end{tabular}
\end{table}

\end{document}


• This works, thanks! However, when the percentage is double-digit (say, 55.55%), the parentheses are no longer-right aligned (even if I use \SI{2.1}), as is the title. Also, is there a way to control the space between value and parentheses as this seems a bit large? Apr 23 '20 at 7:01
• Did you try using num for the percentages? Apr 23 '20 at 7:59
• Yes, as you suggested. Apr 23 '20 at 8:00
• I'll take a look into the spacing. Could you post a small representative example code? Apr 23 '20 at 8:02
• The large spacing is mainly due to a small inconsistency: the table-fomat, sets the space for 3 decimal digits, but the real numbers are integers, and anyway, round-precision is set to 1. So which values do you really need? Apr 23 '20 at 9:21