在 2022 年 7 月发布更新之前,我使用该ctable
包来定义带注释的表格。但在此日期之后,包含siunitx
列和条目的表格会出现大量错误,主要涉及siunitx
。浏览互联网为我提供了该问题的一种可能解决方案,即longtblr
该包提供的环境tabularray
。所以我开始转换其中一个有问题的表格。
除了两个我无法解决的错误外,转换过程很顺利。第一个(主要)错误是表格标题的格式。我已使用包的选项对其进行了配置captions
。这些选项不会解析到由 创建的表格标题上longtblr
。该标题应与示例中的标题相同ctable
。那么为什么不呢?更重要的是:如何解决/解决这个问题?
第二个(次要)问题是关于表格最后一项的奇怪之处。不知何故,需要\textbf{D}
保留在该单元格中,即使单元格已在 的序言中定义为粗体longtblr
。删除该代码会导致siunitx
错误,并且不会打印该条目。
在给定的 MWE 中,两个表环境都呈现了出来。第三个选项 usingtabularx
被注释掉了,因为它甚至无法编译。表被放置在环境中。需要先加载tcolorbox
包以防止出现所有类型的相关错误(被大量使用)。tcolorbox
ams
ams
chemmacros
如果有人能指出为什么使用表格ctable
会导致这么多错误,我将不胜感激。因为我要将所有表格迁移到tabularray
该答案,所以这只是对这个问题提出的答案的一个补充。
\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}
答案1
新年快乐!
在使用该tabularray
包时请尝试以下操作:
- 考虑到包中定义的标题设置,您需要定义新的表格模式,其中默认标题样式替换为,这 在文档序言中定义
talltblr
-longtblr
caption
tabularray
captionof
\captionsetup[table]{...}
- 替换
longtblr
为talltblr
(因为表格在框中,并且不能在页面之间拆分) - 将选项减少
sisetup
到仅需要的选项 talltablr
优化序言中的选项/样式设置- 从本地样式设置中清理表体
\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}