我从 Origin 导出并得到如下 Data.csv:
Short_Name1; Short_Name2
Long_Name1; Long_Name2
Unit1; Unit2
Comment1; Comment2
1,1; 2,0
3,5; 4,3
当我尝试使用 pgfplotstable 打印它时,我需要执行以下操作:
%!TEX TS-program = lualatex
\documentclass[]{scrartcl}
%\usepackage{pgfplots}
\usepackage{
pgfplotstable,
booktabs,
array,
colortbl,
}
\pgfplotsset{compat=1.12}
\begin{document}
\pgfplotstabletypeset[
col sep=semicolon,
read comma as period,
fixed,
zerofill,
% string type,
precision=2,
ignore chars={\_},
%dec sep align, %prints both strings in first column, aligned at the comma
%
every head row/.style={
before row={\toprule },
after row={\midrule },
},
every last row/.style={
after row=\bottomrule
},
every even row/.style={
before row={\rowcolor[gray]{0.985}}}, %also a problem
%
%every row 0/.style={string type}, %does not work
% \directlua{ for i = 0, 2 do %does also not work
% for j= 0,1 do
% tex.sprint( "every row ",i," column ",j,"\noexpand/.style={string type}, " )
% end
% end }
every row 0 column 0/.style={string type},
every row 0 column 1/.style={string type},
every row 1 column 0/.style={string type},
every row 1 column 1/.style={string type},
every row 2 column 0/.style={string type},
every row 2 column 1/.style={string type},
%
every row 2/.style={
after row={\midrule },
},
]
{Data.csv}
%looks like it should as workaround, but is not processed properly
\directlua{ for i = 0, 2 do
for j= 0,1 do
tex.sprint( "every row ",i," column ",j,"\noexpand/.style={string type}, " )
end
end }
\end{document}
有没有更方便的方法可以做到这一点?
我也会很高兴,如果可以得到
Long_Name1 [Unit1]
作为一个标题行,并忽略其余两行字符串。通过 Origin 导出其中两行是没有问题的。
编辑:我已经尝试过every row no 0/.style={string type},
,但它产生了错误。
header=false
将导致列被命名0 1 2 3
,因此需要将每列命名为
columns/<index>/.style={
string type,
column type=l,
column name={Long_Name [Unit]}
},
EDIT2:header=false
-“问题”已经解决这里
所以我会尝试处理
Long_Name1; Long_Name2
Unit1; Unit2
1,1; 2,0
3,5; 4,3
到
Long_Name1 [\si{Unit1}]; Long_Name2 [\si{Unit2}]
1,1; 2,0
3,5; 4,3
使用 lua(python 会更容易……)但即使我生成的代码也没有
every row 0 column 0/.style={string type},
工作(并且当它在 pgfplotstable 之外运行时它肯定会打印该行)。
我认为这肯定是一些常见的工作流程,并且肯定已经有一个简单的解决方案……