我想在电子表格中导入 products.tex。products.tex 的内容是
@ Plant & 1 & 60 & 2 & 77 \\
@ Book & 2 & 90 & 4 & 64 \\
@ Other & 3 & 100 & 10 & 6 \\
我想将其导入下表
\begin{document}
\begin{spreadtab}{{tabular}{lcc}}
\toprule
@ Product name & @ Number & @ Price & @ Count & Count2 \\
\midrule
\input{products}
\midrule
@ Total & &:={sumprod(b2:[0,-1];c2:[1,-1])} & sum(c2:[0,-1])& sum(d2:[0,-1])\\
\bottomrule
\end{spreadtab}
\end{document}
我不知道如何实现它。非常感谢你的帮助
答案1
尝试此代码。基于在 Spreadtab 环境中使用输入
\documentclass{article}
\usepackage{spreadtab,booktabs,xpatch}
% From https://tex.stackexchange.com/a/207313/161015 **************************
\makeatletter
\def\spreadtab@ii{\IfSubStr\ST@tab{\noexpand\input}{\expandafter\spreadtab@iii\ST@tab\@nil}\relax}
\def\spreadtab@iii#1\input#2#3\@nil{%
\long\def\spreadtab@iv##1\spreadtab@iv{\endgroup\def\ST@tab{#1##1#3}\spreadtab@ii}%
\begingroup
\everyeof{\spreadtab@iv\noexpand}%
\expandafter\spreadtab@iv\@@input#2
}
\xpretocmd\spreadtab@i\spreadtab@ii{}{}
\makeatother
%**************************************************
\begin{document}
\begin{spreadtab}{{tabular}{lcccc}}
\toprule
%% col a & col b & col c & col d & col e <<<<<<<<<<<<<<<<
@ Product name & @ Number & @ Price & @ Count & @ Count2 \\
\midrule
\input{products}
\midrule
@ Total & &:={sumprod(b2:b4;c2:c4)} & sum(d2:d4)& sum(e2:e4)\\
\bottomrule
\end{spreadtab}
\end{document}
文件products.tex
%% File products.tex
@ Plant & 1 & 60 & 2 & 77 \\ % row 2
@ Book & 2 & 90 & 4 & 64 \\ % row 3
@ Other & 3 & 100 & 10 & 6 \\ % row 4