5

By making tables I am using packages siunitx, nicematrix and makecell. These three packages applied simultaneously seems to be sufficient for solving my problems with tables - like this one. I am using siunitx package, not dcolumn package, because the last one gives not satisfying placement of numbers. I met the problem with placing the table note. The note mark has to be placed in the cell of the middle column. While I am using S-type column within NiceTabular environment I got the error:

! Extra }, or forgotten \endgroup.
<template> ...z@ plus.5fill\relax \egroup \egroup 
                                                  \begingroup \CT@setup \CT@...
l.23 ...tal & 160\tabularnote{My footnote text.} &
                                                   100,0\\

How to solve this problem? It resembles this one (in this topic probably one of @moewe's comments leads to the solution, nevertheless I can't cope with it). Code:

\documentclass[table]{standalone}
\usepackage{siunitx}
\usepackage{makecell}
\usepackage{nicematrix}
\usepackage{enumitem}

\renewcommand{\theadfont}{\footnotesize\bfseries} \sisetup{output-decimal-marker={,}}

\begin{document} {\footnotesize \begin{NiceTabular}[hvlines,code-before=\rowcolor{gray!50}{1-1}]{ l S[table-format=3,zero-decimal-to-integer,table-space-text-post=\textsuperscript{a}] S[table-format=3.1] } {\thead{Side-heading\description}} & {\thead{First column\with data\description}} & {\thead{Second column\with data\description}}\ Good & 120, & 41,5\ Bad & 140, & 58,5\ Total & 260,\tabularnote{My footnote text.} & 100,0\ \end{NiceTabular} } \end{document}

forrest
  • 958

2 Answers2

8

(I'm the author of nicematrix).

This is a partial incompatibility between nicematrix and the columns S of siunitx.

I will try to find a solution but here is a workaround by using the command \tablenum of siunitx (which is the 'command version' of the S column type).

However, the command tablenum seems to delete all the spaces in its argument (and it will delete the spaces in the text of the tabular note). That's why I have put the text of the tabular note in a TeX macro \myfootnote (it would be possible to use \NewDocumentCommand but I wanted to emphasize the fact that it must be protected).

Moreover, the case of an integer number requires a special treatment...

\documentclass{article}
\usepackage{siunitx}
\usepackage{makecell}
\usepackage{nicematrix}
\usepackage{enumitem}

\renewcommand{\theadfont}{\footnotesize\bfseries} \sisetup{output-decimal-marker={,}}

\NewDocumentCommand { \mytablenum } { } { \tablenum[table-format=3,zero-decimal-to-integer]}

\protected\def\myfootnote{My table note.}

\begin{document} {\footnotesize \begin{NiceTabular}[hvlines,code-before=\rowcolor{gray!50}{1-1}]{ l c S[table-format=3.1] } {\thead{Side-heading\description}} & {\thead{First column\with data\description}} & {\thead{Second column\with data\description}}\ Good & \mytablenum{120,5{\tabularnote{\myfootnote}}} & 41.5\ Bad & \mytablenum{140,} & 58.5\ Total & \mytablenum{60}\rlap{\tabularnote{Another table note.}} & 100.0\ \end{NiceTabular} }

\end{document}

Output of the above code

F. Pantigny
  • 40,250
  • Thank you for the response. Now I am trying to apply this to the integer number - it is not correct to emphasize that in some process is not engaged the fractional part of person, by adding decimal part to the number (in Polish komma is s decimal separator). Could you give some prompt, how to apply your solution to column with integers, please? – forrest Sep 29 '20 at 07:48
  • 1
    I'm not sure to understand what you mean but I have modified my answer to put a tabular note next to an integer number (it's a workaround...). – F. Pantigny Sep 29 '20 at 08:52
  • In my table the number of people has to be eg. 721, not 721.0. Removing the statement table-space-text-post=\textsuperscript{a} leads to wrong horizontal placement: the widest string (according to my guidebooks), which in your response is 120,5a has to be centered horizontally in the cell. But adding table-space-text-post=\textsuperscript{a} gives unwanted space between number and footnotemark. – forrest Sep 29 '20 at 09:48
  • In the second column, you don't have tabular notes and, so, you can use the S column type. You can use the key zero-decimal-to-integer in that column (and you will have 100 instead of 100,0 in my example). However, this is not possible in the first column... – F. Pantigny Sep 29 '20 at 11:12
  • 1
    If you want the contents of the first column centered (including the lables of the tabular notes), I think that, as of now, you will have to drop \tablenum in that column and do the job by hand. I have put a second answer where I do the whole job by hand (it's an awful workaround). – F. Pantigny Sep 29 '20 at 11:14
  • I wonder if putting table-space-text-post=\textsuperscript{a} into \mytablenum definition and adjustment by hand \mytablenum{260}\!\!\!\!\tabularnote{\myfootnote} ensures horizontal centering of the cell content. – forrest Sep 29 '20 at 12:33
  • 1
    Yes. It would work but the \!\!\!\! is an adjustement 'by hand'... – F. Pantigny Sep 29 '20 at 19:03
  • I am using this workaround in the subsequent tables, and met necessity to apply \hspace on both sides of footnotemark, for instance \mytablenum{19}{\hspace{-2.8mm}\tabularnote{\myfootnote}\hspace{0.7mm}}. It is because: 1) decimal separators in a given column must be placed on the same vertical line, 2) column content must be horizontally centered with respect to the most protruding elements. Using \! command disturb vertical alignment from the point (1). – forrest Oct 17 '20 at 12:47
3

(I'm the author of nicematrix)

In a first answer to this question, I have said that the problem of the OP is a (partial) incompatibility between nicematrix and the columns S of siunitx. I've given a workaround with \tablenum of siunitx.

Here is another workaround: siunitx is not used at all (in the first column). This is really a heavy workaround because you have to do the job of centering by hand will \hphantom and \rlap. However, by this way, the contents are strictly centered (including the labels of the tabular notes).

\documentclass{article}
\usepackage{siunitx}
\usepackage{makecell}
\usepackage{nicematrix}
\usepackage{enumitem}

\renewcommand{\theadfont}{\footnotesize\bfseries} \sisetup{output-decimal-marker={,}}

\protected\def\myfootnote{My table note.}

\begin{document} {\footnotesize \begin{NiceTabular}[hvlines,code-before=\rowcolor{gray!50}{1-1}]{ l c S[table-format=3.1,zero-decimal-to-integer] } {\thead{Side-heading\description}} & {\thead{First column\with data\description}} & {\thead{Second column\with data\description}}\ Good & 120,5\hphantom{\textsuperscript{a}} & 41,5\ Bad & 140\rlap{\tabularnote{My first note}}\hphantom{,5\textsuperscript{a}} & 58,5\ Bad & 140,5\tabularnote{My second note} & 58,5\ Total & \hphantom{0}60\hphantom{,5\textsuperscript{a}} & 100,0\ \end{NiceTabular} }

\end{document}

Output of the above code

F. Pantigny
  • 40,250