3

I want to use dec sep align and conditional formatting at the same time. Separately I managed to make them work, but together they double every value in the column.

\documentclass[]{article}
\usepackage{booktabs,pgfplotstable,colortbl}
\begin{document}
    \begin{table}[h!]
            \pgfplotstabletypeset[%
            columns/A/.style={%
                postproc cell content/.style={
                    /pgfplots/table/@cell content/.initial={}{
                        \pgfmathparse{int(less(##1,0))} 
                        \ifnum\pgfmathresult=1
                        \cellcolor{green}{##1}
                        \else
                        {##1}
                        \fi
                    }
                },
                dec sep align,
            },
%           columns/.style={
%               dec sep align
%           },
            col sep=comma
            ]{          ,A,B,C,D
                1,-2.27,-32.94,134.32,-19.92
                2,3.40,13.53,106.51,11.79
                3,-116.5,-6.43,208.59,-0.11
                4,-16.47,-2.38,299.76,-9.76
                }
    \end{table}
\end{document}

which renders the following result

twice rendered values

The commented solution also doesn't work.

Ideally, I would like all columns to respect dec sep align and columns A, B and D to also respect conditional formatting. So far, I managed to get column A to respect conditional formatting, but only if I don't also use dec sep align at the same time.

Is it a bug that dec sep align cannot be used with conditional formatting or I just didn't get it how to use them?

1 Answer 1

2

Check out the footnote on page 12 of the current pgfplotstable manual. Looks like dec sep align doesn't play well with \cellcolor.

As for the double entry, the dec sep align option splits the entry into two columns, to which your post proc is applied. Using .initial and adding ##1 overwrites the parsed entries with the original, resulting in the double entry. Using add and removing the ##1 allows the split by doc sep align to persist; however, the \cellcolor is larger than necessary and the second cell covers a bit of the first (I presume this is the overhang mentioned in the manual):

\documentclass[]{article}
\usepackage{booktabs,pgfplotstable,colortbl,siunitx}
\begin{document}
    \begin{table}[h!]
            \pgfplotstabletypeset[%
            columns/A/.style={
                postproc cell content/.style={
                    /pgfplots/table/@cell content/.add={}{
                        \pgfmathparse{int(less(##1,0))} 
                        \ifnum\pgfmathresult=1
                        \cellcolor{green}
                        \fi
                    }
                },
                dec sep align={c}},
            columns/B/.style={dec sep align={c}},
            columns/C/.style={dec sep align={c}},
            columns/D/.style={dec sep align={c}},
            col sep=comma
            ]{          ,A,B,C,D
                1,-2.27,-32.94,134.32,-19.92
                2,3.40,13.53,106.51,11.79
                3,-116.5,-6.43,208.59,-0.11
                4,-16.47,-2.38,299.76,-9.76
                }
    \end{table}
\end{document}

enter image description here

1
  • 1
    /.append code is the shorthand for /.add={}{...}
    – percusse
    Nov 2, 2015 at 13:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .