我的 CSV 中的标题列名称包含空格。有没有办法继续使用csvsimple
或其他包来导入它?这样我就可以在 CSV 中指定数据,导入它并将其自动呈现为桌子通过一个包。另外,由于标题很长,我希望表格能够扩展到页面宽度并包裹长标题。
\begin{filecontents*}{forum_posts_table_1.csv}
posts per author,sentences per post,quoted sentences per post,EREs per post,mentions per ERE
3.1,23.83454,2313.27,13453453.8,2464642.43
\end{filecontents*}
答案1
正如我在评论中所写的,一切都取决于如何使用数据。csvsimple
只要您不使用创建自动宏,标题内的空格就没有问题head to column names
。
示例用法如下:
\documentclass{article}
\usepackage{csvsimple,array,filecontents,booktabs}
\begin{filecontents*}{forum_posts_table_1.csv}
posts per author,sentences per post,quoted sentences per post,EREs per post,mentions per ERE
3.1,23.83454,2313.27,13453453.8,2464642.43
4.1,23.83454,2313.27,13453453.8,2464642.43
5.1,23.83454,2313.27,13453453.8,2464642.43
\end{filecontents*}
\begin{document}
\newcommand\myhead[1]{\parbox[t]{5em}{\centering\bfseries#1\par\kern1mm}}
\csvreader[no head,column count=5,tabular=rrrrr,
table head=\toprule,
late after first line=\\\midrule,
table foot=\bottomrule
]%
{forum_posts_table_1.csv}{}{%
\csviffirstrow{\myhead{\csvcoli} & \myhead{\csvcolii} & \myhead{\csvcoliii}
& \myhead{\csvcoliv} & \myhead{\csvcolv}
}{\csvlinetotablerow}
}
\end{document}