\documentclass[12pt]{article}
\usepackage{csvsimple,filecontents}
\usepackage{fontspec}
\usepackage[american]{babel}
\usepackage{libertine}
\begin{filecontents*}{test.csv}
H1, H2
X1, Y1
X2, Y2
X3, Y3
X4, Y4
\end{filecontents*}
\begin{document}
\csvautotabular{test.csv}
\end{document}
假设我想节省空间。有没有办法自定义输出,使其像下面的例子一样?
X1 Y1 X2 Y2
X3 Y3 X4 Y4
答案1
输出可以组织为tabular
两条输入线作为一条输出线。\csvifoddrow
宏允许插入适当的代码:
\documentclass[12pt]{article}
\usepackage{csvsimple,filecontents}
\usepackage[american]{babel}
\usepackage{libertine}
\usepackage{array}
\begin{filecontents*}{test.csv}
H1, H2
X1, Y1
X2, Y2
X3, Y3
X4, Y4
\end{filecontents*}
\begin{document}
\csvreader[
column names={H1=\one,H2=\two},
tabular=ll@{\qquad}ll,
table head=H1 & H2 & H1 & H2\\\hline,
late after line=\csvifoddrow{\\}{&},
late after last line=\\\hline,
]%
{test.csv}{}%
{\one & \two}%
\end{document}
输出为: