T-F-S / csvsimple

A LaTeX package for lightweight CSV file processing.
http://www.ctan.org/pkg/csvsimple
LaTeX Project Public License v1.3c
24 stars 5 forks source link

[Q] \csvreader automatically create column header from csv file #25

Closed JustSaX closed 1 year ago

JustSaX commented 1 year ago

Is there an option to automatically create column headers from the first line of a csv file?

I did not spot it in the documentation.

Thanks for your help.

T-F-S commented 1 year ago

No, there is not. \csvautotabular displays the first line separated as header, but the usage is quite restricted.

However, with option no head, the first line is available as data line and may be specially formatted with \ifcsvfirstrow or methods from packages like tabularray, see page 56:

grafik

JustSaX commented 1 year ago

Hi, thanks for your help. Would be the same possible with tabular and booktabs instead of tabulararray?

I tried the following but I don't get bold a bold headerline:

% main.tex
\documentclass{article}

\usepackage[l3]{csvsimple}
\usepackage{booktabs}

\begin{document}

\csvreader[
    no head,
    tabular = rcc,
    table head = {\toprule},
    table foot = {\bottomrule},
    late after first line = {\\ \midrule}
    ]{data.csv}{}{
        \ifcsvfirstrow
        {\textbf{\csvcoli}&\textbf{\csvcolii} & \textbf{\csvcoliii}}
        {\csvcoli & \csvcolii & \csvcoliii}
        }
\end{document}

image

T-F-S commented 1 year ago

This should (and does) work with version 2.3.2. Older versions contained a bug, see https://github.com/T-F-S/csvsimple/issues/23, so I guess your version is too old (?).

JustSaX commented 1 year ago

Thanks T-F-S updating my csvsimple version helped.