遵循 tex.stackexchange.com 上关于使用 pgfplotstable 的其他条目中的建议(例如pgfplotstable:按列对单元格内容进行条件后处理), 我遇到了下面看到的令人费解的行为,我可以成功地将小于 1x10^-4 的 p 值加粗(参见表 1 的图像),但如果我尝试仅将小于 1x10^-5 的 p 值加粗,则完全相同的代码无法工作(参见表 3 的图像)。
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{longtable}
\usepackage{caption}
\usepackage{colortbl}
\definecolor{lightgray}{gray}{0.9}
\usepackage{filecontents}
\begin{filecontents*}{test.csv}
A, B
1, 0.01
2, 0.001
3, 0.0001
4, 1.93E-14
5, 1.44E-09
6, 3.90E-06
\end{filecontents*}
\pgfplotstableread[col sep=comma]{test.csv}\mytable
\begin{document}
\captionof{table}{With threshold $1.0E-04$}
\newcolumntype{C}{>{\centering\arraybackslash}p{17mm}}
\pgfplotstabletypeset[
begin table=\begin{longtable},
end table=\end{longtable},
column type=C,
every even row/.style={
before row={\rowcolor[gray]{0.9}}},
every head row/.style={before row=\hline,after row=\hline\hline},
every last row/.style={after row=\hline},
columns/A/.style={column type=c},
columns/B/.style={column type=c,column name=$p_{B}$,
postproc cell content/.style={
/pgfplots/table/@cell content/.initial={}{%
% However, all calculations must not exceed ±16383.99999 at any point.
% Scientific notation in the form 1.234e+4 is recognized.
% The exponent symbol can be upper or lower case (i.e., E or e).
\pgfmathparse{int(less(##1,1.0E-04))}
\ifnum\pgfmathresult=1
\textbf{##1}
\else
{##1}
\fi
},
},
},
col sep=comma,
string type]\mytable
\captionof{table}{With threshold $1.0E-05$}
\newcolumntype{C}{>{\centering\arraybackslash}p{17mm}}
\pgfplotstabletypeset[
begin table=\begin{longtable},
end table=\end{longtable},
column type=C,
every even row/.style={
before row={\rowcolor[gray]{0.9}}},
every head row/.style={before row=\hline,after row=\hline\hline},
every last row/.style={after row=\hline},
columns/A/.style={column type=c},
columns/B/.style={column type=c,column name=$p_{B}$,
postproc cell content/.style={
/pgfplots/table/@cell content/.initial={}{%
\pgfmathparse{int(less(##1,1.0E-05))}
\ifnum\pgfmathresult=1
\textbf{##1}
\else
{##1}
\fi
},
},
},
col sep=comma,
string type]\mytable
\end{document}
答案1
由于您可能希望设置一个非常小的阈值,因此尝试像 这样的组合效率不高30*##1<3E-6
。只需启用fpu
并使用\ifpgfmathfloatcomparison
。(后者似乎没有记录。并且它的朋友\ifpgfmathcomparison
被提及一次。但是你可以看看pgfmathfloat.code.tex
。)
columns/B/.style={column type=c,column name=$p_{B}$,sci,
postproc cell content/.style={
/pgfplots/table/@cell content/.initial={}{%
\pgfkeys{/pgf/fpu=true}
\pgfmathparse{##1<1.0E-06}
\ifpgfmathfloatcomparison
\textbf{##1}
\else
{##1}
\fi
\pgfkeys{/pgf/fpu=false}
},
},
},
再举一个例子: