Graphics, Figures & TablesColor for Table Cells spanning multiple Rows

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Sky
Posts: 3
Joined: Sun Mar 17, 2013 8:45 pm

Color for Table Cells spanning multiple Rows

Post by Sky »

Hello,

I'm doing a table in LaTeX, but I'm having some serious problems in order to color the two last rows in the third column. I would like this cell to be gray, even though it isn't possible when I compile the file to PDFLaTeX. I have loaded the color, colorbl and multirow packages in the preamble, but it doesn't work.

Besides, once it's compiled, the program I'm using (Texmaker) shows the following error message.

Code: Select all

! Misplaced \omit.\multispan->\omit@\multispan...\multicolumn{1}{|<{\columncolor{Gray}}|}}
Here is the table code.

Code: Select all

\begin{table}
\begin{tabular}{|c|c|c|c|}
\hline
Professors & Despatx & Hores de classe & Tutories \\
\hline
Mary & C1/352 & dl. i dc. de 9 a 10 & dt. de 15 a 17 \\
\hline
John & C1/120 & dv. de 11 a 13 & dj. de 10 a 11 \\
\hline
Louie & C1/214 & \multirow{2}{*}{\multicolumn{1}{|>{\columncolor{Gray}}c|}} & \multirow{2}{*}{dl. de 16 a 18} \\
\cline{1-2}
Peter & C1/364 & & \\
\hline

\end{tabular}
\caption{Despatxos, correus i horaris dels professors}
\label{profes}
\end{table}
I would be grateful if you could help me identify the problem with my code, as I'm a newbie in LaTeX. Sorry for the inconvenience and thank you for your attention.

Sky :)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Color for Table Cells spanning multiple Rows

Post by Stefan Kottwitz »

Hi Sky,

welcome to the board!

If you nest \multirow and \multicolumn, it works only with \multirow inside the argument of \multicolumn, not the other way round.

So this corrected table row would be error-free:

Code: Select all

Louie & C1/214 & \multicolumn{1}{|>{\columncolor{Gray}}c|}{\multirow{2}{*}{}}
  & \multirow{2}{*}{dl. de 16 a 18} \\
Btw. if you post code, please always add the few lines to make it compilable. So readers who would like to help can really work on it - make it easier for them to help you.

Stefan
LaTeX.org admin
Sky
Posts: 3
Joined: Sun Mar 17, 2013 8:45 pm

Re: Color for Table Cells spanning multiple Rows

Post by Sky »

Thank you very much for your reply Stefan_K! However, I have tried compiling it, but only one of both rows is colored. How would I have to write it if I wanted to color both rows?

By the way, thanks for the advice on the add-a-few-lines-to-make-the-code-compilable! I'll try to do that next time!
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Color for Table Cells spanning multiple Rows

Post by Stefan Kottwitz »

I noticed that, but the table design looked already bad, so I didn't comment further. Have a look at the booktabs manual to read about table design.

Just yesterday Nicola Talbot cited the Oxford Style Manual:
Most publishers omit as superfluous all vertical rules in tables. If correctly spaced and aligned, presentation is clearer and less cluttered without them: only tables with extremely complex internal structures benefit from them.
Have a look at good real books in your field of science. No theses. No Excel printouts where the printer forgot to disable printing of the help lines grid. ;-)

Stefan
LaTeX.org admin
Sky
Posts: 3
Joined: Sun Mar 17, 2013 8:45 pm

Re: Color for Table Cells spanning multiple Rows

Post by Sky »

Thanks for your answer Stephan_K!

I hope you have a great day!
Post Reply