我想从新命令 \csvautotabularcenter{2.csv} 传递表格参数|p{5cm}| p{1.5cm}| p{8cm}|,因为它会随着基于输入文件的列数变化而变化。我知道您可以添加第三个参数,但由于某种原因它不起作用。任何帮助都值得赞赏。
\begin{filecontents*}{2.csv}
name,type,random
sample 1,type 1,"some really long text"
sample 2,type 2,"another long text"
sample 3,type 3,"unbelivelably long text"
sample 4,type 4,"just random text"
sample 5,type 5,"the end"
\end{filecontents*}
\usepackage{csvsimple}
\begin{document}
\makeatletter
\csvset{
autotabularcenter/.style={
file=#1,
after head=\csv@pretable\begin{tabular}{|p{5cm}| p{1.5cm}| p{8cm}|}\csv@tablehead, %want to input |p{5cm}| p{1.5cm}| p{8cm}| from \csvautotabularcenter{2.csv}
table head=\hline\csvlinetotablerow\\\hline,
late after line=\\,
table foot=\\\hline,
late after last line=\csv@tablefoot\end{tabular}\csv@posttable,
command=\csvlinetotablerow},
}
\makeatother
\newcommand{\csvautotabularcenter}[2][respect underscore=true]{\csvloop{autotabularcenter={#2},#1}}
\csvautotabularcenter{2.csv}
\end{document}