1

Mainly I want to do something similar this-

\documentclass{article}
\usepackage{csvsimple}
\begin{document}
This is the summary 
\csvreader[autotabular]{coefficient.csv}
\end{document}

but this is not compiled

My coefficient.csv looks like-

"","Estimate","Pr(>|t|)"
"(Intercept)",3083.10823266321,0.410258948870845
"academicYear",-154.682625625893,0.586945960271761
"tuitionOfferPerMonth",166.418331237849,0.626598991149528
"tutionsYouHaveDone",88.1170833442809,0.687790764988264
"result",2174.73550930876,0.0319792901914711
"teachingHour",762.859932701096,0.421832171976142
"subjectsYouTaught",-99.4216388435531,0.831181012593366
"daysInWeek",-471.260444393369,0.409951748818405
"tuitionType",469.36175552496,0.446727615621479
"studentClass",159.808778458308,0.249053825131443
"Dept.science",1902.80982919603,0.105027526587972
"Hall",-1057.61231171402,0.196789600388924

I want to learn the csvsimple from basic.

6
  • Welcome to TeX.SX! You can help us to help you by providing the code for a small compilable document that shows your problem called MWE. Just edit your question and add missing code.
    – Bobyandbob
    Commented Nov 14, 2017 at 12:56
  • You should definitely start providing complete documents and not snippets, like you often do. And given that you get errors from that code, you shouldn't be surprised that the output is wrong. And you should have a look at the csvsimple manual, in particular section 2 on page 8, which describes how \csvreader is supposed to be used. Commented Nov 14, 2017 at 13:02
  • @TorbjørnT. My original document is so big. So, I don't want to attach this. I edited my question although the sample code not run.
    – alhelal
    Commented Nov 14, 2017 at 13:13
  • You're not supposed to show your entire document, you're supposed to show exactly what you now have: the smallest complete document necessary to demonstrate the problem. Commented Nov 14, 2017 at 13:15
  • @TorbjørnT. see line 86 on this
    – alhelal
    Commented Nov 14, 2017 at 13:18

2 Answers 2

2

As described in section 2 of the csvsimple manual, the \csvreader macro takes three mandatory arguments, while you've just added one. That is, the general format is

\csvreader[<options>]{<file name>}{<assignments>}{<command list>}

while you've just used

\csvreader[<options>]{<file name>}

(The \csvautotabular macro on the other hand, as seen in Abo Ammar's answer has just one mandatory argument, the file name.)

The arguments:

  1. The first mandatory argument is the filename of the .csv file.

  2. The second argument assigns macros to the content of the various columns. For example, if you had a .csv file that looked like

    a,b
    1,2
    3,4
    

    then you would use

    a=\foo,b=\bar
    

    in the second mandatory argument, to define the two macros \foo and \bar, referring to the a and b columns respectively.

  3. The third argument is where you define the format of your table rows, using the macros defined in the second argument. For example

    \bar & \foo
    

    to print the b column first, and a column second.

  • \csvreader also has an optional argument, where you define the column types of your table (e.g. tabular=cc for two centred columns), and any other formatting you need.

A complete example below, using some bits from the example in section 3.4 of the manual. To remove the quotation marks (") from the first column output, I load the xstring package and use \StrDel{\name}{"} instead of \name in the row format. That will delete all occurrences of ".

output of code

\documentclass{article}
\usepackage{csvsimple}
\usepackage{xstring} % defines \StrDel
\usepackage{booktabs} % defines \toprule,\midrule,\bottomrule
\begin{document}
\csvreader[
  % set up the columns in the table
  tabular=ccc,
  % define the content of the first row
  table head=\toprule Name & Estimate & $\mathrm{Pr}(>\mid t)$ \\ \midrule,
  % add rule after table
  table foot=\bottomrule
 ]{coefficient.csv}% filename
{""=\name,"Estimate"=\estimate,"Pr(>|t|)"=\Pr}% define macros that refer to the columns you want to use
{\StrDel{\name}{"} & \estimate & \Pr} % format of rows

\end{document}
4
  • Doesn't it work if I don't define macro for column?
    – alhelal
    Commented Nov 15, 2017 at 0:30
  • Why did you write the file content again in the code although you use filePath?
    – alhelal
    Commented Nov 15, 2017 at 0:34
  • The "" should be omit. I want to omit these without changing .csv because it's csv formate.
    – alhelal
    Commented Nov 15, 2017 at 0:37
  • @alhelal 1) No, you must assign macro names to columns, but you don't have to assign all the columns. 2) The filecontents stuff is only to make the example self-contained, you can delete it as you already have the file. 3) Load the xstring package and use \StrDel{\name}{"} instead of \name in the row format. Commented Nov 15, 2017 at 6:58
1
\documentclass{article}
\usepackage{csvsimple}
\begin{document}

This is the summary 

\csvautotabular[respect dollar=false]{coefficient.csv}

\end{document}

With the coefficient.csv file contents

,Estimate, Pr$(>|t|)$
(Intercept),3083.10823266321,0.410258948870845
academicYear,-154.682625625893,0.586945960271761
tuitionOfferPerMonth,166.418331237849,0.626598991149528
tutionsYouHaveDone,88.1170833442809,0.687790764988264
result,2174.73550930876,0.0319792901914711
teachingHour,762.859932701096,0.421832171976142
subjectsYouTaught,-99.4216388435531,0.831181012593366
daysInWeek,-471.260444393369,0.409951748818405
tuitionType,469.36175552496,0.446727615621479
studentClass,159.808778458308,0.249053825131443
Dept.science,1902.80982919603,0.105027526587972
Hall,-1057.61231171402,0.196789600388924

enter image description here

1
  • Isn't it possible without changing the content of coefficient.csv? I know csvautotabular. You give me the solution with csvreader.
    – alhelal
    Commented Nov 14, 2017 at 16:39

You must log in to answer this question.

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