Deyan Ginev edited subsubsection_Backgrounds_for_Individual_Cells__.tex  almost 9 years ago

Commit id: a6a2443779435f71db52a61359b8922199122047

deletions | additions      

       

Setting the background color of a column can be achieved indirectly via the \verb|\newcolumntype| macro, which defines a new column type. That new type could be based on an existing column specification (e.g. the "centered" \verb|c|), with a modified background color via the \verb|\columncolor| macro. In case a row or column background color needs to be overridden, the cell-specific \verb|\cellcolor| macro comes to the rescue. Here is an illustrating example that puts all of these techniques together:  \begin{lstlisting}  % Define some custom colors  \colorlet{FreshGray}{gray!20!white}  \colorlet{FreshGreen}{green!20!white}  \colorlet{FreshYellow}{yellow!20!white}  \colorlet{FreshRed}{red!20!white}  % Define shorthand macros for coloring individual cells  \def\okcell{\cellcolor{FreshGreen}}  \def\avgcell{\cellcolor{FreshYellow}}  \def\badcell{\cellcolor{FreshRed}}  \def\nocell{\cellcolor{FreshGray}}  % A new column type, adding a FreshGray background to the centered type  \newcolumntype{g}{>{\columncolor{FreshGray}}c}  \begin{tabular}{ |g|c|c|c|c| }  \hline