0

How do you make tables with horizontal lines between rows with the csvautotabular function of the csvsimple package?

Example .csv file.

header,
104, 1
312, 0.223
518, 0.198
726, 0.139
932, 0.077
4
  • Can you add an example of code?
    – egreg
    Nov 12, 2015 at 10:07
  • As in to call csvautotabular? There is nothing but \csvautotabular{xxx.csv}.
    – Argyll
    Nov 12, 2015 at 10:08
  • With a sample from xxx.csv
    – egreg
    Nov 12, 2015 at 10:12
  • Multiple row, multiple column numerical data?
    – Argyll
    Nov 12, 2015 at 10:33

2 Answers 2

2

The \csvautotabular macro is intended for a quick tabular overview. It is quite simple and is not really suitable for customization.

In my example code, I offer a hack solution my hack to provide the requested feature. But for productive code, I would rather use a customizable solution with \csvreader or \csvloop. I also added several examples for this:

\documentclass{article}
\usepackage{csvsimple}

\begin{filecontents*}{example.csv}
header,
104, 1
312, 0.223
518, 0.198
726, 0.139
932, 0.077
\end{filecontents*}

\makeatletter
\csvset{
  my hack/.style={
    late after line=\\\hline,
    late after last line=\csv@tablefoot\end{tabular}\csv@posttable},
}
\makeatother

\begin{document}

Hacked autotabular:\par\smallskip
\csvautotabular[my hack]{example.csv}

\medskip

Better with csvreader and tabular:\par\smallskip
\csvreader[tabular=|l|l|,
  table head=\hline header & \\\hline,
  late after line=\\\hline]%
  {example.csv}{}%
{\csvlinetotablerow}%

\medskip

Alternatively:\par\smallskip
\csvreader[tabular=|l|l|,
  no head,
  table head=\hline,
  late after line=\\\hline]%
  {example.csv}{}%
{\csvcoli & \csvcolii}%

\medskip

Alternatively:\par\smallskip
\csvreader[tabular=|l|l|,
  no head,column count=2,
  table head=\hline,
  late after line=\\\hline]%
  {example.csv}{}%
{\csvlinetotablerow}%

\medskip

Alternatively:\par\smallskip
\csvloop{
  file=example.csv,
  no head,column count=2,
  tabular=|l|l|,
  table head=\hline,
  command=\csvlinetotablerow,
  late after line=\\\hline
}

\end{document}

enter image description here

2
  • What does \csvlinetotablerow do under \csvreader please?
    – Argyll
    Nov 13, 2015 at 10:43
  • \csvlinetotablerow typesets the current processed data line with & between the entries. Here, this means \csvcoli & \csvcolii. Nov 17, 2015 at 12:31
0
\documentclass{article}
\usepackage{csvsimple}

\begin{document}
\csvautotabular[respect sharp]{mycsv.csv}
\end{document}

csvtbl

1
  • there is no horizontal lines between data entries though?
    – Argyll
    Nov 12, 2015 at 22:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .