我在用@杰克的 解决方案以突出极端值使用 pgfplotstable。
文档
\documentclass[]{article} \input{table.tex} % table.tex includes Jake's code \begin{document} \begin{table}[ht] \begin{center} \pgfplotstableread[col sep=comma]{data-1.csv}\data \pgfplotstabletypeset[ column type=r, columns/a/.style={column type={l|}, string type}, every head row/.style={before row=\hline, after row=\hline}, every last row/.style={after row=\hline}, empty cells with={\ensuremath{-}}, highlight col max ={\data}{b}, highlight col max ={\data}{c}, highlight col max ={\data}{d}, ]{\data} \end{center} \caption{My table.} \label{tab:results} \end{table} \end{document}
表格.tex
\usepackage{pgfplotstable} \pgfplotsset{compat=newest} % https://tex.stackexchange.com/a/81912/15301 % [conditional formatting per values](https://tex.stackexchange.com/a/34045/15301) \newcommand{\findmax}[3]{ \pgfplotstablevertcat{\datatable}{#1} \pgfplotstablecreatecol[ create col/expr={% \pgfplotstablerow }]{rownumber}\datatable \pgfplotstablesort[sort key={#2},sort cmp={float >}]{\sorted}{\datatable}% \pgfplotstablegetelem{0}{rownumber}\of{\sorted}% \pgfmathtruncatemacro#3{\pgfplotsretval} \pgfplotstableclear{\datatable} } \newcommand{\findmin}[3]{ \pgfplotstablevertcat{\datatable}{#1} \pgfplotstablecreatecol[ create col/expr={% \pgfplotstablerow }]{rownumber}\datatable \pgfplotstablesort[sort key={#2},sort cmp={float <}]{\sorted}{\datatable}% \pgfplotstablegetelem{0}{rownumber}\of{\sorted}% \pgfmathtruncatemacro#3{\pgfplotsretval} \pgfplotstableclear{\datatable} } \pgfplotstableset{ highlight col max/.code 2 args={ \findmax{#1}{#2}{\maxval} \edef\setstyles{\noexpand\pgfplotstableset{ every row \maxval\noexpand\space column #2/.style={ postproc cell content/.append style={ /pgfplots/table/@cell content/.add={$\noexpand\bf}{$} }, } } }\setstyles }, highlight col min/.code 2 args={ \findmin{#1}{#2}{\minval} \edef\setstyles{\noexpand\pgfplotstableset{ every row \minval\noexpand\space column #2/.style={ postproc cell content/.append style={ /pgfplots/table/@cell content/.add={\noexpand\color{red}$\noexpand\bf}{$} }, } } }\setstyles }, highlight row max/.code 2 args={ \pgfmathtruncatemacro\rowindex{#2-1} \pgfplotstabletranspose{\transposed}{#1} \findmax{\transposed}{\rowindex}{\maxval} \edef\setstyles{\noexpand\pgfplotstableset{ every row \rowindex\space column \maxval\noexpand/.style={ postproc cell content/.append style={ /pgfplots/table/@cell content/.add={$\noexpand\bf}{$} }, } } }\setstyles }, highlight row min/.code 2 args={ \pgfmathtruncatemacro\rowindex{#2-1} \pgfplotstabletranspose{\transposed}{#1} \findmin{\transposed}{\rowindex}{\maxval} \edef\setstyles{\noexpand\pgfplotstableset{ every row \rowindex\space column \maxval\noexpand/.style={ postproc cell content/.append style={ /pgfplots/table/@cell content/.add={\noexpand\color{red}$\noexpand\bf}{$} }, } } }\setstyles }, }
当我填写表中的所有值时,它运行良好:
数据-1.csv
a,b,c,d x,1,3,5 y,2,2,2 z,1,1,7
即使有nan
:
数据-2.csv
a,b,c,d x,1,3,5 y,2,2,2 z,1,1,nan
NaN
但是,我想要用破折号-
来标记空单元格,而不是。因此,我将其包含empty cells with={\ensuremath{-}}
在 中\pgfplotstabletypeset
,并完全清空文件中的相应单元格csv
。但是,在这种情况下,编译失败:
数据-3.csv
a,b,c,d x,1,3,5 y,2,2,2 z,1,1,
错误信息:
! Package PGF Math Error: Could not parse input '' as a floating point number, sorry. The unreadable part was near ''..
如果我想用破折号标记我的空单元格,如下面的屏幕截图所示,但同时突出显示每列的最大值,如 Jake 的代码所示,我该怎么做?