I have seen the following code in response to another similar question that works when the numbers in the table are between 0 and 100. How do I have to modify this code so that it works for numbers between 0 and 1 (or any arbitrary range?). My idea is that I need to modify the line:


so that it somehow multiples this by 100, but I can't figure out how to do this.

Here is the full code that works for the numbers given (between 0 and 100) - I would like to do the same for number between 0 and 1. Thanks


    color cells/.style={
        col sep=comma,
        string type,
        postproc cell content/.code={%
                \pgfkeysalso{@cell content=\rule{0cm}{2.4ex}\cellcolor{black!##1}\pgfmathtruncatemacro\number{##1}\ifnum\number>50\color{white}\fi##1}%
            column name={},
            postproc cell content/.code={}

\begin{table}\caption{Correlation or something}
\pgfplotstabletypeset[color cells]{
  • Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Jun 12, 2014 at 20:08
  • 1
    Which one is the question you took this from?
    – percusse
    Jun 12, 2014 at 20:13
  • It's this one "Parametrize shading in table through TikZ". In any case I have copied the full code below:
    – Leo
    Jun 12, 2014 at 20:24
  • Sorry I'm new to this. I have edited the question to include the full code. Thanks
    – Leo
    Jun 12, 2014 at 20:26
  • That code seems to be the one from my answer to Parametrize shading in table through TikZ. There's a much better implementation by Christian Feuersänger at Drawing heatmaps using TikZ
    – Jake
    Jun 13, 2014 at 8:58

1 Answer 1


I've modified Christian's code a bit (basically destroyed visually and converted to a style) to limit the effective range of the macros defined. Otherwise string type columns also pick up the cell content setting directives. This allows to selectively enable the cell coloring.


  /color cells/min/.initial=0,
  /color cells/max/.initial=1000,
  /color cells/textcolor/.initial=,
  color cells/.style={
    postproc cell content/.append code={%
          \pgfkeys{/color cells/.cd,#1}%
      \pgfkeysgetvalue{/pgfplots/table/@preprocessed cell content}\value%
            [\pgfkeysvalueof{/color cells/min}:\pgfkeysvalueof{/color cells/max}]%
            {\value}{\pgfkeysvalueof{/pgfplots/colormap name}}%
        \pgfkeysgetvalue{/pgfplots/table/@cell content}\typesetvalue%
        \pgfkeysgetvalue{/color cells/textcolor}\textcolorvalue%
        \edef\temp{\noexpand\pgfkeyssetvalue{/pgfplots/table/@cell content}{%
            \noexpand\definecolor{mapped color}{rgb}{\pgfmathresult}%

\pgfplotstabletypeset[col sep=comma,
/color cells/max=100,
/color cells/min=0,
/color cells/textcolor=white,
columns/a/.style={color cells},
columns/b/.style={color cells},
columns/c/.style={color cells},
columns/d/.style={color cells},
columns/x/.style={string type},

enter image description here

  • I am using this code to color my cells according to a heatmap. Could someone give me a tip what I need to change in the above code if I additionally want to have the numbers printed in bold? Apr 9, 2017 at 10:04

You must log in to answer this question.

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