Adding a toprule below the header of a table read from csv where some rows are multicolumn
The environment {NiceTabular}
of nicematrix
gives you tools to draw rules with Tikz after the construction of the tabular. So, it's possible to draw the heavy rule without changing the code concerning \csvreader
(and even simplifying that code).
\documentclass[11pt]{article}
\usepackage{array}
\usepackage{csvsimple}
\usepackage{nicematrix}
\usepackage{tikz}
\begin{filecontents}[overwrite]{data-mwe.csv}
a,b
c,d
text,
e,f
\end{filecontents}
\begin{document}
\begin{NiceTabular}{ll}%
[
hvlines,
code-after = { \tikz \draw [very thick] (row-2-|col-1) -- (row-2-|col-3) ; }
]
column 1 & column 2
\csvreader[no head]{data-mwe.csv}{}{%
\ifthenelse{\equal{\csvcolii}{}}{
\\ \multicolumn{2}{c}{\csvcoli}
}{%
\\ \csvcoli & \csvcolii
}
}
\\
\end{NiceTabular}
\end{document}
You need several compilations.