1

Prior to the updates published in July 2022 I used the ctable package to define annotated tables. But after that date those tables containing siunitx columns and entries give rise to a plethora of errors, mainly referencing to siunitx. Browsing the internet provided me with a possible solution to the issue in the form of the longtblr environment provided by the tabularray package. So I started converting one of the problematic tables.

That conversion went well except for two errors I can't resolve. The first (major) one is the formatting of the caption of the table. I have configured that using the options of the captions package. These options aren't parsed onto the table caption created by longtblr. That caption should look the same as the one in the ctable example. So why not? And more importantly: how to solve / work around that?

The second (minor) question is about something odd at the last entry of the table. Somehow the \textbf{D} needs to stay in that cell, even though the cell is already defined as boldface in the preamble of longtblr. Removing that code results in a siunitx error and not printing of that entry.

In the given MWE both tables environments are presented. The third option using tabularx is commented out as that doesn't even compile. The tables are placed in a tcolorbox environment. The package tcolorbox needs to be loaded first to prevent all kind of ams related errors (ams is massively used by chemmacros).

If someone can point out to me why the table uisng ctable causes so many errors I would be grateful. Since I am going to migrate all tables to tabularray that answer is just a bonus to the one posed in this question.

\documentclass[a4paper,12pt]{article}

\usepackage[many]{tcolorbox} %needs to be loaded first to prevent ams / math font conflicts \tcbset{colback=gray!2.5, width=\linewidth, frame hidden, boxrule=0pt, toprule=1pt, bottomrule=1pt, sharp corners, boxsep=3pt, top=12pt, bottom=3pt,}

%----- taal/font pakketten ----- \usepackage[dutch]{babel}

%----- font paketten ----- \usepackage{gfsartemisia} \usepackage[charter]{mathdesign} \usepackage[scale=0.95]{tgheros}

%----- chemische pakketten ----- \usepackage[modules={minimal}]{chemmacros} \chemsetup{greek=mathdesign,formula=chemformula} \chemsetup[chemformula]{format=\sffamily}

%----- grafische pakketten ----- %\usepackage{xcolor} \usepackage{colortbl} \usepackage{graphicx} \usepackage{tikz} %\usepackage[many]{tcolorbox}

%----- opmaak pakketten ----- \usepackage[labelfont=bf,labelsep=endash,font=small]{caption} \usepackage{ctable} \usepackage{booktabs} %\usepackage{multirow} %\usepackage{bigdelim,bigstrut} \usepackage{dashrule}

\usepackage{tabularray} \UseTblrLibrary{booktabs,siunitx}

%----- layout pakketten ----- \usepackage[text={17.0cm,26cm},top=2.0cm,left=2.5cm]{geometry} %\usepackage{xstring}

%----- wiskunde paketten ----- \usepackage{siunitx} \sisetup{ table-alignment-mode=format, table-number-alignment=center, output-decimal-marker={,}, reset-text-family=false, % doesn't work - math roman font is still selected detect-all % now undocumented, but needed to maintain the tgheros font in siuntitx macros }

%----- aanvullende pakketten ---- %\usepackage{xpatch} \usepackage{float}

%----- font en versie selectie ----- \renewcommand*{\familydefault}{\sfdefault} \setlength{\parindent}{0mm} \renewcommand{\baselinestretch}{1.2} \setlength{\marginparwidth}{40pt}

\tcbset{colback=gray!2.5, width=\linewidth, frame hidden, boxrule=0pt, toprule=1pt, bottomrule=1pt, sharp corners, boxsep=3pt, bottom=3pt,}

\begin{document}

Using the \textit{ctable}-package to create an annotated table (used to compile correctly prior to the July 2022 updates):

\begin{tcolorbox}[top=-12pt] \ctable[pos=H,caption={Analyse van de synthese van \textit{cafeïne} volgens Traube uit 1900}] {| p{2.4cm} S[table-format=3.3] | p{2.4cm} S[table-format=3.3] | p{2.4cm} S[table-format=3.3] |} {\tnote[1]{MW staat voor molecuulmassa in \si{\g\per\mole}} \tnote[2]{Afvalstoffen zijn in \textcolor{red}{rood} weergegeven.}}{ \FL \rowcolor{yellow!30} \multicolumn{2}{| c}{\textbf{Reagent}} & \multicolumn{2}{| c}{\textbf{Gebruikt in cafeïne}} & \multicolumn{2}{| c |}{\textbf{Niet gebruikt}} \ \rowcolor{yellow!10} \textit{Formule} & \textit{MW} & \textit{Formule} & MW & \textit{Formule} & \textit{MW} \ML \ch{C3H8N2O} & 88.114 & \ch{C3H6N2O} & 86.098 & & \ML \ch{C3H3NO2} & 85.064 & \ch{C3HNO} & 67.048 & \textcolor{red}{\ch{H2O}} & 18.016 \ML \ch{HNO2} & 47.018 & \ch{N} & 14.01 & \textcolor{red}{\ch{H2O}} & 18.016 \ML 2 \ch{H2} & 4.032 & & & \textcolor{red}{\ch{H2O}} & 18.016 \ML \ch{HCOOH} & 46.026 & \ch{C} & 12.01 & \textcolor{red}{\ch{H2O}} & 18.016 \ML \ch{NaOH} & 39.998 & & & \textcolor{red}{2 \ch{H2O}} & 36.032 \ML \ch{CH3Cl} & 50.484 & \ch{CH3} & 15.034 & \textcolor{red}{\ch{NaCl}} & 58,44 \ML \rowcolor{yellow!30} \multicolumn{2}{| c}{\textbf{Totaal}} & \multicolumn{2}{| c}{\textbf{Cafeïne}} & \multicolumn{2}{| c |}{\textbf{Restant}} \ML \textbf{A} & \textbf{B} & \ch{C8H10N4O2} & 194.20 & \textbf{C} & \textbf{D}
\LL } \end{tcolorbox}

% \begin{tabularx} % {| p{3.0cm} S[table-format=3.3] | p{3.0cm} S[table-format=3.3] | p{3.0cm} S[table-format=3.3] |} % \toprule % \rowcolor{yellow!30} \multicolumn{2}{| c}{\textbf{Reagent}} & \multicolumn{2}{| c}{\textbf{Gebruikt in cafeïne}} & \multicolumn{2}{| c |}{\textbf{Niet gebruikt}} \ % \rowcolor{yellow!10} \textit{Formule} & \textit{MW} & \textit{Formule} & \textit{MW} & \textit{Formule} & \textit{MW} \tabularnewline \midrule % \ch{C3H8N2O} & 88.114 & \ch{C3H6N2O} & 86.098 & & \tabularnewline \midrule % \ch{C3H3NO2} & 85.064 & \ch{C3HNO} & 67.048 & \textcolor{red}{\ch{H2O}} & 18.016 \tabularnewline \midrule % \ch{HNO2} & 47.018 & \ch{N} & 14.01 & \textcolor{red}{\ch{H2O}} & 18.016 \tabularnewline \midrule % 2 \ch{H2} & 4.032 & & & \textcolor{red}{\ch{H2O}} & 18.016 \tabularnewline \midrule % \ch{HCOOH} & 46.026 & \ch{C} & 12.01 & \textcolor{red}{\ch{H2O}} & 18.016 \tabularnewline \midrule % \ch{NaOH} & 39.998 & & & \textcolor{red}{2 \ch{H2O}} & 36.032 \tabularnewline \midrule % \ch{CH3Cl} & 50.484 & \ch{CH3} & 15.034 & \textcolor{red}{\ch{NaCl}} & 58,44 \tabularnewline \midrule % \rowcolor{yellow!30} \multicolumn{2}{| c}{\textbf{Totaal}} & \multicolumn{2}{| c}{\textbf{Cafeïne}} & \multicolumn{2}{| c |}{\textbf{Restant}} \tabularnewline \midrule % \textbf{A} & \textbf{B} & \ch{C8H10N4O2} & 194.20 & \textbf{C} & \textbf{D}
% \bottomrule % \end{tabularx}

%\clearpage

Same table as above using the \textit{tabularray}-package.

\begin{tcolorbox}[top=-12pt] \begin{longtblr} [ caption={Analyse van de synthese van \textit{cafeïne} volgens Traube uit 1900}, %<- doesn't use the formating options given for captions remark{1}={\small MW staat voor molecuulmassa in \unit{\g\per\mole}}, remark{2}={\small Afvalstoffen zijn in \textcolor{red}{rood} weergegeven}, ]{ colsep=10pt, colspec={p{2.4cm} Q[si={table-format=3.3,},c] p{2.4cm} Q[si={table-format=3.3,},c] p{2.4cm} Q[si={table-format=3.3,},c] }, cell{1-11}{2,4,6}={wd=1.5cm}, row{1,10}={bg=yellow!30,font=\bfseries}, row{2}={bg=yellow!10, font=\itshape}, cell{11}{1,2,5,6}={font=\bfseries,c}, cell{3-9}{5}={fg=red}, hline{1-12}={blue5, solid, 1pt}, vline{1,3,5,7}={blue5, solid, 1pt}, } \SetCell[c=2]{c} Reagent & & \SetCell[c=2]{c} Gebruikt in cafeïne & & \SetCell[c=2]{c} Niet gebruikt & \ Formule & MW & Formule & MW & Formule & MW \ \ch{C3H8N2O} & 88.114 & \ch{C3H6N2O} & 86.098 & & \ \ch{C3H3NO2} & 85.064 & \ch{C3HNO} & 67.048 & \ch{H2O} & 18.016 \ \ch{HNO2} & 47.018 & \ch{N} & 14.01 & \ch{H2O} & 18.016 \ 2 \ch{H2} & 4.032 & & & \ch{H2O} & 18.016 \ \ch{HCOOH} & 46.026 & \ch{C} & 12.01 & \ch{H2O} & 18.016 \ \ch{NaOH} & 39.998 & & & 2 \ch{H2O} & 36.032 \ \ch{CH3Cl} & 50.484 & \ch{CH3} & 15.034 & \ch{NaCl} & 58,44 \ \SetCell[c=2]{c}{Totaal} & & \SetCell[c=2]{c}{Cafeïne} & & \SetCell[c=2]{c}{Restant} & \ A & B & \ch{C8H10N4O2} & 194.20 & C & \textbf{D} % <- removing \textbf results in an error / not printing the last line \end{longtblr} \end{tcolorbox}

\end{document}

alchemist
  • 1,761
  • the ctable version breaks as siunitx doesn't like that the row ends are hidden in alias commands, see https://github.com/josephwright/siunitx/issues/335 – Ulrike Fischer Dec 31 '22 at 22:38

1 Answers1

2

Happy New Year!

At use of the tabularray package try the following:

  • That talltblr (and longtblr) consider caption settings defined by caption package, you need to define new table mode, where default tabularray caption style replace with captionof, which consider \captionsetup[table]{...} defined in document preamble-
  • replace longtblr with talltblr (since table is in box and which cant be broken between pages)
  • reduce options in sisetupto only needed ones
  • optimize options/style settings in talltablr preamble
  • cleanup table body from local style settings
\documentclass[a4paper,12pt]{article}
\usepackage[text={17.0cm,26cm},top=2.0cm,left=2.5cm]{geometry}

\usepackage[dutch]{babel} \usepackage[many]{tcolorbox} %needs to be loaded first to prevent ams / math font conflicts \tcbset{colback=gray!2.5, width=\linewidth, frame hidden, boxrule=0pt, toprule=1pt, bottomrule=1pt, sharp corners, boxsep=3pt, top=12pt, bottom=3pt,} %----- font paketten ----- \usepackage{gfsartemisia} \usepackage[charter]{mathdesign} \usepackage[scale=0.95]{tgheros} \renewcommand*{\familydefault}{\sfdefault}

\usepackage[modules={minimal}]{chemmacros} \chemsetup{greek=mathdesign,formula=chemformula} \chemsetup[chemformula]{format=\sffamily}

\usepackage{xcolor} \usepackage{tabularray} \UseTblrLibrary{booktabs,siunitx} \sisetup{ output-decimal-marker={,}, reset-text-family=false, % doesn't work - math roman font is still selected detect-all % now undocumented, but needed to maintain the tgheros font in siunitx macros } \usepackage{caption} % added
\captionsetup[table]{skip=1ex, font=small, labelfont=bf, } % set up it as you wish

\begin{document} \begin{tcolorbox}%[top=-12pt] \NewTblrTheme{captionof}% for use caption set up in talltablr captions { \DefTblrTemplate{caption}{default}% {\addtocounter{table}{-1}% \captionof{table}{\InsertTblrText{caption}}} } \SetTblrStyle{remark}{font=\footnotesize} \centering \begin{talltblr}[
theme = captionof, caption = {Analyse van de synthese van \textit{cafeïne} volgens Traube uit 1900.}, % now use the formatting options given for caption package remark{1} = {MW staat voor molecuulmassa in \unit{\g\per\mole}}, remark{2} = {Afvalstoffen zijn in \textcolor{red}{rood} weergegeven}, ]{colsep = 10pt, colspec = {*{3}{l Q[c, si={table-format=3.3}]}}, row{1-2}= {guard}, cell{3-9}{5} = {fg=red}, cell{Z}{1,2,5,6} = {guard, font=\bfseries, c}, row{1,Y} = {guard, bg=yellow!30, font=\bfseries}, row{2} = {guard, bg=yellow!10, font=\itshape}, hlines = {blue, 1pt}, vline{1,3,5,7} = {blue5, 1pt}, } \SetCell[c=2]{c} Reagent
& & \SetCell[c=2]{c} Gebruikt in cafeïne
& & \SetCell[c=2]{c} Niet gebruikt & \ Formule & MW & Formule & MW & Formule & MW \ \ch{C3H8N2O} & 88.114 & \ch{C3H6N2O} & 86.098 & & \ \ch{C3H3NO2} & 85.064 & \ch{C3HNO} & 67.048 & \ch{H2O} & 18.016 \ \ch{HNO2} & 47.018 & \ch{N} & 14.01 & \ch{H2O} & 18.016 \ 2 \ch{H2} & 4.032 & & & \ch{H2O} & 18.016 \ \ch{HCOOH} & 46.026 & \ch{C} & 12.01 & \ch{H2O} & 18.016 \ \ch{NaOH} & 39.998 & & & 2 \ch{H2O} & 36.032 \ \ch{CH3Cl} & 50.484 & \ch{CH3} & 15.034 & \ch{NaCl} & 58,44 \ \SetCell[c=2]{c}{Totaal}
& & \SetCell[c=2]{c}{Cafeïne}
& & \SetCell[c=2]{c}{Restant}
& \ A & B & \ch{C8H10N4O2} & 194.20 & C & D \ \end{talltblr} \end{tcolorbox}

\end{document}

enter image description here

Zarko
  • 296,517
  • Happy New Year too. May it be a good year. I studied your code. Thanks for giving me the answer to the caption question. So I have to define a theme for tabularray to use. I came across that reading the manual, but didn't connect that to my question :-S . – alchemist Jan 01 '23 at 08:30
  • you added a few new lines in the preamble of the table. Why using 'row{1-2}={guard}' ? If it's to protect the text in those rows, row Y (10) should be guarded as well. Leaving out that option doesn't seem te affect the output anyway. – alchemist Jan 01 '23 at 08:41
  • In your answer the content of the last cell is empty. There should be a bold D present. Adding that to your answer, the siunitx errors occurred again. Maybe it has something to do with the issue @Ulrike Fischer pointed out in her comment. I am going to turn that minor question into a new question. – alchemist Jan 01 '23 at 08:45
  • @alchemist, (regarding above comment) oh I simple lost it. I add them now. – Zarko Jan 01 '23 at 12:33
  • @alchemist, you need to read recend package documentation. Option guard is added to version 2022B, and enable to vrite text in S cells. Added theme is not (yet) described in documentation, but I got it in some conversation with package author. In table is not row Y(10) only is used option row{˛1,Y}. Row Y (Y means row before last) not need to be protected because two column cells start in columns of l type. – Zarko Jan 01 '23 at 12:49
  • @alchemist, by mistake I add specification row{10} which overwrite cell{Z}{1,2,5,6}={font=\bfseries,c}. No is removed and inserted correct table image. – Zarko Jan 01 '23 at 13:26
  • Thanks a lot, @Zarko . I already adapted your code slightly to get the last cell printed too. In answer to my question about the errors occurring using D in that cell. @Joseph Wright explained the use of D in siunitx to denote exponential numbers (see https://tex.stackexchange.com/questions/670261/caption-in-longtblr-doesnt-follow-options-given-to-format-captions). A lone D would confuse siunitx as there is no number present. Putting it in curly brackets - as you did - or using \textbf{D} - as I did - prevents this error. – alchemist Jan 01 '23 at 15:06
  • @alchemist, I just edit my answer. Added are some explanation and corrected (simplified) table preamble. Now in the last cell you can simply write "D" (since to last row is added option guard). – Zarko Jan 01 '23 at 15:10
  • So the line row{1-2}={guard} has become obsolete too, since you combined the guard options with the colloring of those rows? ;-P Again thanks you for your prompt replies and very useful answers, @Zarko. Learning a lot from them, since tabularray was a new package to me. – alchemist Jan 01 '23 at 15:15
  • @alchemist, yes, I optimize talltblr preamble. Now seems, that you may consider to accept answer ;-) – Zarko Jan 01 '23 at 15:18
  • Already had accepted the first time you answered ;-P Confirmed that again – alchemist Jan 01 '23 at 16:10