Graphics, Figures & TablesColoured multirows

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
eiterorm
Posts: 24
Joined: Fri Dec 25, 2009 6:40 pm

Coloured multirows

Post by eiterorm »

Hi!
I wish to make a table with multirows and colours corresponding to my examples given below, which I assume are fairly comprehensible.

Described in words I want the cells in the leftmost column to span varying numbers of rows, in addition to being every other white and grey. Furthermore, I want the rows in the rest of the columns to be every other white and grey as well.

I tried using "\rowcolors{1}{white}{lightgray}" in the table, but that did not work well together with the row spanning in the leftmost column.

Is there a way of defining every other (spanned) cell white and grey in a single column? Defining the colour of every cell seems like a lot of unnecessary work.

This table is also going to span several pages, (I have left that out of my code for simplicity) so manually drawing a table on every page is not an option.

Thanks!
example.png
example.png (6.15 KiB) Viewed 17186 times

Code: Select all

\documentclass[11pt, a4paper]{article}
\usepackage[top=3.5cm, bottom=3.5cm, left=2cm, right=2cm]{geometry}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern,microtype}
\usepackage{multirow}
\usepackage[table]{xcolor}
\pagestyle{empty}

\begin{document}

\begin{table}[htbp]
\centering
\begin{tabular}{ |p{0.25\textwidth}|*{2}{p{0.32\textwidth}|} }
\hline
\multirow{5}{*}{white}
	& white	& white	\\
 	& grey	& grey	\\
 	& white	& white	\\
 	& grey	& grey	\\
 	& white	& white	\\ \hline
\multirow{4}{*}{grey}
	& grey	& grey	\\
	& white	& white	\\
	& grey	& grey	\\
	& white	& white	\\ \hline
\multirow{3}{*}{white}
	& grey	& grey	\\
	& white	& white	\\
	& grey	& grey	\\ \hline
\end{tabular}
\end{table}

\end{document}
Last edited by eiterorm on Sun Feb 07, 2010 1:00 am, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
eiterorm
Posts: 24
Joined: Fri Dec 25, 2009 6:40 pm

Coloured multirows

Post by eiterorm »

While bumping, I might also add that even colouring each cell does not work well with multirows. When colouring a cell which spans multiple rows, you have to colour each and every row to entirely colour the spanned cell. However, when you do this, the text disappears, as shown below.

So I wonder, as before, if there is an easy way to colour a table according to my previous post.
output.pdf
(24.3 KiB) Downloaded 899 times

Code: Select all

\documentclass[11pt, a4paper]{article}
\usepackage[top=3.5cm, bottom=3.5cm, left=2cm, right=2cm]{geometry}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern,microtype}
\usepackage{multirow}
\usepackage[table]{xcolor}
\pagestyle{empty}

\begin{document}

\begin{table}[htbp]
\centering
\begin{tabular}{ |p{0.25\textwidth}|*{2}{p{0.32\textwidth}|} }
\hline
\multirow{5}{*}{white}
	& white	& white	\\
 	& grey	& grey	\\
 	& white	& white	\\
 	& grey	& grey	\\
 	& white	& white	\\ \hline
\multirow{4}{*}{grey}
\cellcolor{lightgray}	& grey	& grey	\\
\cellcolor{lightgray}	& white	& white	\\
\cellcolor{lightgray}	& grey	& grey	\\
\cellcolor{lightgray}	& white	& white	\\ \hline
\multirow{3}{*}{white}
	& grey	& grey	\\
	& white	& white	\\
	& grey	& grey	\\ \hline
\end{tabular}
\end{table}

\end{document}
eiterorm
Posts: 24
Joined: Fri Dec 25, 2009 6:40 pm

Re: Coloured multirows

Post by eiterorm »

Still nobody knows how I can solve this?
Johandicap
Posts: 3
Joined: Thu Sep 04, 2008 11:44 am

Coloured multirows

Post by Johandicap »

Hi eiterorm,

I was facing the same problem as you and found the answer on a German forum!
http://www.matheplanet.com/matheplanet/ ... pic=109770

I guess my mandatory German classes in elementary school paid off after all :)

The problem is that table cells below the multirow cell are 'painted' after the text has been written. This is easy to see if you try a \multirow{2}{*}{Test} where you'll see only the upper half of the text!

The solution is to use a negative multirow argument and place it in the bottom cell, e.g.

Code: Select all

\multirow{-2}{*}{Text on colored background}
Very simple but still what I would call a workaround.

Greetings,
Johan from Denmark
eiterorm
Posts: 24
Joined: Fri Dec 25, 2009 6:40 pm

Coloured multirows

Post by eiterorm »

Hi, Johan! Thanks for the reply.

I tried the workaround with the pdflatex compiler, and I have attached the output below. It doesn't seem to work too well, as it, for some reason, interferes with the text placement in the column. The code used to generate the output is the same as the one in my previous post, only with

Code: Select all

\multirow{-4}{*}{grey}
placed below the spanned cell.
output2.pdf
(24.3 KiB) Downloaded 903 times
spiderman2
Posts: 3
Joined: Sat Jan 10, 2009 11:55 am

Coloured multirows

Post by spiderman2 »

Thanks a lot, even if it didn't seem to help the original poster this worked for me with pdflatex and 2-row spanning.

Best regards,
Henrik
Johandicap wrote:Hi eiterorm,

I was facing the same problem as you and found the answer on a German forum!
http://www.matheplanet.com/matheplanet/ ... pic=109770

I guess my mandatory German classes in elementary school paid off after all :)

The problem is that table cells below the multirow cell are 'painted' after the text has been written. This is easy to see if you try a \multirow{2}{*}{Test} where you'll see only the upper half of the text!

The solution is to use a negative multirow argument and place it in the bottom cell, e.g.

Code: Select all

\multirow{-2}{*}{Text on colored background}
Very simple but still what I would call a workaround.

Greetings,
Johan from Denmark
Golgor
Posts: 1
Joined: Mon May 21, 2012 10:22 pm

Coloured multirows

Post by Golgor »

Hello there!
I know this is a pretty late answer, but I found an answer to your problem and felt like sharing. The example code below will create a table exactly as your picture in the top post. Hope this helps someone! :)

Code: Select all

\begin{table}[htbp]
\caption{Table with gray and white.}
\begin{center}
\begin{tabular}{lcccl}
                                                				& Column 1	& Column 2	& Column 3			& Column 4              	\\ \rowcolor{lightgray}
                                                				& PM		& 1		& 2				& 28				\\
\multicolumn{1}{>{\columncolor{lightgray}}l}{}  				& PD		& 3		& 4				& 29				\\ \rowcolor{lightgray}
                                                				& PM		& 5		& 6				& 30				\\ 
\multicolumn{1}{>{\columncolor{lightgray}}l}{\multirow{-4}{*}{Gray}}		& PD		& 7		& 8				& 31				\\ \rowcolor{lightgray}


\multicolumn{1}{>{\columncolor{white}}l}{}  					& PM		& 9		& 10				& 32				\\
                                            					& PM		& 11		& 12				& 33				\\ \rowcolor{lightgray}
\multicolumn{1}{>{\columncolor{white}}l}{}  					& PD	        & 13		& 14				& 34				\\
                                            					& PM		& 15		& 16				& 35				\\ \rowcolor{lightgray}
\multicolumn{1}{>{\columncolor{white}}l}{\multirow{-5}{*}{White}}  		& PD		& 17		& 18				& 36				\\


\multicolumn{1}{>{\columncolor{lightgray}}l}{}  				& P1		& 20		& 21				& 37				\\ \rowcolor{lightgray}
                                                				& P2		& 22		& 23				& 38				\\
\multicolumn{1}{>{\columncolor{lightgray}}l}{}  				& P3		& 24		& 25				& 39				\\ \rowcolor{lightgray}
\multicolumn{1}{>{\columncolor{lightgray}}l}{\multirow{-4}{*}{Gray}}    	& P4		& 26		& 27				& 40				\\

\end{tabular}
\end{center}
\end{table}
eiterorm
Posts: 24
Joined: Fri Dec 25, 2009 6:40 pm

Coloured multirows

Post by eiterorm »

Golgor wrote:Hello there!
I know this is a pretty late answer, but I found an answer to your problem and felt like sharing. The example code below will create a table exactly as your picture in the top post. Hope this helps someone! :)
This example is exactly what I was looking for. Thanks a lot for sharing! =)
Post Reply