1

(question updated from 1 to 3 columns)

I am trying to do something supremely simple: typeset a table such as

what.csv

First,Last,Style
Bob,Marley,Reggae
Fritz,Wunderlich,Lieder

with boldface headings.

CSV table

Yet in the code

\documentclass{article}
\usepackage{csvsimple}

\begin{document}

\section{---One---}
\begin{tabular}{|c|}
  \hline
  \bfseries Name
  \\\hline
  \csvreader[head to column names]{what.csv}{}
        {\First \Last \Style \\}
\end{tabular}

\section{---Two---}
\csvautotabular{what.csv}

\section{---Three---}
% \csvautobooktabular{what.csv}

\end{document}

various attempts at eliminating the extra emtpy entry fail. Indeed just adding the closing bottom line is tricky.

I'd gladly settle for some preset style, one applying \bfseries for the headings (and without frequent horizontal lines). Using \csvautotabular works (minus the boldface), but \csvautobooktabular doesn't. Adding \bfseries as an option also fail. Is csvsimple the right tool for the job in the first place?

1

enter image description here

In the following MWE, I have replaced \begin{tabular}{|c|} with the tabular=|c| option, used table head=\hline\bfseries Name\\\hline, for the top line, the bold column header and the line below the header as well as table foot = \hline for the horizontal line at the end of the table. I have also added a second variant using the horizontal lines from the booktabs package.

\documentclass{article}
\usepackage{csvsimple}
\usepackage{booktabs} %% Only needed for the second example.
\begin{document}

\csvreader[head to column names,%
           tabular=|c|,%
           table head=\hline\bfseries Name\\\hline,%
           table foot = \hline]%
           {who.csv}%
           {}%
           {\Name}

\bigskip

\csvreader[head to column names,%
           tabular=c,%
           table head=\toprule\bfseries Name\\\midrule,%
           table foot = \bottomrule]%
           {who.csv}%
           {}%
           {\Name}

\end{document}

Updae regarding the changed what.csv:

With

First,Last,Style
Bob,Marley,Reggae
Fritz,Wunderlich,Lieder

you can use the following MWE to get a two column tabular that contains the first and last name:

enter image description here

\documentclass{article}
\usepackage{csvsimple}
\usepackage{booktabs}
\begin{document}

\csvreader[head to column names,%
           tabular=cc,%
           table head=\toprule\bfseries First & \bfseries Last\\\midrule,%
           table foot = \bottomrule]%
           {who.csv}%
           {}%
           {\First & \Last}

\end{document}
  • Nice! Though apparently moving to just two (First, Last) columns cannot simply be done by replacing the lines with tabular=c c,% and {\First \Last}. Could you add a hint? – Vrokipal Oct 3 at 17:54
  • @Vrokipal: I have updated my answer regarding your edited csv file. – leandriis Oct 3 at 18:19
  • I see. We're actually plugging in into tabular. – Vrokipal Oct 3 at 18:26

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.