I have created a table using data from a csv, such that multicolumn rows are automatically detected in the csv.
In order to do this, I placed all the \\
before each line rather than after, otherwise a multicolumn in an ifthenelse did not work (see csvsimple misplaced \omit. \multispan when using multicolumn for entire row)
However, I do not know now how to place a thick line between the column names and the rest of the table.
This is what I have:
\documentclass[11pt]{article}
\usepackage{csvsimple}
\begin{filecontents}[overwrite]{data-mwe.csv}
a,b
c,d
text,
e,f
\end{filecontents}
\begin{document}
\begin{tabular}{|l|l|}
\hline
column 1 & column 2
\csvreader[no head]{data-mwe.csv}{}{%
\ifthenelse{\equal{\csvcolii}{}}{
\\ \hline \multicolumn{2}{|c|}{\csvcoli}
}{%
\\ \hline \csvcoli & \csvcolii
}
}
\\ \hline
\end{tabular}
\end{document}
In the spirit of Tabularx, csvsimple and multicol on first row lead to \omit error, this is almost what I want (thick line emulated by double hline), except it has of course way to much space after the header line:
Adding \\ \hline \hline \multicolumn{1}{c}{}
after the header row results in
I wanted to use \csviffirstrow
from the csvsimple docs (page 12), but when I replace {\\ \hline \csvcoli & \csvcolii}
with {\\ \csviffirstrow{\hline\hline}{\hline} \csvcoli & \csvcolii}
this gives me
Unfortunately it is not the case that the first data row is always the same, otherwise I could of course simply have hardcoded that row and put the \toprule above it.
Answers suggesting completely different solutions (perhaps LuaTeX?) are of course also valid, if they are for LaTeX and can determine multicolumn/no multicolumn from the csv (so not hardcoded in the LaTeX file). csv format is not fixed, I can change that.