1

I try to format a CSV file as a table and ran into the issue that the csvsimple package repeats the head elements after a % sign appears in the file. Consider the following MWE (strongly reduced from my original classicthesis file):

\documentclass[paper=a4]{scrreprt}

\RequirePackage{tabularx}
\usepackage{filecontents}

\RequirePackage{csvsimple}

\csvset{every csv/.style={
  separator=semicolon,
  respect percent
}}

\begin{filecontents*}[overwrite]{Courses.csv}
A;B;C;D;E;F;G;Portion;H;I
a;b;c;d;e;f;g;100%;1,00;3,00
a;b;c;d;e;f;g;100%;2,00;4,00
\end{filecontents*}

\begin{document}

\begin{table}[h]
  \centering
  \begin{tabularx}{\textwidth}{XXXXXXXXXX}
    \csvreader[no head, late after line=\\]{Courses.csv}{}{\csvlinetotablerow}\\
  \end{tabularx}
\end{table}

\end{document}

The output looks like this: enter image description here

Note that the % signs are missing in the first and second data row (second and third row of the table) and that the last two columns are filled with the column headings instead of the content. I verified that csvsimple is configured to respect % signs (see package options) and that the output of filecontents is actually correct. (Note: Even respect all does not change this behavior)

Oddly, if I remove the no head flag, csvsimple prints the first table row correctly, but skips all remaining rows. Even if I add 100 additional rows, only 1 is printed:

enter image description here

I am a bit lost on what else to try. How can I can configure/convince csvsimple to print all rows correctly in my table?

2
+50

cvssimple sets the catcode of the percent char locally, and in a tabular, where cells build groups, it gets lost again. Change it before the tabularx:

\documentclass[paper=a4]{scrreprt}

\RequirePackage{tabularx}
\usepackage{filecontents}

\RequirePackage{csvsimple}

\csvset{every csv/.style={
  separator=semicolon,
  respect percent
}}

\begin{filecontents*}[overwrite]{Courses.csv}
A;B;C;D;E;F;G;Portion;H;I
a;b;c;d;e;f;g;100%;1,00;3,00
a;b;c;d;e;f;g;100%;2,00;4,00
\end{filecontents*}


\begin{document}

\begin{table}[h]
  \centering
  \catcode`\%=12
  \begin{tabularx}{\textwidth}{XXXXXXXXXX}
    \csvreader[no head, late after line=\\]{Courses.csv}{}{\csvlinetotablerow}\\
  \end{tabularx}
\end{table}

\end{document}

enter image description here

1
  • Works perfectly, thanks. I will award the bounty once it is possible to do so. – Andreas Unterweger Apr 12 at 14:41

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.