我想模仿 Excel 中的 3-Scale 评分格式功能,该功能会根据表格单元格的值更改其背景。
我希望每个单元格都有一个百分比值,并且每个单元格根据它们与 50% 的接近程度逐渐从红色变为绿色。下图显示了我想要的颜色:
我尝试使用发布的文章中的代码希亚沃什但是,这个颜色标度仅基于 2 种颜色。我尝试重写他的代码,以便获得 3 种标度:
% Color set related!
\definecolor{high}{rgb}{0.8500, 0.3250, 0.0980} % the color for the highest number in your data set (Matlab Red)
\definecolor{middle}{rgb}{0.4660, 0.6740, 0.1880} % the color for the highest number in your data set (Matlab Green)
\definecolor{low}{rgb}{0.8500, 0.3250, 0.0980} % the color for the lowest number in your data set (Matlab Red)
\newcommand*{\opacity}{100}% here you can change the opacity of the background color!
%======================================
% Data set related!
\newcommand*{\minval}{40.0}% define the minimum value on your data set
\newcommand*{\midval}{50.0}% define the middle value on your data set
\newcommand*{\maxval}{60.0}% define the maximum value in your data set!
%======================================
% gradient function single cell!
\newcommand{\gradient}[1]{
\pgfmathparse{3*(round(100*(#1/(\maxval-\minval))-(\minval*(100/(\maxval-\minval)))))}
% \pgfmathparse{int(round(100*(#1/(\maxval-\minval))-(\minval*(100/(\maxval-\minval)))))}
\xdef\tempa{\pgfmathresult}
% The values are calculated linearly between \minval and \maxval
\ifdimcomp{#1pt}{>}{\maxval pt}{\cellcolor{high!\opacity} #1}{
\ifdimcomp{#1pt}{<}{\minval pt}{\cellcolor{high!\opacity} #1}{
\ifdimcomp{#1pt}{>}{\midval pt}{\cellcolor{high!\opacity} #1}{
\cellcolor{middle!\tempa!low!\opacity} #1
}}}}
然而,由于某种我不知道的原因,当改变最后一个表的条件时,\ifdimcomp{<dimA>}{<relation>}{<dimB>}{<true>}{<false>}
我的表不起作用。
有人知道如何修复吗?或者有没有更简单的方法让表格有 3 个比例?