3

I want to generate a table based on an input data. For those cell with value (x) less than 5, it is supposed to be with gray background, and the value is changed to x+3. The code I use is

columns/C/.style={
postproc cell content/.append code={
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\cellcolor{lightgray}{##1}}
      }

It can generates the gray background, but I have no idea to change the value at the same time. If I replace {##1} with {##1+3}, it doesn't work. I am wondering if there's a way to change the value. Thanks.

1 Answer 1

2

You need to test and perform arithmetic. Here is one way to test and another way to do simple operations. Otherwise you need pgfmath or any other math package.

\documentclass{standalone}
\usepackage{pgfplotstable,colortbl}
\pgfplotstableread{
C  D  
1  5  
2  5  
4  10 
5  10 
7  15 
}\mytable

\begin{document}
\pgfplotstabletypeset[
columns={C,D},
columns/C/.style={
postproc cell content/.append code={
\ifdim##1pt<5pt %
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\cellcolor{lightgray}{\number\numexpr##1+3\relax}}
\fi}}
]\mytable
\end{document}

enter image description here

You must log in to answer this question.

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