我正在尝试根据条件有条件地对具有值的表格单元格使用粗体字体。它可以很好地更改文本颜色,如下例所示,但我无法改用粗体字体。有什么想法吗?
\documentclass{standalone}
\usepackage{pgfplotstable}
\pgfplotstableread{
index error
1 2.50000000e-01
2 0.0
3 1.56250000e-01
4 3.90625000e-01
5 0.0
6 2.44140625e-01
}\mytable
\begin{document}
\pgfplotstabletypeset[
percent type/.style={
column type=r,
precision=1,
preproc/expr={100*##1},
postproc cell content/.append style={
/pgfplots/table/@cell content/.add={}{~\%},
},
fixed,
fixed zerofill,
postproc cell content/.append code={%
\pgfkeysgetvalue{/pgfplots/table/@preprocessed cell content}\valueIn
\pgfmathfloatparsenumber{\valueIn}%
\pgfmathfloattofixed{\pgfmathresult}%
\let\value=\pgfmathresult
\ifdim \value pt = 0 pt% if value is zero
\begingroup\edef\temp{\endgroup\noexpand
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\noexpand\color{gray!75}
\pgfkeysvalueof{/pgfplots/table/@cell content}
}}\temp
\fi
}
},
columns/error/.style={percent type}
]{\mytable}
\end{document}
此示例产生以下输出:
答案1
我找到了一种方法,但对我来说这似乎不是最佳解决方案。在 pgfplotstable 中有条件地使用粗体字体所需的源代码是
\documentclass{standalone}
\usepackage{pgfplotstable}
\pgfplotstableread{
index error
1 2.50000000e-01
2 0.0
3 1.56250000e-01
4 3.90625000e-01
5 0.0
6 2.44140625e-01
}\mytable
\begin{document}
\pgfplotstabletypeset[
percent type/.style={
column type=r,
precision=1,
preproc/expr={100*##1},
% postproc cell content/.append style={
% /pgfplots/table/@cell content/.add={}{~\%},
% },
fixed,
fixed zerofill,
postproc cell content/.append code={%
\pgfkeysgetvalue{/pgfplots/table/@preprocessed cell content}\valueIn
\pgfmathfloatparsenumber{\valueIn}%
\pgfmathfloattofixed{\pgfmathresult}%
\let\value=\pgfmathresult
\ifdim \value pt = 0 pt% if value is zero
\begingroup\edef\temp{\endgroup\noexpand
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\noexpand\boldmath
\pgfkeysvalueof{/pgfplots/table/@cell content}~\noexpand\textbf{\%}}}\temp
\else
\begingroup\edef\temp{\endgroup\noexpand
\pgfkeyssetvalue{/pgfplots/table/@cell content}{
\pgfkeysvalueof{/pgfplots/table/@cell content}~\%}}\temp
\fi
}
},
columns/error/.style={percent type}
]{\mytable}
\end{document}
输出结果如下: