# Display top border of table using csvreader

I am using csvreader from the csvsimple package to generate a table in my document. I am struggling to get a top border on the table. Here is the code, including writing the .csv

\documentclass{article}
\usepackage{csvsimple}

% Make csv in question
\begin{filecontents*}{scientists2.csv}
name,surname,
Albert,Einstein,
Marie,Curie,
Thomas,Edison
\end{filecontents*}

\begin{document}

\begin{center}
table head=\textbf{ First Name} & \textbf{Last Nmae} \\\hline,
late after line = \\\hline]%
{scientists2.csv}{name=\name,surname=\surname}%
{\name & \surname}%

\end{center}

\end{document}


What argument can I pass (to tabular?) to see the top border? I am using TexWorks to compile. Thanks,

-
 Happy to provide more feedback, but what is MWE? – mike Nov 10 '12 at 23:54 @mike: MWE means Minimal Working Example – Xavier Garrido Nov 11 '12 at 0:03 Thanks -- MWE now included. – mike Nov 11 '12 at 0:28

## 1. csvsimple:

You can simply adjust the table head to start with an \hline:

## 2. booktabs:

However, the booktabs package is usually recommened to produce more professional looking tables. So, I have added a second example that uses this along with the datatool package:

Much thanks to Nicola Talbot, who helped with proper use of booktabs here.

## 3. pgfplotstable:

A solution using pgfplotstable is provided at Bold one cell in table using CSV reader.

## Notes:

• Not sure why I needed the extra \\ before the \bottomrule which is producing the additional spacing at the bottom. To fix this I added a manual \vspace*{-12pt}, which is more of a hack.

• It appears the the csvsimple package was discarding the last row as it did not have a trailing ,.

## Code:

\documentclass{article}

\usepackage{datatool}
\usepackage{booktabs}
\usepackage{csvsimple}

% Make csv in question
%\usepackage{filecontents}
\begin{filecontents*}{scientists2.csv}
name,surname,
Albert,Einstein,
Marie,Curie,
Thomas,Edison,
\end{filecontents*}

\begin{document}

\begin{center}
table head=\hline \textbf{ First Name} & \textbf{Last Name} \\\hline,
late after line = \\\hline]%
{scientists2.csv}{name=\name,surname=\surname}%
{\name & \surname}%
\end{center}

%\DTLdisplaydb{myDB}% Useful for debugging.

\begin{center}
\begin{tabular}{ll}\toprule
\textbf{First Name} & \textbf{Last Name}%
\DTLforeach*{myDB}{\Name=name,\Surname=surname}{%
\DTLiffirstrow{\\\cmidrule{1-2}}{\\}%
\Name & \Surname
}%
\\\bottomrule
\end{tabular}
\end{center}
\end{document}

-
 Perfect, thanks! – mike Nov 11 '12 at 0:32 Also, why does Thomas Edison not show up when this code is run? Thanks for help with a new user! – mike Nov 11 '12 at 0:35 Hmmm... Don't know as I have never used the csvsimple package, just really guessed at the solution (bad habit I picked up from David Carlisle :-)). I was about to do a datatool solution for you using booktabs as I know that will work, and you can get a "better" table. As the missing data seems unrelated to displaying a top border, I would recommend you should post a separate question. – Peter Grill Nov 11 '12 at 0:41 @mike: Found issue with last entry: Need a trailing , for some reason. See updated answer. – Peter Grill Nov 11 '12 at 1:05 Seems strange -- thanks! – mike Nov 11 '12 at 1:32