我无法将不同信息从表格转移到其他表格

我无法将不同信息从表格转移到其他表格

我使用此代码,并且想要在一个表中收集不同表中的信息。因此,我将标签放在不同的表中,并在最后一个表中使用 \STtag,但出现此错误:Package spreadtab 错误:标签“BN”未知,您定义过吗?。\STtag{BN}

\documentclass{article}
\usepackage[a4paper,left=2.5cm,right=2.5cm,bottom=2.8cm,top=2.8cm]{geometry} 
\usepackage{longtable,tabu}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{datetime}

\usepackage{siunitx}
\usepackage{multirow}
\usepackage[sc]{mathpazo}
\usepackage{datatool}
\usepackage{spreadtab,booktabs,xpatch}
\usepackage[]{numprint}
\usepackage[]{eurosym}
\usepackage{fp}
\usepackage{booktabs}
\usepackage{tabularx,siunitx}
\usepackage{numprint}


% HACK % HACK % HACK % HACK % HACK % HACK % HACK % HACK % HACK % HACK %
\usepackage{xparse}
\ExplSyntaxOn
\tl_new:N \l__ihpro_spreadtab_hack_tl
\tl_new:N \l__ihpro_tmpa_tl
\NewDocumentEnvironment { spreadtabwithinput } { +b }
  {
    \tl_clear:N \l__ihpro_spreadtab_hack_tl
    \__ihpro_spreadtab_loop:w \prg_do_nothing: #1
      \input \q_recursion_tail \q_recursion_stop
    \exp_last_unbraced:Nno
    \begin{spreadtab}
      \l__ihpro_spreadtab_hack_tl
    \end{spreadtab}
  } { }
\cs_new_protected:Npn \__ihpro_spreadtab_loop:w #1 \input #2
  {
    \quark_if_recursion_tail_stop:n {#2}
    \tl_put_right:No \l__ihpro_spreadtab_hack_tl {#1}
    \file_get:nnNF {#2} { } \l__ihpro_tmpa_tl
      {
        \msg_error:nnn { ihpro } { file-not-found } {#2}
        \tl_clear:N \l__ihpro_tmpa_tl
      }
    \exp_last_unbraced:NNo
    \__ihpro_spreadtab_loop:w \prg_do_nothing: \l__ihpro_tmpa_tl
  }
\msg_new:nnn { ihpro } { file-not-found } { File~'#1'~not~found. }
\ExplSyntaxOff
% HACK % HACK % HACK % HACK % HACK % HACK % HACK % HACK % HACK % HACK %


\newcounter{foo}
\newcounter{fo}
\newcounter{B}
\newcounter{P}
\newcounter{H}
\newcounter{T}
\newcounter{S}
\newcounter{Z}


\nprounddigits{2}
\npthousandsep{,}
\npdecimalsign{.}

\renewcommand\STprintnum[1]{\numprint{#1}}
\npthousandsep{,}

\setlength{\tabcolsep}{17pt}

\begin{document}
\subsection*{B}
    \begin{spreadtabwithinput}{{tabular}{@{\hskip1pt}r@{\hskip7pt}p{2.7cm}crrr}}
    \toprule
    &@ Ku& @ Re & @ Ne & @ Me & @ Br \\
        \midrule
        \input{Bu1.txt}
        \input{Bu2.txt}
        \input{Bu3.txt}
        \input{Bu4.txt}
        \input{Bu5.txt}
        \input{Bu6.txt}
        \input{Bu7.txt}
        \input{Bu8.txt}
        \input{Bu9.txt}
        \input{Bu10.txt}
        \input{Bu11.txt}
        \input{Bu12.txt}
        \input{Bu13.txt}
        \input{Bu14.txt}
        \input{Bu15.txt}
        \midrule
        &@ To & @\thefo &(sum(d2:[0,-1]))tag(BN) & sum(e2:[0,-1])tag(BM)& sum(f2:[0,-1])tag(BB)\\
        \bottomrule
    \end{spreadtabwithinput}
\setcounter{B}{\thefo}
\setcounter{fo}{0}

\subsection*{P}
    \begin{spreadtabwithinput}{{tabular}{@{\hskip1pt}r@{\hskip7pt}p{2.7cm}crrr}}
    \toprule
    &@ Ku& @ Re & @ Ne & @ Me & @ Br \\
        \midrule
        \input{Pu1.txt}
        \input{Pu2.txt}
        \input{Pu3.txt}
        \input{Pu4.txt}
        \input{Pu5.txt}
        \midrule
        &@ To & @\thefo &(sum(d2:[0,-1]))tag(PN) & sum(e2:[0,-1])tag(PM)& sum(f2:[0,-1])tag(PB)\\
        \bottomrule
    \end{spreadtabwithinput}
\setcounter{P}{\thefo}
\setcounter{fo}{0}

\subsection*{P}
    \begin{spreadtabwithinput}{{tabular}{@{\hskip1pt}r@{\hskip7pt}p{2.7cm}crrr}}
    \toprule
    &@ Ku& @ Re & @ Ne & @ Me & @ Br \\
        \midrule
        \input{Hu1.txt}
        \input{Hu2.txt}
        \input{Hu3.txt}
        \input{Hu4.txt}
        \input{Hu5.txt}
        \input{Hu6.txt}
        \input{Hu7.txt}
        \midrule
        &@ To & @\thefo &(sum(d2:[0,-1]))tag(HN) & sum(e2:[0,-1])tag(HM)& sum(f2:[0,-1])tag(HB)\\
        \bottomrule
    \end{spreadtabwithinput}

\setcounter{H}{\thefo}
\setcounter{fo}{0}

\newcommand\BN{\STtag{BN}}
\newcommand\BM{\STtag{BM}}
\newcommand\BB{\STtag{BB}}
\newcommand\PN{\STtag{PN}}
\newcommand\PM{\STtag{PM}}
\newcommand\PB{\STtag{PB}}
\newcommand\HN{\STtag{HN}}
\newcommand\HM{\STtag{HM}}
\newcommand\HB{\STtag{HB}}
\newcommand\TN{\STtag{TN}}
\newcommand\TM{\STtag{TM}}
\newcommand\TB{\STtag{TB}}
\newcommand\SN{\STtag{SN}}
\newcommand\SM{\STtag{SM}}
\newcommand\SB{\STtag{SB}}
\newcommand\ZN{\STtag{ZN}}
\newcommand\ZM{\STtag{ZM}}
\newcommand\ZB{\STtag{ZB}}

    \subsection*{Ge}
    \setlength{\tabcolsep}{14.3pt}
    \begin{spreadtab}{{tabular}{@{\hskip23pt}p{2.7cm}rrrr@{\hskip25pt}r@{\hskip7pt}}}
    \toprule
@ Ku & @ Pr & @ Ne & @ Me & @ Br& @An\\
    \midrule
@ B & & \BN & \BM & \BB& @\theB\\
@ P &  & \PN & \PM & \PB& @\theP\\
@ H &  & \HN & \HM & \HB& @\theH\\
    \midrule
    \SThiderow @ Total & &sum(c2:[0,-1]) & sum(d2:[0,-1])& sum(e2:[0,-1])@\thefoo \\
    \bottomrule
\end{spreadtab}

\end{document}

*.txt 的内容例如

@ \stepcounter{foo} \stepcounter{fo} \thefoo&@BU1& @5& 650.00& 123.50& 773.50\\

答案1

软件包 spreadtab 的手册说,如果 -environment本身嵌套在另一个范围/另一个环境中,则需要在 -environment\STmakegtag{<tag>}之外使用以使标签全局可用。因此必须在该其他环境/范围内使用。spreadtabspreadtab\STmakegtag{<tag>}

使用您示例中展示的代码,spreadtab-environment 在 -environment 范围内使用spreadtabwithinput。因此,必须在spreadtab-environment 之后但仍在spreadtabwithinput-environment内\STmakegtag{<tag>}应用。

\afterspreadtab我已在您的示例中展示的代码中添加了为您执行该操作的命令。

该命令不能用作表格单元格中电子表格公式的一部分。
因此,如果您在表格单元格中使用它,则需要使用
:={<formula>}\afterspreadtab{...}
或类似命令以确保它不会被用作公式的组成部分。
...:={<formula>}... 在电子表格软件包手册中提到。

\documentclass{article}
\usepackage[a4paper,left=2.5cm,right=2.5cm,bottom=2.8cm,top=2.8cm]{geometry} 
\usepackage{longtable,tabu}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{datetime}

\usepackage{siunitx}
\usepackage{multirow}
\usepackage[sc]{mathpazo}
\usepackage{datatool}
\usepackage{spreadtab,booktabs,xpatch}
\usepackage[]{numprint}
\usepackage[]{eurosym}
\usepackage{fp}
% Seems to be a second attempt at loading booktabs:
\usepackage{booktabs}
\usepackage{tabularx,siunitx}
\usepackage{numprint}


%% This creates text files:
% \newwrite\wrt
% \def\exchange#1#2{#2#1}%
% \def\x#1;#2#3{\immediate\openout\wrt"#3#1.txt"
%   \immediate\write\wrt{@ \string\stepcounter{foo} \string\stepcounter{fo} \string\thefoo&@#3#1& @5& 650.00& 123.50& 773.50\string\\}%
%   \immediate\closeout\wrt
%   \ifnum#1<#2 \exchange{\expandafter\x\number\numexpr#1+1;{#2}{#3}}\fi}
% \x1;{15}{Bu}%
% \x1;{5}{Pu}%
% \x1;{7}{Hu}%
%%


% HACK % HACK % HACK % HACK % HACK % HACK % HACK % HACK % HACK % HACK %
\usepackage{xparse}
\ExplSyntaxOn
\tl_new:N \l__ihpro_spreadtab_hack_tl
\tl_new:N \l__ihpro_tmpa_tl
\tl_new:N \l__ihpro_afterspreadtab_tl
\NewDocumentCommand \afterspreadtab {m} {\tl_gput_right:Nn \l__ihpro_afterspreadtab_tl {#1}}
\NewDocumentEnvironment { spreadtabwithinput } { +b }
  {
    \tl_clear:N \l__ihpro_spreadtab_hack_tl
    \tl_gclear:N \l__ihpro_afterspreadtab_tl
    \__ihpro_spreadtab_loop:w \prg_do_nothing: #1
      \input \q_recursion_tail \q_recursion_stop
      \exp_last_unbraced:Nno
      \begin{spreadtab}
        \l__ihpro_spreadtab_hack_tl
      \end{spreadtab}
      \l__ihpro_afterspreadtab_tl
  } { }
\cs_new_protected:Npn \__ihpro_spreadtab_loop:w #1 \input #2
  {
    \tl_put_right:No \l__ihpro_spreadtab_hack_tl {#1}
    \quark_if_recursion_tail_stop:n {#2}
    \file_get:nnNF {#2} { } \l__ihpro_tmpa_tl
      {
        \msg_error:nnn { ihpro } { file-not-found } {#2}
        \tl_clear:N \l__ihpro_tmpa_tl
      }
    \exp_last_unbraced:NNo
    \__ihpro_spreadtab_loop:w \prg_do_nothing: \l__ihpro_tmpa_tl
  }
\msg_new:nnn { ihpro } { file-not-found } { File~'#1'~not~found. }
\ExplSyntaxOff
% HACK % HACK % HACK % HACK % HACK % HACK % HACK % HACK % HACK % HACK %


\newcounter{foo}
\newcounter{fo}
\newcounter{B}
\newcounter{P}
\newcounter{H}
\newcounter{T}
\newcounter{S}
\newcounter{Z}


\nprounddigits{2}
\npthousandsep{,}
\npdecimalsign{.}

\renewcommand\STprintnum[1]{\numprint{#1}}
\npthousandsep{,}

\setlength{\tabcolsep}{17pt}

\begin{document}
\null\kern-2cm
\subsection*{B}
    \begin{spreadtabwithinput}{{tabular}{@{\hskip1pt}r@{\hskip7pt}p{2.7cm}crrr}}
    \toprule
    &@ Ku& @ Re & @ Ne & @ Me & @ Br \\
        \midrule
        \input{Bu1.txt}
        \input{Bu2.txt}
        \input{Bu3.txt}
        \input{Bu4.txt}
        \input{Bu5.txt}
        \input{Bu6.txt}
        \input{Bu7.txt}
        \input{Bu8.txt}
        \input{Bu9.txt}
        \input{Bu10.txt}
        \input{Bu11.txt}
        \input{Bu12.txt}
        \input{Bu13.txt}
        \input{Bu14.txt}
        \input{Bu15.txt}
        \midrule
        &@ To & @\thefo &(sum(d2:[0,-1]))tag(BN) & sum(e2:[0,-1])tag(BM)& sum(f2:[0,-1])tag(BB)\\
        \bottomrule
        :={}\afterspreadtab{\STmakegtag{BN}\STmakegtag{BM}\STmakegtag{BB}}%
    \end{spreadtabwithinput}
\setcounter{B}{\thefo}
\setcounter{fo}{0}

BN: \STtag{BN}
BM: \STtag{BM}
BB: \STtag{BB}

\subsection*{P}
    \begin{spreadtabwithinput}{{tabular}{@{\hskip1pt}r@{\hskip7pt}p{2.7cm}crrr}}
    \toprule
    &@ Ku& @ Re & @ Ne & @ Me & @ Br \\
        \midrule
        \input{Pu1.txt}
        \input{Pu2.txt}
        \input{Pu3.txt}
        \input{Pu4.txt}
        \input{Pu5.txt}
        \midrule
        &@ To & @\thefo &(sum(d2:[0,-1]))tag(PN) & sum(e2:[0,-1])tag(PM)& sum(f2:[0,-1])tag(PB)\\
        \bottomrule
        :={}\afterspreadtab{\STmakegtag{PN}\STmakegtag{PM}\STmakegtag{PB}}%
    \end{spreadtabwithinput}
\setcounter{P}{\thefo}
\setcounter{fo}{0}

PN: \STtag{PN}
PM: \STtag{PM}
PB: \STtag{PB}


% This should probably be \subsection*{H}
\subsection*{P}
    \begin{spreadtabwithinput}{{tabular}{@{\hskip1pt}r@{\hskip7pt}p{2.7cm}crrr}}
    \toprule
    &@ Ku& @ Re & @ Ne & @ Me & @ Br \\
        \midrule
        \input{Hu1.txt}
        \input{Hu2.txt}
        \input{Hu3.txt}
        \input{Hu4.txt}
        \input{Hu5.txt}
        \input{Hu6.txt}
        \input{Hu7.txt}
        \midrule
        &@ To & @\thefo &(sum(d2:[0,-1]))tag(HN) & sum(e2:[0,-1])tag(HM)& sum(f2:[0,-1])tag(HB)\\
        \bottomrule
        :={}\afterspreadtab{\STmakegtag{HN}\STmakegtag{HM}\STmakegtag{HB}}%
    \end{spreadtabwithinput}

\setcounter{H}{\thefo}
\setcounter{fo}{0}

HN: \STtag{HN}
HM: \STtag{HM}
HB: \STtag{HB}

\newcommand\BN{\STtag{BN}}
\newcommand\BM{\STtag{BM}}
\newcommand\BB{\STtag{BB}}
\newcommand\PN{\STtag{PN}}
\newcommand\PM{\STtag{PM}}
\newcommand\PB{\STtag{PB}}
\newcommand\HN{\STtag{HN}}
\newcommand\HM{\STtag{HM}}
\newcommand\HB{\STtag{HB}}
\newcommand\TN{\STtag{TN}}
\newcommand\TM{\STtag{TM}}
\newcommand\TB{\STtag{TB}}
\newcommand\SN{\STtag{SN}}
\newcommand\SM{\STtag{SM}}
\newcommand\SB{\STtag{SB}}
\newcommand\ZN{\STtag{ZN}}
\newcommand\ZM{\STtag{ZM}}
\newcommand\ZB{\STtag{ZB}}

\subsection*{Ge}
\setlength{\tabcolsep}{14.3pt}

\begin{spreadtab}{{tabular}{@{\hskip23pt}p{2.7cm}rrrr@{\hskip25pt}r@{\hskip7pt}}}
\toprule
@ Ku & @ Pr & @ Ne & @ Me & @ Br& @An\\
\midrule
@ B & & \BN & \BM & \BB& @\theB\\
@ P &  & \PN & \PM & \PB& @\theP\\
@ H &  & \HN & \HM & \HB& @\theH\\
\midrule
\SThiderow @ Total & &sum(c2:[0,-1]) & sum(d2:[0,-1])& sum(e2:[0,-1])@\thefoo \\
\bottomrule
\end{spreadtab}

\end{document}

在此处输入图片描述

相关内容