TransWikia.com

Adding footnote to the table leads to the error: ! Extra }, or forgotten endgroup

TeX - LaTeX Asked on November 3, 2020

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.5fillrelax egroup egroup 
                                                  begingroup CT@setup CT@...
l.23 ...tal & 160tabularnote{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}{footnotesizebfseries}
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}

2 Answers

(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}{footnotesizebfseries}
sisetup{output-decimal-marker={,}}


protecteddefmyfootnote{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,5hphantom{textsuperscript{a}} & 41,5\
        Bad   & 140rlap{tabularnote{My first note}}hphantom{,5textsuperscript{a}}  & 58,5\
        Bad   & 140,5tabularnote{My second note}  & 58,5\
        Total & hphantom{0}60hphantom{,5textsuperscript{a}} & 100,0\
    end{NiceTabular}
}

end{document}

Output of the above code

Correct answer by F. Pantigny on November 3, 2020

(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}{footnotesizebfseries}
sisetup{output-decimal-marker={,}}

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

protecteddefmyfootnote{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

Answered by F. Pantigny on November 3, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP