pgfplotstable:帶有 2 個或更多標題行的 csv 類型(例如名稱、單位、註釋)

pgfplotstable:帶有 2 個或更多標題行的 csv 類型(例如名稱、單位、註釋)

我從 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]}
        },

編輯2: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之外運行時它肯定會打印該行)。

我認為這一定是一些常見的工作流程,並且已經有一個簡單的解決方案...

相關內容