I suggest you simply set up two separate tabular
environments, with one row of each tabular
(likely the header row) containing information about the (ex-ante fixed) width of each column.
In the following example, vertical lines are used in each tabular
purely to demonstrate that they line up across the two environments.
\documentclass{article}
\usepackage{siunitx}
\newlength{\mylen}
\setlength{\mylen}{1in} % desired width of first column
\newcommand\slug{\hphantom{123456}} % set desired width of "slug" used in column 2
\begin{document}
\begin{center}
\begin{tabular}{|l|S[table-format=3.2]|}
\multicolumn{1}{|p{\mylen}|}{\textbf{Part 1}} & {\slug} \\
Number & 100 \\
Number & 2.00 \\
\end{tabular}\\[-0.25ex] % snug up the two tabulars
\begin{tabular}{|r|S[table-format=1]|}
\multicolumn{1}{|p{\mylen}|}{\textbf{Part 2}} & {\slug} \\
Right & 1 \\
Right & 10 \\
\end{tabular}
\end{center}
\end{document}
Probably \colorlet
is your friend. ;-)
\begin{filecontents*}{Test1.csv}
Sign
High
Intermediate
Low
\end{filecontents*}
\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'
\colorlet{High}{red}
\colorlet{Intermediate}{yellow}
\colorlet{Low}{green}
\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\expandafter\cellcolor\expandafter{\romannumeral`\^^@\csvcoli}\csvcoli}% specify your coloumns here
\end{tabular}
}
\end{center}
\end{document}
If you need more sophisticated mapping from phrase to color, you can do with delimited arguments:
\begin{filecontents*}{Test1.csv}
Sign
High
Intermediate
Low
\end{filecontents*}
\makeatletter
\@ifdefinable\@gobbletoexclam{\long\def\@gobbletoexclam#1!{}}%
\newcommand\exchange[2]{#2#1}%
%
% \mycolormapping{<Tokens>}{<s.th. that expands to one of the phrases High/Intermediate/Low>}
% -> <Tokens>{red}
% or <Tokens>{yellow}
% or <Tokens>{green}
% or <nothing>
%
\newcommand\mycolormapping[2]{%
% Expand #2 until encountering a non-expandable token.
% (If that non-expandable token is a space-token it will be discarded.)
% Then call the mapping-routine.
\expandafter\exchange\expandafter{\expandafter{\romannumeral`\^^@#2}}{\@mycolormapping{#1}}%
}%
\newcommand\@mycolormapping[2]{%
% Check whether #2 does contain "!". If so it is not one of the phrases
% High/Intermediate/Low but it could be a phrase which erroneously
% matches up delimiters due to containing (parts of) the delimiter "!High!Intermediate!Low!".
% If not so, apply the macro \mycolormappingfork which via delimited arguments
% cranks out the right cases.
\ifcat$\detokenize\expandafter{\@gobbletoexclam#2!}$%
\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{%
\mycolormappingfork!#2!Intermediate!Low!{#1{red}}%
!High!#2!Low!{#1{yellow}}%
!High!Intermediate!#2!{#1{green}}%
!High!Intermediate!Low!{}%
!!!!%
}{}%
}%
\@ifdefinable\mycolormappingfork{%
% Let \mycolormappingfork grab the argument #2 behind a
% delimiter "!High!Intermediate!Low!". Stuff before that
% delimiter is removed as unused #1. Stuff behind the
% second argument is removed as unused `!!!!`-delimited
% argument #3. The delimiter in turn is completed by
% \@mycolormapping's second argument. Depending on which
% of the sequences "!#2!Intermediate!Low!",
% "!High!#2!Low!", "!High!Intermediate!#2!",
% "!High!Intermediate!Low!" matches the delimiter you can
% crank out which of the phrases `High`, `Intermediate`
% or `Low` was provided via \@mycolormapping's #2. The
% last one, "!High!Intermediate!Low!", is for the case
% that \@mycolormapping's #2 formed neither of these
% phrases.
\long\def\mycolormappingfork#1!High!Intermediate!Low!#2#3!!!!{#2}%
}%
\makeatother
\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'
\colorlet{High}{red}
\colorlet{Intermediate}{yellow}
\colorlet{Low}{green}
\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\mycolormapping{\cellcolor}{\csvcoli}\csvcoli}% specify your coloumns here
\end{tabular}
}
\end{center}
\end{document}
Best Answer
You could use pgfplotstable and the
xcolor
package with the[table]
option, which gives you the\cellcolor
command.Here's a new style for
\pgfplotstabletypeset
that colors the cell a different shade of gray according to the cell value, and prints the value in white if the background is more than 50% black.The command
will then give you (shown here with a caption)