![在 Pgfplotstable 中使用 Slashbox/Diagbox](https://linux22.com/image/389715/%E5%9C%A8%20Pgfplotstable%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20Slashbox%2FDiagbox.png)
我有一个这种形式的 csv 文件
,0.01,0.1,1.0,10.0,100.0
0,0.3837,0.8259,0.9386,0.9386,0.9386
1,0.3837,0.9464,0.9386,0.9386,0.9386
2,0.3976,0.95,0.9386,0.9386,0.9386
3,0.8259,0.9386,0.9386,0.9386,0.9386
4,0.9464,0.9386,0.9386,0.9386,0.9386
我已成功使用 Pgfplotstable 包将其作为表格插入我的 latex 文件中。这是屏幕截图:
我的问题是我想将最左上角的单元格(当前为空)设为具有两个元素 A 和 B 的对角线单元格。A 表示最左行,B 表示最上列。我知道我必须使用 slashbox 或 diagbox 来执行此操作,但我不知道如何在 pgfplotstable 中使用它。这是表格的工作示例。
\documentclass[a4,12pt]{report}
\usepackage{pgfplotstable}
\begin{document}
\begin{table}[h!]
\caption{Example Table}
\label{tab:polytune}
\begin{center}
\pgfplotstabletypeset[
col sep=comma,
header = has colnames,
string type,
display columns/0/.style={column name = ,column type={|l|},
postproc cell content/.code={% <--- style row 2 (=index 1) of column "2"
\ifnum\pgfplotstablerow=0
\pgfkeysalso{@cell content=0.01}% <---make it red
\fi
\ifnum\pgfplotstablerow=1
\pgfkeysalso{@cell content=0.1}% <---make it red
\fi
\ifnum\pgfplotstablerow=2
\pgfkeysalso{@cell content=1}% <---make it red
\fi
\ifnum\pgfplotstablerow=3
\pgfkeysalso{@cell content=10}% <---make it red
\fi
\ifnum\pgfplotstablerow=4
\pgfkeysalso{@cell content=100}% <---make it red
\fi
},
},
display columns/1/.style={column type={l|}},
display columns/2/.style={column type={l|}},
display columns/3/.style={column type={l|}},
display columns/4/.style={column type={l|}},
display columns/5/.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},
]{
,0.01,0.1,1.0,10.0,100.0
0,0.3837,0.8259,0.9386,0.9386,0.9386
1,0.3837,0.9464,0.9386,0.9386,0.9386
2,0.3976,0.95,0.9386,0.9386,0.9386
3,0.8259,0.9386,0.9386,0.9386,0.9386
4,0.9464,0.9386,0.9386,0.9386,0.9386
}
\end{center}
\end{table}
\end{document}
答案1
您几乎已经完成了。我刚刚将其添加到before row
密钥中。
\documentclass[a4,12pt]{report}
\usepackage{diagbox}
\usepackage{pgfplotstable}
\begin{document}
\begin{table}[h!]
\caption{Example Table}
\label{tab:polytune}
\begin{center}
\pgfplotstabletypeset[
col sep=comma,
header = has colnames,
string type,
display columns/0/.style={column name = ,column type={|l|},
postproc cell content/.code={% <--- style row 2 (=index 1) of column "2"
\ifnum\pgfplotstablerow=0
\pgfkeysalso{@cell content=0.01}% <---make it red
\fi
\ifnum\pgfplotstablerow=1
\pgfkeysalso{@cell content=0.1}% <---make it red
\fi
\ifnum\pgfplotstablerow=2
\pgfkeysalso{@cell content=1}% <---make it red
\fi
\ifnum\pgfplotstablerow=3
\pgfkeysalso{@cell content=10}% <---make it red
\fi
\ifnum\pgfplotstablerow=4
\pgfkeysalso{@cell content=100}% <---make it red
\fi
},
},
display columns/1/.style={column type={l|}},
display columns/2/.style={column type={l|}},
display columns/3/.style={column type={l|}},
display columns/4/.style={column type={l|}},
display columns/5/.style={column type={l|}},
every head row/.style={before row={\hline\diagbox[innerwidth = 2.5em,
height = 3ex]{}{}},after row=\hline},
every nth row={1}{before row=\hline},
every last row/.style={after row=\hline},
]{
,0.01,0.1,1.0,10.0,100.0
0,0.3837,0.8259,0.9386,0.9386,0.9386
1,0.3837,0.9464,0.9386,0.9386,0.9386
2,0.3976,0.95,0.9386,0.9386,0.9386
3,0.8259,0.9386,0.9386,0.9386,0.9386
4,0.9464,0.9386,0.9386,0.9386,0.9386
}
\end{center}
\end{table}
\end{document}