[Tugindia] Colored tables in LaTeX involving multirow
Venkatesh Choppella
choppell at gmail.com
Thu Feb 2 08:26:54 CET 2006
Dear Mr. Krishnan,
Thank you for your solution.
The specification I had was slightly different. It had alternate
*rows* of blue and white (instead of columns of blue and white).
With alternate rows, I would like to use a command like
\rowcolors{2}{White}{Blue}
so the solution is more resilient to addition/deletion of rows, but
this doesn't seem to work at all.
I'm enclosing a latex listing consisting of
1. Your solution of colored columns,
2. A solution for alternate colored rows that I made up after looking
at your solution, and
3. a (non) solution using \rowcolor.
Best Regards.
- venkatesh choppella
%%% Example of Colored Tables with multirows. Suggestions
%%% to improve solution(s) are welcome. Please post to
%%% tugindia.tug.org
\documentclass{article}
\usepackage[pdftex,table,fixpdftex]{xcolor}
% \usepackage{array}
% \usepackage{colortbl}
\usepackage{multirow}
\begin{document}
\newcolumntype{r}{>{\columncolor{red!20}}c}
\newcolumntype{g}{>{\columncolor{green!20}}c}
\newcolumntype{b}{>{\columncolor{blue!20}}c}
\newcolumntype{y}{>{\columncolor{yellow!20}}c}
\newcolumntype{w}{>{\columncolor{white!20}}c}
\renewcommand{\multirowsetup}{\centering}
%%%% TABLE WITH BLUE AND WHITE COLUMNS
\begin{center}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{|c|b|c|}
\hline
\multicolumn{1}{|y|}{Yellow}
& \multicolumn{2}{g|}{Green}\\
\hline
\multicolumn{1}{|r|}{}
& Blue & White\\
\cline{2-3}
\multicolumn{1}{|r|}{}
& Blue & White\\
\cline{2-3}
\multicolumn{1}{|r|}{}
& Blue & White\\
\cline{2-3}
\multicolumn{1}{|r|}{%
\multirow{-4}*{Red}}
& Blue & White\\
\hline
& Blue & White\\
\cline{2-3}
& Blue & White\\
\cline{2-3}
& Blue & White\\
\cline{2-3}
\multirow{-4}*{White}
& Blue & White\\
\hline
\end{tabular}
\end{center}
%%%% TABLE WITH ALTERNATING BLUE AND WHITE ROWS
\begin{center}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{|c|c|c|}
\hline
\multicolumn{1}{|y|}{Yellow}
& \multicolumn{2}{g|}{Green}\\
\hline
\multicolumn{1}{|r|}{}
&\multicolumn{1}{|b|}{Blue}
&\multicolumn{1}{|b|}{Blue}\\
\cline{2-3}
\multicolumn{1}{|r|}{}
&\multicolumn{1}{|w|}{White}
&\multicolumn{1}{|w|}{White}\\
\cline{2-3}
\multicolumn{1}{|r|}{}
&\multicolumn{1}{|b|}{Blue}
&\multicolumn{1}{|b|}{Blue}\\
\cline{2-3}
\multicolumn{1}{|r|}{%
\multirow{-4}*{Red}}
&\multicolumn{1}{|w|}{White}
&\multicolumn{1}{|w|}{White}\\
\hline
&\multicolumn{1}{|b|}{Blue}
&\multicolumn{1}{|b|}{Blue}\\
\cline{2-3}
&\multicolumn{1}{|w|}{White}
&\multicolumn{1}{|w|}{White}\\
\cline{2-3}
&\multicolumn{1}{|b|}{Blue}
&\multicolumn{1}{|b|}{Blue}\\
\cline{2-3}
\multirow{-4}*{White}
&\multicolumn{1}{|w|}{White}
&\multicolumn{1}{|w|}{White}\\
\hline
\end{tabular}
\end{center}
%%%% TABLE WITH ALTERNATING BLUE AND WHITE ROWS BUT TRYING
%%%% TO USE \rowcolors or \rowcolor command
% \rowcolors%[\hline] %% DOESN'T WORK!
% {1}{White}{blue!10}
\begin{center}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{|c|c|c|}
\hline
\multicolumn{1}{|y|}{Yellow}
& \multicolumn{2}{g|}{Green}\\
\hline
\rowcolor{blue!20} %% DOESN'T WORK.
%% HOW CAN I FIX IT?
\multicolumn{1}{|r|}{}
Blue & Blue\\
\cline{2-3}
\multicolumn{1}{|r|}{}
&\multicolumn{1}{|w|}{White}
&\multicolumn{1}{|w|}{White}\\
\cline{2-3}
\multicolumn{1}{|r|}{}
&\multicolumn{1}{|b|}{Blue}
&\multicolumn{1}{|b|}{Blue}\\
\cline{2-3}
\multicolumn{1}{|r|}{%
\multirow{-4}*{Red}}
&\multicolumn{1}{|w|}{White}
&\multicolumn{1}{|w|}{White}\\
\hline
&\multicolumn{1}{|b|}{Blue}
&\multicolumn{1}{|b|}{Blue}\\
\cline{2-3}
&\multicolumn{1}{|w|}{White}
&\multicolumn{1}{|w|}{White}\\
\cline{2-3}
&\multicolumn{1}{|b|}{Blue}
&\multicolumn{1}{|b|}{Blue}\\
\cline{2-3}
\multirow{-4}*{White}
&\multicolumn{1}{|w|}{White}
&\multicolumn{1}{|w|}{White}\\
\hline
\end{tabular}
\end{center}
\end{document}
On 2/1/06, E. Krishnan <ekmath at asianetindia.com> wrote:
> On Tue, 31 Jan 2006, CV Radhakrishnan wrote:
>
> > From: Venkatesh Choppella <choppell at gmail.com>
> > To: tugindia at tug.org
> > Date: Tue, 31 Jan 2006 16:56:59 +0530
> > Subject: Colored tables in LaTeX involving multirow
> >
> > Are there a set of good examples of doing colored tables that have
> > cells spanning multiple rows (multirow).
>
> > More specifically, how do I generate a colored table with multirow and
> > multicolumn with indicated background color (and text)
> > entries drawn schematically (in ascii) in the attached file.
>
> Here's a (somewhat crude) way of doing it:
>
> \newcolumntype{r}{>{\columncolor{red}}c}
> \newcolumntype{g}{>{\columncolor{green}}c}
> \newcolumntype{b}{>{\columncolor{blue}}c}
> \newcolumntype{y}{>{\columncolor{yellow}}c}
>
> \renewcommand{\multirowsetup}{\centering}
>
> \begin{center}
> \renewcommand{\arraystretch}{1.5}
> \begin{tabular}{|c|b|c|}
> \hline
> \multicolumn{1}{|y|}{Yellow}
> & \multicolumn{2}{g|}{Green}\\
> \hline
> \multicolumn{1}{|r|}{}
> & Blue & White\\
> \cline{2-3}
> \multicolumn{1}{|r|}{}
> & Blue & White\\
> \cline{2-3}
> \multicolumn{1}{|r|}{}
> & Blue & White\\
> \cline{2-3}
> \multicolumn{1}{|r|}{%
> \multirow{-4}*{Red}}
> & Blue & White\\
> \hline
> & Blue & White\\
> \cline{2-3}
> & Blue & White\\
> \cline{2-3}
> & Blue & White\\
> \cline{2-3}
> \multirow{-4}*{White}
> & Blue & White\\
> \hline
> \end{tabular}
> \end{center}
>
>
>
> --
> Krishnan
>
> _______________________________________________
> Home: http://www.tug.org.in/
> TeX FAQ: http://www.tex.ac.uk/faq
> unsubscribe: http://tug.org/mailman/listinfo/tugindia
>
--
Venkatesh Choppella
choppell at gmail.com
More information about the tugindia
mailing list