3

I am trying to conditionally use bold font for table cells with values according to a condition. It works nicely with changing the text color as illustrated in the example below, but I am not able to use bold font instead. Any ideas?

\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}

This example results in the following output:

enter image description here

1 Answers1

1

I found one way of doing this, but it does not seem to be the optimal solution to me. The required source code to conditionally use bold font in pgfplotstable is

\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}

which produces the following output:

enter image description here