一个简单的例子:
\documentclass[12pt]{article}
\usepackage{csvsimple}
\begin{document}
\begin{tabular}{|c|c|}
\csvreader[separator=pipe,head to column names]{test.csv}{}{\foo&\bar\\}
\end{tabular}
\end{document}
文件test.csv
:
foo|bar|baz|
foo|bar|baz|
它应该是一但前两个垂直线比表格长。
编辑
Ruixi 的答案在以下情况下不起作用。文件adatok.csv
:
vara|varb|varc|vard|vare|
foo|bar|baz|foox|fooy|
foo2|bar2|baz2|foofoo|bazbar|
LaTeX 文件:
\documentclass[landscape,12pt]{article}
\usepackage{csvsimple}
\begin{document}
\begin{tabular}{|l|c|c|c|c|}
\csvreader[separator=pipe,head to column names]{adatok.csv}{}{\vara&\varb&\varc&\vard&\vare}
\end{tabular}
\end{document}
答案1
我认为我没有完全理解你的问题。但删除似乎 \\
可以解决你的问题:
\documentclass[12pt]{article}
\usepackage{tcolorbox}
\usepackage{csvsimple}
\begin{document}
\begin{tcbverbatimwrite}{test.csv}
foo|bar|baz|
foo|bar|baz|
\end{tcbverbatimwrite}
\begin{tabular}{|c|c|}
\csvreader[separator=pipe,head to column names]{test.csv}{}{\foo&\bar}
\end{tabular}
\end{document}
添加:使用您的新示例:
\documentclass[12pt]{article}
\usepackage{tcolorbox}
\usepackage{csvsimple}
\begin{document}
\begin{tcbverbatimwrite}{test.csv}
vara|varb|varc|vard|vare|
foo|bar|baz|foox|fooy|
foo2|bar2|baz2|foofoo|bazbar|
\end{tcbverbatimwrite}
\begin{tabular}{|l|c|c|c|c|}
\hline
\csvreader[separator=pipe,late after line=\\\hline,head to column names]{test.csv}{}{\vara&\varb&\varc&\vard&\vare}
\end{tabular}
\end{document}