\csvreader 不显示表格

\csvreader 不显示表格

我主要想做类似的事情-

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

但这还没有被编译

我的coefficient.csv样子就像-

"","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

我想csvsimple从基础开始学习。

答案1

如手册第 2 节所述csvsimple,该\csvreader宏采用强制参数,而你刚刚添加了一个。也就是说,一般格式是

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

当你刚刚使用

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

\csvautotabular另一方面,宏观方面,如Abo Ammar 的回答只有一个强制参数,即文件名。)

论点:

  1. 第一个强制参数是文件的文件名.csv

  2. 第二个参数将宏分配给各列的内容。例如,如果你有一个.csv文件,如下所示

    a,b
    1,2
    3,4
    

    那么你将使用

    a=\foo,b=\bar
    

    在第二个必需参数中,定义两个宏\foo\bar,分别引用ab列。

  3. 第三个参数是使用第二个参数中定义的宏来定义表格行的格式。例如

    \bar & \foo
    

    首先打印b列,然后a打印列。

  • \csvreader还有一个可选参数,您可以在其中定义表的列类型(例如,tabular=cc两个居中的列)以及所需的任何其他格式。

"下面是一个完整的示例,使用了手册第 3.4 节中示例中的一些内容。为了从第一列输出中删除引号 ( ),我加载了xstring包并在行格式中使用了\StrDel{\name}{"}而不是。这将删除所有出现的。\name"

代码输出

\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}

答案2

\documentclass{article}
\usepackage{csvsimple}
\begin{document}

This is the summary 

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

\end{document}

文件coefficient.csv内容

,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

在此处输入图片描述

相关内容