Deyan Ginev edited subsubsection_Backgrounds_for_Individual_Cells__.tex  almost 9 years ago

Commit id: 909c1afd6a087da4836a7bf9a5ce44c281439af9

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 \begin{table}[h!]  \newcolumntype{g}{>{\columncolor{FreshGray}}c}  \begin{tabular}{ |g|c|c|c|c| }  \hline 

In-place merge Sort & \nocell -- & \nocell -- & \avgcell $n \log^2(n)$ & \okcell 1 \\  \hline  \end{tabular}  \end{lstlisting}  %%% \end{table}  Source for the tabular data: \url{http://en.wikipedia.org/wiki/Sorting_algorithm}  \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}}  \begin{table}[h!] % 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 

In-place merge Sort & \nocell -- & \nocell -- & \avgcell $n \log^2(n)$ & \okcell 1 \\  \hline  \end{tabular}  \end{table}  Source for the tabular data: \url{http://en.wikipedia.org/wiki/Sorting_algorithm} \end{lstlisting}  %%%