0

A simple example:

\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}

The test.csv file:

foo|bar|baz|
foo|bar|baz|

It should be one line but the first two vertical rules are longer than the table.

What's wrong? How can I fix it? result

EDIT Ruixi's answer doesn't work the following case. The adatok.csv file:

vara|varb|varc|vard|vare|
foo|bar|baz|foox|fooy|
foo2|bar2|baz2|foofoo|bazbar|

The LaTeX-file:

\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}
3

I don’t think I fully understand your question. But removing the \\ seems to solve your problem:

\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}

foo and bar


Added: With your new example:

\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}

new example

  • It seems in this simple case it works well. But I don't understand in my a little complicated case why not: without \\ causes error. – uzsolt Sep 3 '18 at 16:21
  • Could you please check my edit? Why doesn't work? – uzsolt Sep 3 '18 at 16:38
  • Your solution doesn't work too when you add a new line into (virtual) CSV file (for example copy the latest one). – uzsolt Sep 3 '18 at 16:44
  • 1
    @uzsolt Answer updated. :) – Ruixi Zhang Sep 3 '18 at 20:43
  • 1
    @uzsolt Using late after line={\\[1cm]\hline} should work. The curly braces are needed to secure the option setting. – Thomas F. Sturm Sep 11 '18 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.