Graphics, Figures & TablesHow to color a certain row in tabular* environment?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
bobnayar
Posts: 4
Joined: Fri Dec 26, 2008 7:44 am

How to color a certain row in tabular* environment?

Post by bobnayar »

I am trying to color a certain row in a table which has been made using the tabular* environment. The statement I have used for the tabular* is:

\begin{tabular*}{\textwidth}{@{\extracolsep{2cm plus 5cm minus 2cm}}lcl}

and for the rowcolor, I used:

\rowcolor[gray]{.95}

before each row that I needed colored. However the output is such that it appears that discrete cells are colored but there is space between the cells that is NOT colored. I believe the extracolsep is responsible for this, but I don't know how to take care of this. Any help you can provide would be most appreciated.
Thanks

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

bobnayar
Posts: 4
Joined: Fri Dec 26, 2008 7:44 am

How to color a certain row in tabular* environment?

Post by bobnayar »

Since I was not getting a reply to this, I contacted a friend who is a TeX guru and he came up with the following for a row to be colored in tabular* environment:

Put this in preamble:

\usepackage[dvips]{color}
\usepackage{multicol}
\definecolor{Mygrey}{gray}{0.95}

Then put this statement above the line with the row contents that you want colored:

\makebox[0pt][l]{\fboxsep0pt\colorbox{Mygrey} {\strut\hspace*{\linewidth}}}

So, in my case, the relevant code looked like:

\makebox[0pt][l]{\fboxsep0pt\colorbox{Mygrey} {\strut\hspace*{\linewidth}}}
Deposit Money Bank Assets & $dkldby$ & 1.084$^{**}$ \\
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

How to color a certain row in tabular* environment?

Post by localghost »

A much easier way would be to use the colortbl package. It is loaded by the xcolor package when setting a special option.

Code: Select all

\usepackage[table]{xcolor}
More information is given in the according manuals which can be found on CTAN


Best regards
Thorsten¹
Post Reply