1

What is wrong with:

\documentclass[12pt]{article}

\usepackage{fontspec}
\usepackage[american]{babel}
\usepackage{libertine}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{csvsimple}
\usepackage{filecontents}
\usepackage{silence}
\WarningFilter{latex}{Overwriting file}

\begin{filecontents*}{test.csv}
HH,GG
X1,Y1
X2,Y2
X3,Y3
X4,Y4
\end{filecontents*}

\begin{document}

\csvreader[tabular={ll}, no head, late after head=\\\rowcolor{yellow},
late after line=\csvifoddrow{\\\rowcolor{yellow}}{\\}] {test.csv}{}%
{\csvcoli & \csvcolii}%

\bigskip

\begin{tabular}{lll}
header & header & header \\
test   & test   & test   \\
test   & test   & test   \\
test   & test   & test  
\end{tabular}

\end{document}

That it gives me:

enter image description here

2

You didn't nothing wrong. You only used the package example, I think that the culprit is the package since this function should be used with other options. I'll try to explain myself. In your example, you put some options after the row ends. I don't know why, but if you put an option after the last line of a table, this option affect the first line of the next table. Obviously putting an option after the last line of a table is wrong, but I don't know why it affects the first line of the following table.

In fact, if you ad another line of data, you don't have this problem anymore.

\documentclass[12pt]{article}

\usepackage{fontspec}
\usepackage[american]{babel}
\usepackage{libertine}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{csvsimple}
\usepackage{filecontents}
\usepackage{silence}
\WarningFilter{latex}{Overwriting file}

\begin{filecontents*}{test.csv}
HH,GG
X1,Y1
X2,Y2
X3,Y3
X4,Y4
X5,Y5
\end{filecontents*}

\begin{document}

\csvreader[tabular={ll}, no head, late after head=\\\rowcolor{yellow},
late after line=\csvifoddrow{\\\rowcolor{yellow}}{\\}] {test.csv}{}%
{\csvcoli & \csvcolii}%

\bigskip

\begin{tabular}{lll}
header & header & header \\
test   & test   & test   \\
test   & test   & test   \\
test   & test   & test  
\end{tabular}

\end{document}

example_with_one_more_line_of_data

To avoid this fact I propose to you another approach based on the oddity of the lines.

\documentclass[12pt]{article}

\usepackage{fontspec}
\usepackage[american]{babel}
\usepackage{libertine}
\usepackage[table]{xcolor}% Add option table
\usepackage{colortbl}
\usepackage{csvsimple}
\usepackage{filecontents}
\usepackage{silence}
\WarningFilter{latex}{Overwriting file}

\begin{filecontents*}{test.csv}
HH,GG
X1,Y1
X2,Y2
X3,Y3
X4,Y4
\end{filecontents*}

\begin{document}

\csvreader[tabular={ll}, no head] {test.csv}{}%
{\csvifoddrow%
  {\cellcolor{yellow}\csvcoli&\cellcolor{yellow}\csvcolii}%
  {\csvcoli&\csvcolii}%
}

\bigskip

\begin{tabular}{lll}
header & header & header \\
test   & test   & test   \\
test   & test   & test   \\
test   & test   & test  
\end{tabular}
\end{document}

result

Note that I loaded xcolor with the option table to color the cell.

  • Thank you for the solution. I am a csvsimple newbie. Could I come up with your solution just by scanning the package tutorial? Further, loading xcolor without the table option also works. What benefit does it provide (at least, in this case)? – blackened May 14 '18 at 9:57
  • My example is just the one before yours in the package distribution. The only difference is that that one is about bold fonts. Loading the package xcolor with table gives you the possibility to use \cellcolor. I don't know if there is any command in csvsimple that perform the same task, this is the first time that I see csvsimple package. :) – gvgramazio May 14 '18 at 10:11

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.