我有一段相当复杂的代码,它在最后生成了几个表。目前的问题在于最后一个表的区域设置。这使用来自的命令来datatool
计算几个位置的总和。在各个表中(例如\excTable{EarlyCareer}
和\excTable{Collaboration}
),一切看起来都符合预期。但使用命令\DTLsumcolumn
或 \DTLsumforkeys
会更改区域设置 - 因此小数点标记被解释为错误。在环境\DTLsumcolumn{TotalStructuralMeasures}{totalsum}{\excSumTotalStructuralMeasures}
之外使用tblr
,一切都很好。
\DTLdecimaltolocale
我也不能使用,因为这会导致编译错误:
! Package siunitx Error: Invalid number '35,,000'.
For immediate help type H <return>.
...
l.242 \excTable{TotalStructuralMeasures}
以下是完整的 MWE:
\documentclass{scrbook}
\usepackage{datatool,xstring}
\usepackage{xkeyval}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\PassOptionsToPackage{
mode = match,
propagate-math-font = true,
reset-math-version = false,
reset-text-family = false,
reset-text-series = false,
reset-text-shape = false,
text-family-to-math = true,
text-series-to-math = true,
tight-spacing = true,
group-minimum-digits = 4, % --> 1.234 instead of 1234
group-separator = {,},% for "12.345" instead of "12 345" %
%table-format = 6,
table-alignment-mode = format,
%table-auto-round,
locale=UK,
}{siunitx}
\UseTblrLibrary{siunitx}
\sisetup{output-decimal-marker={.}} % Neue Zeile hinzugefügt
\providecommand\excDB{}
\makeatletter
\define@key{funding}{category}{\DTLnewdbentry{\excDB}{category}{#1}}
\define@key{funding}{fundingYear1}{\DTLnewdbentry{\excDB}{fundingYear1}{#1}}
\define@key{funding}{fundingYear2}{\DTLnewdbentry{\excDB}{fundingYear2}{#1}}
\define@key{funding}{fundingYear3}{\DTLnewdbentry{\excDB}{fundingYear3}{#1}}
\define@key{funding}{fundingYear4}{\DTLnewdbentry{\excDB}{fundingYear4}{#1}}
\define@key{funding}{fundingYear5}{\DTLnewdbentry{\excDB}{fundingYear5}{#1}}
\define@key{funding}{fundingYear6}{\DTLnewdbentry{\excDB}{fundingYear6}{#1}}
\define@key{funding}{fundingYear7}{\DTLnewdbentry{\excDB}{fundingYear7}{#1}}
\define@key{funding}{totalsum}{\DTLnewdbentry{\excDB}{totalsum}{#1}}
\makeatother
\NewDocumentCommand{\excEntry}{ m o m }{%
% #1 name of the database into which the values are stored
% #2 name of the keys
% #3 part of the key-values
\def\excDB{#1}%
\DTLifdbexists{\excDB}{}{\DTLnewdb{\excDB}}%
\DTLnewrow{\excDB}%
\IfNoValueTF{#2}{\setkeys{#1}{#3}}{\setkeys{#2}{#3}}%
}
\NewDocumentCommand{\tmpDTLifdbexists}{mmm}{%
\DTLifdbexists{#2}
{\DTLsumforkeys{#2}{%
fundingYear1,%
fundingYear2,%
fundingYear3,%
fundingYear4,%
fundingYear5,%
fundingYear6,%
fundingYear7%
}{#3}%
\excEntry{#1}[funding]{%
category={#2},
totalsum={#3}%
}}%yes
{}%no
}
\makeatletter
\NewDocumentCommand{\excTotalStructuralMeasuresTable}{}{%
\def\tblrbody{}%
\tmpDTLifdbexists{TotalStructuralMeasures}{EarlyCareer}{\EarlyCareer}%
\tmpDTLifdbexists{TotalStructuralMeasures}{Collaboration}{\Collaboration}%
\DTLforeach{TotalStructuralMeasures}{%
\category =category,%
\totalsum =totalsum%
}{%
%%\DTLdecimaltolocale{\totalsum}{\totalsum}% try to convert . to ,
\protected@edef\tblrbody{\tblrbody
\category & \totalsum % <--- wrong locale // decimal
\\
}}%
% getting the sum of the total table
\DTLsumcolumn{TotalStructuralMeasures}{totalsum}{\excSumTotalStructuralMeasures}
\begin{tblr}[%
expand = \tblrbody,
long
]{%
vspan=even,
colspec = {%
*{1}{X[4,m]}
*{1}{X[c,si={table-format=6.0, round-mode=places, output-decimal-marker={,},locale=UK}]}
%% *{1}{X[c,si={locale=UK}]}
},
hline{Y}={wd=1pt},
column{2}={halign={c}},
row{1}={guard}
}
Structural measures & Total Year\\
\tblrbody
Total & \excSumTotalStructuralMeasures \\
\end{tblr}%
}
\NewDocumentCommand{\excFundingRequestTable}{}{%
\begingroup%
\def\tblrbody{}%
\DTLforeach{\tmpLocalDB}{%
\category=category,%
\FundingYearOne ={fundingYear1},%
\FundingYearTwo ={fundingYear2},%
\FundingYearThree ={fundingYear3},%
\FundingYearFour ={fundingYear4},%
\FundingYearFive ={fundingYear5},%
\FundingYearSix ={fundingYear6},%
\FundingYearSeven ={fundingYear7}%
}{%
\protected@edef\tblrbody{\tblrbody
\category
& \FundingYearOne
& \FundingYearTwo
& \FundingYearThree
& \FundingYearFour
& \FundingYearFive
& \FundingYearSix
& \FundingYearSeven \\
}}%
\begin{tblr}[%
expand = \tblrbody,
long
]{%
vspan=even,
colspec = {%
*{1}{X[3,m]}
*{7}{X[si={%
table-format=6,
table-auto-round,
round-mode=places},
c]}
},
hline{2}={wd=0pt},
hline{3}={wd=1pt},
rowhead = 2,
row{1,2}={guard},
row{2} = {
font={\bfseries},
halign={c},
}
}
% empty
& Year 1
& Year 2
& Year 3
& Year 4
& Year 5
& Year 6
& Year 7 \\
Funding category
& \SetCell[c=7]{c} Totals per year
&
&
&
&
&
& \\
\tblrbody
\end{tblr}%
\endgroup%
}
\makeatother
\NewDocumentCommand{\excTable}{om}{%
% #1 value for a specific database
% #2 using the default database of the defined table
\def\tmpLocalDB{#2}%
\IfStrEqCase{#2}{%
{EarlyCareer}{\def\tmpLocalTableCaption{Funding Request for Early-career Support}\excFundingRequestTable}%
{Collaboration}{\def\tmpLocalTableCaption{Funding Request for Collaboration with external partners}\excFundingRequestTable}%
}[\csname exc#2Table\endcsname]
}
\begin{document}
\excEntry{Collaboration}[funding]{
category = {Staff},
fundingYear1 = {4119},
fundingYear2 = {4229},
fundingYear3 = {4339},
fundingYear4 = {4449},
fundingYear5 = {4559},
fundingYear6 = {4669},
fundingYear7 = {4779},
}
\excEntry{Collaboration}[funding]{
category = {{Direct project costs}},
fundingYear1 = {5118},
fundingYear2 = {5228},
fundingYear3 = {5338},
fundingYear4 = {5448},
fundingYear5 = {5558},
fundingYear6 = {5668},
fundingYear7 = {5778},
}
\excEntry{EarlyCareer}[funding]{
category = {{Direct project costs}},
fundingYear1 = {2000},
fundingYear2 = {2000},
fundingYear3 = {2000},
fundingYear4 = {2000},
fundingYear5 = {2000},
fundingYear6 = {2000},
fundingYear7 = {2000},
}
\excEntry{EarlyCareer}[funding]{
category = {Instrumentation},
fundingYear1 = {3000},
fundingYear2 = {3000},
fundingYear3 = {3000},
fundingYear4 = {3000},
fundingYear5 = {3000},
fundingYear6 = {3000},
fundingYear7 = {3000},
}
% tables with correct decimals
\excTable{EarlyCareer}
\excTable{Collaboration}
% table with wrong decimals
\excTable{TotalStructuralMeasures}
% command with correct decimal
correct decimal: \excSumTotalStructuralMeasures
\end{document}
为了更好理解的视觉产品: