如何使用包csvautotabular
的功能制作行间带有水平线的表格csvsimple
?
示例 .csv 文件。
header,
104, 1
312, 0.223
518, 0.198
726, 0.139
932, 0.077
答案1
该\csvautotabular
宏用于快速表格概览。它非常简单,不太适合自定义。
在我的示例代码中,我提供了一个 hack 解决方案my hack
来提供所请求的功能。但对于生产性代码,我宁愿使用带有\csvreader
或 的可自定义解决方案\csvloop
。我还为此添加了几个示例:
\documentclass{article}
\usepackage{csvsimple}
\begin{filecontents*}{example.csv}
header,
104, 1
312, 0.223
518, 0.198
726, 0.139
932, 0.077
\end{filecontents*}
\makeatletter
\csvset{
my hack/.style={
late after line=\\\hline,
late after last line=\csv@tablefoot\end{tabular}\csv@posttable},
}
\makeatother
\begin{document}
Hacked autotabular:\par\smallskip
\csvautotabular[my hack]{example.csv}
\medskip
Better with csvreader and tabular:\par\smallskip
\csvreader[tabular=|l|l|,
table head=\hline header & \\\hline,
late after line=\\\hline]%
{example.csv}{}%
{\csvlinetotablerow}%
\medskip
Alternatively:\par\smallskip
\csvreader[tabular=|l|l|,
no head,
table head=\hline,
late after line=\\\hline]%
{example.csv}{}%
{\csvcoli & \csvcolii}%
\medskip
Alternatively:\par\smallskip
\csvreader[tabular=|l|l|,
no head,column count=2,
table head=\hline,
late after line=\\\hline]%
{example.csv}{}%
{\csvlinetotablerow}%
\medskip
Alternatively:\par\smallskip
\csvloop{
file=example.csv,
no head,column count=2,
tabular=|l|l|,
table head=\hline,
command=\csvlinetotablerow,
late after line=\\\hline
}
\end{document}