我尝试使用下面的数据和代码在 Latex 中创建一个表。但是,Texmaker 一直给我“!Package PGF Math Error: Could not parse input 'fdcexp' as a floating point nu”。有人能帮我解决这个问题吗?
\documentclass[12pt,a4paper]{article}
\usepackage{float}
\usepackage{pgfplotstable,pgfplots,booktabs,filecontents,pdflscape}
\newcolumntype{M}{>{$}c<{$}}
\begin{document}
\begin{filecontents}{result3.dat}
model,modelx
,y3
fdcexp,0.402**
,-2.19
L.gdpper,-0.00472
,(-1.63)
growth,0.138
,-0.29
D.lnhuman,-0.533
,(-0.60)
ligdp,-0.251
,(-1.55)
2002.obs,0
,(.)
2003.obs,0.356
,-1.44
2004.obs,0.262
,-1.02
2005.obs,0.605**
,-2.32
2006.obs,0.707***
,-2.6
2007.obs,1.407***
,-4.97
2008.obs,1.943***
,-6.67
2009.obs,2.187***
,-6.77
2010.obs,2.324***
,-6.72
2011.obs,2.483***
,-6.67
2012.obs,2.817***
,-7.31
2013.obs,3.073***
,-8.48
2014.obs,3.495***
,-9.26
fdcall,
,
fdcave,
,
fdcnet,
,
fdcrev,
,
yr2007,
,
_cons,8.796***
,-4.23
N,259
r2_o,0.152
\end{filecontents}
\begin{landscape}
\centering\small
\setlength\tabcolsep{2.2pt}
\pgfplotstabletypeset[
col sep = comma,
display columns/model/.style={string type,column type={l}},
display columns/modelx/.style={string type},
]{result3.dat}
\end{landscape}
\end{document}
答案1
您必须使用其中之一display columns/0/.style
,columns/model/.style
这意味着
display columns/<column index>/.style
或者
columns/<column name>/.style
因为在_
单元格中列模型需要string replace*={_}{\_},
。
您的表格太长了,所以我删除了一些行作为示例。也许您必须使用longtable
。
\documentclass[12pt,a4paper]{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.14}% <- added!
\usepackage{pdflscape}
\usepackage{filecontents}
\begin{document}
\begin{filecontents}{result3.dat}
model,modelx
,y3
fdcexp,0.402**
,-2.19
L.gdpper,-0.00472
,(-1.63)
growth,0.138
,-0.29
D.lnhuman,-0.533
,(-0.60)
ligdp,-0.251
,(-1.55)
2002.obs,0
,(.)
2003.obs,0.356
,-1.44
fdcall,
,
fdcave,
,
yr2007,
,
_cons,8.796***
,-4.23
N,259
r2_o,0.152
\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}
结果是
以下是针对您的长表使用包的附加建议longtable
,如上所述:
\documentclass[12pt,a4paper]{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.14}% <- added!
\usepackage{pdflscape}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{filecontents}
\begin{document}
\begin{filecontents}{result3.dat}
model,modelx
,y3
fdcexp,0.402**
,-2.19
L.gdpper,-0.00472
,(-1.63)
growth,0.138
,-0.29
D.lnhuman,-0.533
,(-0.60)
ligdp,-0.251
,(-1.55)
2002.obs,0
,(.)
2003.obs,0.356
,-1.44
2004.obs,0.262
,-1.02
2005.obs,0.605**
,-2.32
2006.obs,0.707***
,-2.6
2007.obs,1.407***
,-4.97
2008.obs,1.943***
,-6.67
2009.obs,2.187***
,-6.77
2010.obs,2.324***
,-6.72
2011.obs,2.483***
,-6.67
2012.obs,2.817***
,-7.31
2013.obs,3.073***
,-8.48
2014.obs,3.495***
,-9.26
fdcall,
,
fdcave,
,
fdcnet,
,
fdcrev,
,
yr2007,
,
_cons,8.796***
,-4.23
N,259
r2_o,0.152
\end{filecontents}
\begin{landscape}
\centering\small
\setlength\tabcolsep{2.2pt}
\pgfplotstabletypeset[
col sep = comma,
begin table=\begin{longtable},
end table=\end{longtable},
every head row/.append style={
before row={\caption{My Table}\label{tbl:MyTable}\\\toprule},
after row={
\midrule\endfirsthead
\multicolumn{2}{l}{{\scriptsize Table \thetable\ continued from previous page}}\\
\midrule
model&modelx\\
\midrule
\endhead
\midrule
\multicolumn{2}{r}{{\scriptsize Continued on next page}}
\endfoot
\bottomrule
\endlastfoot
}
},
display columns/0/.style={string type,string replace*={_}{\_},column type={l}},
columns/modelx/.style={string type},
]{result3.dat}
\end{landscape}
\end{document}
运行多次可得:
数据文件中有更多列,但输出中只有两列的示例:
\documentclass[12pt,a4paper]{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.14}% <- added!
\usepackage{pdflscape}
\usepackage{filecontents}
\begin{document}
\begin{filecontents}{result8.dat}
model,modela,modelb,modelc,modeld,modele,modelf,modelg
,y3,fdcexp,0.402**, ,-2.19,L.gdpper,-0.00472
,(-1.63),growth,0.138,,-0.29,D.lnhuman,-0.533
,(-0.60),ligdp,-0.251,,(-1.55),2002.obs,0
,(.),2003.obs,0.356,,-1.44,2004.obs,0.262
2005.obs,0.605**,,-2.32,2006.obs,0.707***,,-2.6
fdcall,,,fdcave,,,fdcnet,
_cons,8.796***,,-4.23,N,259,r2_o,0.152
\end{filecontents}
\begin{landscape}
\centering\small
\setlength\tabcolsep{2.2pt}
\pgfplotstabletypeset[
col sep = comma,
columns={model,modela},
display columns/0/.style={string type,string replace*={_}{\_},column type={l}},
columns/modela/.style={string type}
]{result8.dat}
\end{landscape}
\end{document}
或输出中的所有列
\documentclass[12pt,a4paper]{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.14}% <- added!
\usepackage{pdflscape}
\usepackage{filecontents}
\begin{document}
\begin{filecontents}{result8.dat}
model,modela,modelb,modelc,modeld,modele,modelf,modelg
,y3,fdcexp,0.402**, ,-2.19,L.gdpper,-0.00472
,(-1.63),growth,0.138,,-0.29,D.lnhuman,-0.533
,(-0.60),ligdp,-0.251,,(-1.55),2002.obs,0
,(.),2003.obs,0.356,,-1.44,2004.obs,0.262
2005.obs,0.605**,,-2.32,2006.obs,0.707***,,-2.6
fdcall,,,fdcave,,,fdcnet,
_cons,8.796***,,-4.23,N,259,r2_o,0.152
\end{filecontents}
\begin{landscape}
\centering\small
\setlength\tabcolsep{2.2pt}
\pgfplotstabletypeset[
col sep = comma,
string type,
display columns/0/.style={string replace*={_}{\_},column type={l}},
display columns/6/.style={string replace*={_}{\_}}
]{result8.dat}
\end{landscape}
\end{document}