I have the following table which uses the S column type of siunitx. The code is given below.
I would like to color the 4th and last columns according to the cell value, i.e. bigger values with a darker cell color, ignoring 0 and the header. I tried to define a new column type P as follows:
\newcommand*{\colorfromval}[3]{\cellcolor{blue!\numexpr (#3-#1)/(#2-#1)\relax}#3}
\newcolumntype{P}[2]{>{\collectcell{\colorfromval{#1}{#2}}}S<{\endcollectcell}}
using the collcell package. However, this does not work. When using the column type on the second column (for testing) as P{0.9}{1.2}, I get the error Forbidden control sequence found while scanning use of \collectcell..
How could I make this work?
Full code for table:
\sisetup{round-mode=places,round-precision=3, scientific-notation = fixed, fixed-exponent = 0,table-format = -1.3}
\begin{tabular}{S[table-format=1, round-precision=0]SSS[scientific-notation = true,table-format = -1.3e-1]SSS[scientific-notation = true,table-format = -1.3e-1]}
\toprule
{$i$} & {$\hat{V}_i$} & {$V_i$} & {$\hat{V}_i-V_i$} & {$\hat{\theta}_i$} & {$\theta_i$} & {$\hat{\theta}_i-\theta_i$} \\
\midrule
1.0000000000000000 & 1.0600513664049058 & 1.0600000000000001 & 0.0000513664049058 & 0.0000000000000000 & 0.0000000000000000 & 0.0000000000000000 \\
2.0000000000000000 & 1.0449150520806798 & 1.0449999999999997 & -0.0000849479193199 & -0.0903780427925868 & -0.0902017440415705 & -0.0001762987510163 \\
3.0000000000000000 & 1.0105441985030748 & 1.0100000000000000 & 0.0005441985030747 & -0.2304605464392513 & -0.2301219110840708 & -0.0003386353551804 \\
4.0000000000000000 & 0.9789355479424200 & 0.9791315016787916 & -0.0001959537363716 & -0.1752380028739756 & -0.1753187387925544 & 0.0000807359185787 \\
5.0000000000000000 & 0.9947345140646511 & 0.9947162540443552 & 0.0000182600202959 & -0.1537094582193175 & -0.1540388428198418 & 0.0003293846005243 \\
6.0000000000000000 & 1.0706559848653179 & 1.0700000000000005 & 0.0006559848653174 & -0.1740028705713847 & -0.1758764990453216 & 0.0018736284739369 \\
7.0000000000000000 & 1.0878678557421266 & 1.0867138686093800 & 0.0011539871327466 & -0.1924014746958308 & -0.1928710973587694 & 0.0004696226629387 \\
8.0000000000000000 & 1.0926370327432411 & 1.0900000000000001 & 0.0026370327432410 & -0.1934253801264002 & -0.1928710973587695 & -0.0005542827676308 \\
9.0000000000000000 & 1.1350111431100269 & 1.1349865824723053 & 0.0000245606377216 & -0.2468347037087413 & -0.2473205248149422 & 0.0004858211062009 \\
10.0000000000000000 & 1.1145990779760711 & 1.1157467646194807 & -0.0011476866434097 & -0.2402510798658636 & -0.2406391973514620 & 0.0003881174855984 \\
11.0000000000000000 & 1.0879593795908786 & 1.0891426622447808 & -0.0011832826539022 & -0.2117229608434851 & -0.2124538791757123 & 0.0007309183322272 \\
12.0000000000000000 & 1.0616622688849244 & 1.0614460024977288 & 0.0002162663871956 & -0.1913550493582837 & -0.1941598017476726 & 0.0028047523893889 \\
13.0000000000000000 & 1.0631476700900693 & 1.0612828680975894 & 0.0018648019924798 & -0.1992471419947266 & -0.2012591555052847 & 0.0020120135105581 \\
14.0000000000000000 & 1.0846952529936669 & 1.0852515529021312 & -0.0005562999084643 & -0.2433305541020903 & -0.2442183053872717 & 0.0008877512851813 \\
\bottomrule
\end{tabular}



