1

I am not managing to make a simple table in csvsimple.

My data is like this: value 1, 5.5 value 2, 3806.0 value 3, 601.0 value 4, 26.8 value 5, 150.0 value 6, 2.0 value 8, 75.0 value 9, 21

I have made the following code and I cannot figure out what is the problem:

\documentclass{article}
\usepackage{csvsimple}

\begin{document}
\csvreader[tabular==|l|r|,
no head,
table head=\hline,
late after line=\\\hline
]{data.csv}
\end{document}

Any advice would be greatly appreciated !

Thanks, Kind regards,

Nicolas

  • 1
    1. After the key tabular, there should be only one =. 2. \csvreader requires three regular arguments. 3. Try \csvreader[tabular=|l|r|,no head,table head=\hline,late after line=\\\hline]{data.csv}{}{\csvcoli & \csvcolii} (note the second and third argument). 4. Read the fine manual. – gernot Aug 17 '16 at 15:52
1

[EDIT Some how I missed @Gernot's comment. This answer is nothing more than an expanded version of what he wrote.]

I think that you have two problems.

  1. A typo: tabular==|l|r| should be tabular=|l|r|.
  2. There are missing arguments to the \csvreader command that are supposed to say how the table should be constructed.

From your question it is not entirely clear to me what data.csv looks like so I have used the file:

5.5
3806.0
601.0
26.8
150.0
2.0
75.0
21

Changing your MWE to

\documentclass{article}
\usepackage{csvsimple}

\begin{document}
  \csvreader[tabular=|l|r|,
  no head,
  table head=\hline,
  late after line=\\\hline]{data.csv}{}{\thecsvrow & \csvcoli}%
\end{document}

you now obtain the table:

enter image description here

Note that \thecsvrow gives the row number and, for a given row, \csvcoli gives the entry in column 1. There are also \csvcolii, \csvcoliii and so on. So the argument {\thecsvrow & \csvcoli} to \csvreader says that each of the table show start with the row index and then have the corresponding entry in column 1 of the data file.

Finally, I'd recommend reading the manual from the booktabs package as it explains why you shouldn't use vertical rules in tables:)

| improve this answer | |
  • Thank you very much to both of you ! I had read the manual but had not understood that the {} between the filename and the column choice was mandatory, nor had I understood that the column choice was mandatory. I thought csvreader would just take all columns if left unspecified (like csvautotabular). Again, big thanks ! ;-) – Nicolas Aug 18 '16 at 6:49
0

Simple solution without lines:

\csvautobooktabular[table head=\toprule\csvlinetotablerow\]{data.csv}

table layout

This requires that you include in your header:

\usepackage{booktabrule}

It's an easy solution because it doesn't need any more arguments. So, you can use it to read tables with a different number of columns – without having to re-specify them every time. It is straight from the manual, p. 39 / section 5.5.

However, if you want to change the style, for example add horizontal lines, I recommend @Andrew's answer.

| improve this answer | |

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.