4

I would like to have this kind of table

\documentclass[12pt]{standalone}
\usepackage{spreadtab}
\usepackage{siunitx}
\usepackage{tabularx}
\usepackage{eurosym}
\usepackage{numprint}
\usepackage{booktabs}
\begin{document}
\begin{spreadtab}{{tabularx}{\linewidth}{XS[table-format=4.2]l}}
\toprule
@{Was}  & @{Betrag [\euro]} & @{Belegart} \\
\midrule
@Nice People Charity & 300 & Spendenbescheinigung @\\
\midrule
@Summe [\euro]  & \textbf{\numprint{:={sum(b2:[0,-1]) }}} & \\
\bottomrule    
\end{spreadtab}
\end{document}

but the money amount in the second and last lines are not aligned as they should:

enter image description here

It seems to me that the last row does not get included by siunitx. How can I get this to work? Tinkering with table-format=4.2 does not really count, because then I have the same problem with another table somewhere (the whole thing is in a custom made command, but let's keep it simple for now).

Bonus if one can get me this to work with

\usepackage{tabu}

instead of tabularx. I'd like to use XS[...] or X[c]{S[...]} or whatever the current command is... ready through Stackexchange got me a little confused... sorry.

I tried using

\usepackage{dcolumn}

which did not work, because it does not support \euro from

\usepackage{eurosym}

Edit: From siunitx: aligning numbers by decimal points in tables doesn't work for bolded or italicized numbers and siunitx: How to get bold, aligned entries and how to align when units differ in length? I got that the reason the numbers are not aligned are because of the boldness and \numprint. However, I have not been able to get the suggestions to work – propably because I am additionally using spreadtab.

Faheem Mitha
  • 7,778
Make42
  • 1,772
  • I can reproduce your issue. However, you do not state what the purpose of using \numprint is. I'm not familiar with the package, but it seems that it's a number formatting package. But siunitx also does number formatting, so it's hard to make a case that one needs to use \numprint here. Can you clarify, please? – Faheem Mitha Sep 10 '21 at 07:40
  • @FaheemMitha: It is a long time ago, but https://ctan.org/pkg/numprint says that the package "Print numbers with separators and exponent if necessary". As far as I remember, my goal was to use a formatter and also make the number bold. If I had only used \textbf, it would not have been formatted. Maybe I did not know how to format it with something else than numprint, but maybe the issue would have remained because of \textbf. – Make42 Sep 10 '21 at 17:47
  • Thank you for replying. I think you can use siunitx instead of numprint. It looks like siunitx is a superset in terms of features. Though without carefully looking at both packages I cannot be sure, of course. Having said that, there still seems to be an issue using \numprint with siunitx v3 in TL 2021. Can you still reproduce it with TL 2021? – Faheem Mitha Sep 10 '21 at 18:18

1 Answers1

3

I managed to find a solution after a lot of reasoning and trying out.

The reason for my problem is caused by the boldness and the letterspacing, but because something other than the number was put in the supposed-to-be-cell. In my example this "something other" is the \textbf{\numprint{:={ ... }. This seems to confuse the spreadtab-siunitx-combination. \robustify from siunitx: aligning numbers by decimal points in tables doesn't work for bolded or italicized numbers does not help either.

The solution is to make the entire row bold (giving the command at a different place – tabu is helping with that) and then un-bolding the cells which are not supposed to be bold:

\begin{spreadtab}{{tabu} to \linewidth{XS[table-format=4.2]l}}
\toprule
@{Was}  & @{Betrag [\euro]} & @{Belegart} \\
\midrule
@Nice People Charity & 300 & Spendenbescheinigung @\\
\midrule
\rowfont\bfseries
{\mdseries @Summe [\euro]}  & sum(b2:[0,-1]) & \\
\bottomrule
\end{spreadtab}
Make42
  • 1,772