3

Following advice seen in other entries about using pgfplotstable on tex.stackexchange.com (such as pgfplotstable: Conditional post-processing of cell content on a per-column basis), I have encountered the puzzling behavior seen below, where I can successfully bold p-values less than 1x10^-4 (see Table 1 image), but the exact same code fails to work if I try to bold only p-values less than 1x10^-5 (see Table 3 image).

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

Imgur

  • While I still don't understand why Table 3 does not format correctly using the above code, I can get it to format correctly if I change the line containing the 'less' comparison to this: \pgfmathparse{int(less(10*##1,1.0E-04))} – Daniel Weeks Apr 15 '15 at 22:01
  • But this does not work correctly/as desired if I increase the '10' to '100' like this: \pgfmathparse{int(less(100*##1,1.0E-04))} – Daniel Weeks Apr 15 '15 at 22:20
  • The incorrect table numbering here is caused by the usage of longtable. To avoid this, instead use longtable* from the caption package as described here – Daniel Weeks Apr 27 '15 at 18:26

1 Answers1

3

Since you may want to set a pretty small threshold, it is not efficient to try out combinations like 30*##1<3E-6. Simply enable fpu and use \ifpgfmathfloatcomparison. (The latter seems to be undocumented. And its friend \ifpgfmathcomparison is mentioned once. However you may take a look at 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}
      },
    },
  }, 

Yet one more example:

Symbol 1
  • 36,855