我正在使用 \csvreader 打印表格。但是,其中一个字段包含很多逗号
\begin{filecontents*}{sairis7.csv}
weights, accuracy, duration
[0.3837762, 0.3441996, 0.6423321, 0.480776], 00:03:55.18, 95.9106552963
[0.7841548, 0.5516101, 0.3033666, 0.1603187], 00:03:53.79, 92.6795811851
[0.3249006, 0.4728797, 0.3725799, 0.996232], 00:04:19.29, 95.2666745935
[0.1699597, 0.5566617, 0.9622979, 0.051388], 00:04:50.01, 95.8973879383
[0.4532285, 0.3019645, 0.6935862, 0.8012383], 00:04:33.44, 95.4078896272
[0.1580461, 0.4561823, 0.613519, 0.0955829], 00:05:09.47, 95.6631033785
[0.5424764, 0.621894, 0.7174977, 0.5827319], 00:04:27.20, 95.8742075138
[0.3560077, 0.346697, 0.6691461, 0.9715148], 00:04:04.99, 95.6211843553
[0.4464995, 0.95631, 0.5825031, 0.4944645], 00:04:11.69, 95.6329624721
[0.9851933, 0.4518537, 0.5542809, 0.9837232], 00:04:23.49, 95.1412451035
\end{filecontents*}
当我用 tex 调用时
\begin{table}
\caption{SA-WKNN for the Iris Dataset}
\csvreader[longtable=lllllc,
table head= Weights & Accuracy & Duration (in hr:min:sec)\\\hline,
late after line=\\\hline]%
{sairis7.csv}{weights = \w, accuracy = \a, duration = \d}%
{\w & \a & \d }%
\label{tab:label}
\end{table}
它什么也没打印
我怎样才能让它跳过重量字段中的逗号,以便打印重量列?
答案1
您当然是对的,csvsimple
将 解释,
为列分隔符。如果可以更改您的 csv 文件,此解决方案应该有效。
您可以为列分隔符指定不同的符号,这在文档的cvsimple
第3.6 分隔符:
/csv/separator=⟨sign⟩
设置⟨sign⟩,将其视为数据行数据值之间的分隔符。
请注意,您始终可以通过命令行/终端输入 来查找文档texdoc csvsimple
,这适用于任何软件包。该文档也可在以下位置找到:http://ctan.org/pkg/csvsimple
输出
代码
\documentclass[11pt]{article}
\usepackage{filecontents}
\begin{filecontents*}{sairis7.csv}
weights;accuracy; duration
[0.3837762, 0.3441996, 0.6423321, 0.480776]; 00:03:55.18; 95.9106552963
[0.7841548, 0.5516101, 0.3033666, 0.1603187]; 00:03:53.79; 92.6795811851
[0.3249006, 0.4728797, 0.3725799, 0.996232]; 00:04:19.29; 95.2666745935
[0.1699597, 0.5566617, 0.9622979, 0.051388]; 00:04:50.01; 95.8973879383
[0.4532285, 0.3019645, 0.6935862, 0.8012383]; 00:04:33.44; 95.4078896272
[0.1580461, 0.4561823, 0.613519, 0.0955829]; 00:05:09.47; 95.6631033785
[0.5424764, 0.621894, 0.7174977, 0.5827319]; 00:04:27.20; 95.8742075138
[0.3560077, 0.346697, 0.6691461, 0.9715148]; 00:04:04.99; 95.6211843553
[0.4464995, 0.95631, 0.5825031, 0.4944645], 00:04:11.69; 95.6329624721
[0.9851933, 0.4518537, 0.5542809, 0.9837232]; 00:04:23.49; 95.1412451035
\end{filecontents*}
\usepackage{csvsimple}
\usepackage{longtable}
\begin{document}
\begin{table}
\caption{SA-WKNN for the Iris Dataset}
\csvreader[longtable=lllllc,
separator=semicolon,
table head= Weights & Accuracy & Duration (in hr:min:sec)\\\hline,
late after line=\\\hline]%
{sairis7.csv}{weights = \w, accuracy = \a, duration = \d}%
{\w & \a & \d }%
\label{tab:label}
\end{table}
\end{document}