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

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


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.

C  D  
1  5  
2  5  
4  10 
5  10 
7  15 

postproc cell content/.append code={
\ifdim##1pt<5pt %
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\cellcolor{lightgray}{\number\numexpr##1+3\relax}}

enter image description here

You must log in to answer this question.

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