-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighlight.sty
44 lines (44 loc) · 1.93 KB
/
highlight.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
% Siavoosh Payandeh Azad Jan. 2019
\ProvidesPackage{highlight}[Cell background highlighting based on user data]
\RequirePackage{etoolbox}
\RequirePackage{pgf} % for calculating the values for gradient
\RequirePackage{xcolor} % enables the use of cellcolor make sure you have [table] option in the document class
% Color set related!
\definecolor{high}{HTML}{ef3b2c} % the color for the highest number in your data set
\definecolor{low}{HTML}{fff7bc} % the color for the lowest number in your data set
\newcommand*{\opacity}{90}% here you can change the opacity of the background color!
%======================================
% Data set related!
\newcommand*{\minval}{0.0}% define the minimum value on your data set
\newcommand*{\maxval}{1.0}% define the maximum value in your data set!
%======================================
% gradient function!
\newcommand{\gradient}[1]{
% The values are calculated linearly between \minval and \maxval
\ifdimcomp{#1pt}{>}{\maxval pt}{#1}{
\ifdimcomp{#1pt}{<}{\minval pt}{#1}{
\pgfmathparse{int(round(100*(#1/(\maxval-\minval))-(\minval*(100/(\maxval-\minval)))))}
\xdef\tempa{\pgfmathresult}
\cellcolor{high!\tempa!low!\opacity}
}}
}
%\newcommand{\gradient}[1]{
% % The values are calculated linearly between \minval and \maxval
% \ifdimcomp{#1pt}{>}{\maxval pt}{#1}{
% \ifdimcomp{#1pt}{<}{\minval pt}{#1}{
% \pgfmathparse{int(round(100*(#1/(\maxval-\minval))-(\minval*(100/(\maxval-\minval)))))}
% \xdef\tempa{\pgfmathresult}
% \cellcolor{high!\tempa!low!\opacity} #1
% }}
% }
%======================================
% gradient function single cell!
\newcommand{\gradientcell}[6]{
% The values are calculated linearly between \minval and \maxval
\ifdimcomp{#1pt}{>}{#3 pt}{#1}{
\ifdimcomp{#1pt}{<}{#2 pt}{#1}{
\pgfmathparse{int(round(100*(#1/(#3-#2))-(\minval*(100/(#3-#2)))))}
\xdef\tempa{\pgfmathresult}
\cellcolor{#5!\tempa!#4!#6} #1
}}
}