处理大型数据表

处理大型数据表

在我的研究中,我通常需要处理大量的结果表。我尝试找到一种方法将这些结果导入 Latex。我搜索互联网并尝试了一些软件包,如 csvsimple、pgfplotstable。起初,这些软件包适用于 3、4 行和列的小表格。但是,当我添加更多行和更多列时,这些软件包将不再起作用。随着表格尺寸的增大,浮点数会出现许多错误,以下面的消息为例: “!包 PGF 数学错误:无法将输入‘(-1.63)’解析为浮点数,抱歉。不可读的部分靠近‘(-1.63)’。” 有人能解决这个问题吗?我在下面附上我正在做的一个示例。数据为文本格式,带有逗号分隔符。

\documentclass[12pt,a4paper]{article}
\usepackage{float}
\usepackage{pgfplotstable,pgfplots,booktabs,filecontents,pdflscape,
csvsimple,longtable}
\newcolumntype{M}{>{$}c<{$}}
\begin{document}
\begin{filecontents}{result3.dat}
model,-1,-2,-3,-4,-5,-6,-7,-8,-9,-10
fdcexp,0.402**,,,,,0.402**,,,,
,-2.19,,,,,-2.19,,,,
L.gdpper,-0.00472,-0.00465,-0.00540***,-0.00542***,-0.00540***,-0.00472,-0.00465,-0.00540***,-0.00542***,-0.00540***
,(-1.63),(-1.60),(-3.45),(-3.45),(-3.44),(-1.63),(-1.60),(-3.45),(-3.45),(-3.44)
growth,0.138,0.149,0.0726,0.0794,0.0868,0.138,0.149,0.0726,0.0794,0.0868
,-0.29,-0.32,-0.18,-0.2,-0.22,-0.29,-0.32,-0.18,-0.2,-0.22
D.lnhuman,-0.533,-0.496,-0.639,-0.661,-0.622,-0.533,-0.496,-0.639,-0.661,-0.622
,(-0.60),(-0.55),(-0.90),(-0.93),(-0.88),(-0.60),(-0.55),(-0.90),(-0.93),(-0.88)
ligdp,-0.251,-0.238,-0.148,-0.135,-0.148,-0.251,-0.238,-0.148,-0.135,-0.148
,(-1.55),(-1.49),(-0.58),(-0.53),(-0.58),(-1.55),(-1.49),(-0.58),(-0.53),(-0.58)
fdcall,,0.400**,,,,,0.400**,,,
,,-2.21,,,,,-2.21,,,
fdcave,,,0.0626*,,,,,0.0626*,,
,,,-2.06,,,,,-2.06,,
fdcnet,,,,0.0262**,,,,,0.0262**,
,,,,-2.2,,,,,-2.2,
fdcrev,,,,,0.0643***,,,,,0.0643***
,,,,,-3,,,,,-3
yr2007,,,,,,3.495***,3.495***,3.416***,3.398***,3.430***
,,,,,,-9.26,-9.27,-6.02,-5.97,-5.98
_cons,8.796***,8.526***,7.695**,7.575**,7.678**,8.796***,8.526***,7.695**,7.575**,7.678**
,-4.23,-4.17,-2.25,-2.21,-2.25,-4.23,-4.17,-2.25,-2.21,-2.25
N,259,259,259,259,259,259,259,259,259,259
r2_o,0.152,0.131,0.187,0.181,0.185,0.152,0.131,0.187,0.181,0.185
\end{filecontents}
\begin{landscape}
\centering\small
\setlength\tabcolsep{2.2pt}
\pgfplotstabletypeset[
col sep = comma,
display columns/0/.style={string type,,string replace*={_}{\_},column type={l}},
columns/modelx/.style={string type},
]{result3.dat}
\end{landscape}
\end{document}

I would like my table to look like this

答案1

几分钟的编辑就可以制作出可以排版为表格的内容。您使用该pgfplotstable包意味着 tex 需要将数据视为数值,在这种情况下需要进行更多过滤。

这里我只是改为,&在行\\尾添加了,

它仍然太满,但在缩小字体和其他操作之前,您需要这么多小数位吗?像 -0.00540 这样的值很难显示合理的表格。您可以在 tex 中格式化这些数字,但在输出此数据的任何应用程序中这样做可能更简单。

enter image description here

\documentclass[12pt,a4paper]{article}

\usepackage{pdflscape,longtable,array,dcolumn}
\newcolumntype{M}{>{$}c<{$}}
\begin{document}
\begin{landscape}\small
\setlength\tabcolsep{4pt}
\setlength\LTleft{-10pt}
\setlength\LTright{-10pt plus 1fill}
\begin{longtable}{@{}l*{10}{D..{3.6}}@{}}
model&-1&-2&-3&-4&-5&-6&-7&-8&-9&-10\\
fdcexp&0.402**&&&&&0.402**&&&&\\
&-2.19&&&&&-2.19&&&&\\
L.gdpper&-0.00472&-0.00465&-0.00540***&-0.00542***&-0.00540***&-0.00472&-0.00465&-0.00540***&-0.00542***&-0.00540***\\
&(-1.63)&(-1.60)&(-3.45)&(-3.45)&(-3.44)&(-1.63)&(-1.60)&(-3.45)&(-3.45)&(-3.44)\\
growth&0.138&0.149&0.0726&0.0794&0.0868&0.138&0.149&0.0726&0.0794&0.0868\\
&-0.29&-0.32&-0.18&-0.2&-0.22&-0.29&-0.32&-0.18&-0.2&-0.22\\
D.lnhuman&-0.533&-0.496&-0.639&-0.661&-0.622&-0.533&-0.496&-0.639&-0.661&-0.622\\
&(-0.60)&(-0.55)&(-0.90)&(-0.93)&(-0.88)&(-0.60)&(-0.55)&(-0.90)&(-0.93)&(-0.88)\\
ligdp&-0.251&-0.238&-0.148&-0.135&-0.148&-0.251&-0.238&-0.148&-0.135&-0.148\\
&(-1.55)&(-1.49)&(-0.58)&(-0.53)&(-0.58)&(-1.55)&(-1.49)&(-0.58)&(-0.53)&(-0.58)\\
fdcall&&0.400**&&&&&0.400**&&&\\
&&-2.21&&&&&-2.21&&&\\
fdcave&&&0.0626*&&&&&0.0626*&&\\
&&&-2.06&&&&&-2.06&&\\
fdcnet&&&&0.0262**&&&&&0.0262**&\\
&&&&-2.2&&&&&-2.2&\\
fdcrev&&&&&0.0643***&&&&&0.0643***\\
&&&&&-3&&&&&-3\\
yr2007&&&&&&3.495***&3.495***&3.416***&3.398***&3.430***\\
&&&&&&-9.26&-9.27&-6.02&-5.97&-5.98\\
\_cons&8.796***&8.526***&7.695**&7.575**&7.678**&8.796***&8.526***&7.695**&7.575**&7.678**\\
&-4.23&-4.17&-2.25&-2.21&-2.25&-4.23&-4.17&-2.25&-2.21&-2.25\\
N&259&259&259&259&259&259&259&259&259&259\\
r2\_o&0.152&0.131&0.187&0.181&0.185&0.152&0.131&0.187&0.181&0.185\\
\end{longtable}
\end{landscape}
\end{document}

相关内容