I am trying to color table cell depending on the text value imported from the CSV file. The CSV file has three possible text values that are "High", "Intermediate" and "Low". I am trying to color table cell Red if "High" is in cell or yellow if "Intermediate" is in cell or green if "Low" is in a cell.
Test1.csv:
Sign
High
My MWE is below:
\documentclass{report}
\usepackage[a4paper,left=1.9cm,right=1.9cm,top=2cm,bottom=2cm]{geometry}%set margin of page
\usepackage{csvsimple,booktabs,array,filecontents,siunitx}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{color, colortbl}%enable color use in table cell
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}%this will align cell content of table to center via using 'P'
\begin{document}
\begin{center}
{\renewcommand{\arraystretch}{1.5}
\begin{tabular}{| P{3.5cm} | } \rowcolor{cyan!60!black}
\hline
\setlength\tabcolsep{2mm}
\bfseries \rule{0pt}{1pt} \color{white}SIGN% specify table head and its font color
\csvreader[head to column names, late after last line =\\\hline]{./Test1.csv}{}% use head of csv as column names
{\\\hline\csvcoli}% specify your coloumns here
\end{tabular}
}
\end{center}
\end{document}
Here I want the cell color to be red. Similarly, if the cell text value is "Intermediate" the cell color should be yellow, and so on.
This is a similar question Tables: Cell Color based on content / conditional cell coloring at some extent and tried to implement it but did not succeed.
Is there any other way I can achieve this?
Best Answer
Probably
\colorlet
is your friend. ;-)If you need more sophisticated mapping from phrase to color, you can do with delimited arguments: