更改列名和单元格值 Pgfplotstable

更改列名和单元格值 Pgfplotstable

我有这个 csv 文件:

,Accuracy
1,0.982
2,0.982
3,0.982
4,0.988
5,0.916
6,0.976
7,0.958
8,0.97
9,0.945
10,0.988
11,0.969

这是我将其导入 Latex 文件时的截图:

在此处输入图片描述

这是工作示例文件:

\documentclass[a4,12pt]{report}

\usepackage{pgfplotstable}

\begin{document}


    \begin{table}[h!]
        \caption{Accuracy value}
        \label{tab:cvinitial}
        \begin{center}
            \pgfplotstabletypeset[
            col sep=comma,
            header = has colnames,
            string type,
            display columns/ /.style={column type={|l|},}
            display columns/Accuracy/.style={column type={|l|}},
            every head row/.style={before row=\hline,after row=\hline},
            every nth row={1}{before row=\hline},
            every last row/.style={after row=\hline},
            ]{
            ,Accuracy
            1,0.982
            2,0.982
            3,0.982
            4,0.988
            5,0.916
            6,0.976
            7,0.958
            8,0.97
            9,0.945
            10,0.988
            11,0.969
        }
        \end{center}
    \end{table}

\end{document}

我有几个问题:

  1. 0例如,我怎样才能将第一列名称更改为另一个值/文本No
  2. 例如,如何将第一列名称(11)的最后一个元素更改为另一个值/文本Average
  3. 如何在列之间添加垂直线?

提前感谢您的帮助。

答案1

  1. 为了将此空单元格的预定义值更改0No,我添加了assign column name。 (我并不是说这一定是最优雅的方式。)

  2. 为了添加垂直条,我使用了every even columnevery odd column

  3. 为了替换表格元素,我添加了every row 10 column 0/.style={postproc cell content/.style={@cell content=Average}},

\documentclass[a4,12pt]{report}

\usepackage{pgfplotstable}
%\pgfplotsset{compat=1.15}
\begin{document}


    \begin{table}[h!]
        \caption{Accuracy value}
        \label{tab:cvinitial}
        \begin{center}
            \pgfplotstabletypeset[
            col sep=comma,
            header=has colnames,
            assign column name/.style={
            /pgfplots/table/column name={\ifx#10
            No
            \else
            #1
            \fi}
            },
            string type,
            %display columns/ /.style={column type={|l|},}
            every odd column/.style={
                column type/.add={}{|}
            },
            every even column/.style={
                column type/.add={|}{|}
            },
            every row 10 column 0/.style={postproc cell content/.style={@cell
            content=Average}},
            every head row/.style={before row=\hline,after row=\hline},
            every nth row={1}{before row=\hline},
            every last row/.style={after row=\hline},
            ]{
            ,Accuracy
            1,0.982
            2,0.982
            3,0.982
            4,0.988
            5,0.916
            6,0.976
            7,0.958
            8,0.97
            9,0.945
            10,0.988
            11,0.969
        }
        \end{center}
    \end{table}

\end{document}

在此处输入图片描述

相关内容