Compatability issues \tablenum and package colortbl
Problem description
The presence of the colortbl package somehow breaks the number alignment inside tables performed by \tablenum when \multicolumn is used (might also happen with \multirow, but I did not test this). Since the package colortbl only needs to be loaded for this effect, it is by extension also caused by using \usepackage[table]{xcolor} or \documentclass[xcolor={table}]{beamer}.
No error or warning is raised. The order of the packages does not seem to matter.
I am unsure if this is a problem with siunitx oder with colortbl, so please let me know if this the latter applies, and I will direct this problem towards the colortbl package.
In any case I would be grateful for any insight on what the problem is and how to fix it. Thanks in advance for any help.
MWE
Without the package colortbl involved, everything is aligned as expected, regardless of chosen column orientation:
\documentclass{scrarticle}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{c c}
\hline
Text 1 & Text 2 \\
\hline
A1 & B1 \\
\multicolumn{2}{l}{\tablenum{34.556E5}} \\
A3 & B3 \\
\multicolumn{2}{r}{\tablenum{22.5}} \\
A5 & B5 \\
\multicolumn{2}{c}{\tablenum{0.078E-3}} \\
\hline
\end{tabular}
\end{document}
If the package colortbl is loaded (regardless by which means) the alignment fails:
\documentclass{scrarticle}
\usepackage{siunitx}
\usepackage[table]{xcolor} % or directly via \usepackage{colortbl}
\begin{document}
\begin{tabular}{c c}
\hline
Text 1 & Text 2 \\
\hline
A1 & B1 \\
\multicolumn{2}{l}{\tablenum{34.556E5}} \\
A3 & B3 \\
\multicolumn{2}{r}{\tablenum{22.5}} \\
A5 & B5 \\
\multicolumn{2}{c}{\tablenum{0.078E-3}} \\
\hline
\end{tabular}
\end{document}
Specs
- System: Windows 10 64bit
- Distribution: MikTeX (up-to-date)
- Version
siunitx: 3.4.14 - Version
colortbl: 1.0k
The implementation of \tablenum is basically the same as the code for a cell in a table. This means that the fill used for alignment is 'just there' - nothing is boxed up. This gets a bit 'interesting' with colortbl but I think the obvious fix for the use case here is to apply a table-format - which I typically recommend anyway. If I use
\documentclass{scrarticle}
\usepackage{siunitx}
\usepackage[table]{xcolor} % or directly via \usepackage{colortbl}
\begin{document}
\sisetup{table-format = 2.3e-1}
\begin{tabular}{c c}
\hline
Text 1 & Text 2 \\
\hline
A1 & B1 \\
\multicolumn{2}{l}{\tablenum{34.556E5}}\\
A3 & B3 \\
\multicolumn{2}{l}{\tablenum{22.5}} \\
A5 & B5 \\
\multicolumn{2}{l}{\tablenum{0.078E-3}}\\
\hline
\end{tabular}
\end{document}
the alignment is good with or without colortbl. You could add a box around the content for even more rigid outcomes, but I'm not sure that's needed.
Firstly, thanks for the information and sorry for the late reply. Do you still have a idea for a more "central" solution, that would fix this globally?
Adding boxes around the \tablenum commands does nothing or still gives wrong alignments (depending on the box).
While the specific table-format provided fixes this use case, it still requires manual adjustment and a different format still gives wrong alignments.
I still feel like this should ideally be a fix on the package side, as
- it breaks the "out-of-the-box" functionality of
\tablenumfor the user - this problem is really hard to diagnose without extensive testing, as it makes no obvious sense
But of course I see your point if you want to say it's too niche of a problem or should be fixed on the side of colotbl