我有这个 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}
我有几个问题:
0
例如,我怎样才能将第一列名称更改为另一个值/文本No
?- 例如,如何将第一列名称(11)的最后一个元素更改为另一个值/文本
Average
? - 如何在列之间添加垂直线?
提前感谢您的帮助。
答案1
为了将此空单元格的预定义值更改
0
为No
,我添加了assign column name
。 (我并不是说这一定是最优雅的方式。)为了添加垂直条,我使用了
every even column
和every odd column
。- 为了替换表格元素,我添加了
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}