[Tex/LaTex] \csvreader doesn’t show the table

csvsimple

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.

Best Answer

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}
Related Question