Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to set background color in cell of a table in LaTeX??

9,046 views
Skip to first unread message

Peter Jakobi

unread,
Oct 31, 2005, 9:26:30 AM10/31/05
to
Hello,

i am writing on a LaTeX document. There are many tables in it. Now i
want to set the background color of some cells to green or red. Is
there any possibility to set the cell backgound??

Thanks!!

Regards,
Pet

Thomas Becker

unread,
Oct 31, 2005, 10:43:03 AM10/31/05
to
Hi Pet,

you should use the usepackage "colorbtl"
as shown in the following.
You dont need the package "tabularx" better use "booktabs"

\documentclass{article}

\usepackage{tabularx,colortbl}

\begin{document}
\begin{tabularx}{120mm}{l|X} \hline
\rowcolor{red}column 1&column 2\\
row 1&row 1\\
row 2&row 2\\ \hline
\end{tabularx}

Thomas

Peter Jakobi schrieb:

Joachim Schrod

unread,
Oct 31, 2005, 7:23:58 PM10/31/05
to

Thomas referenced already \rowcolor.
There is also \columncolor to set the background of a single cell.

I often define
\newcolumntype{G}{>{\columncolor{lightgray}}}

to be able to use `G' as `grey' column specifier prefix in tabular preambles.
E.g., to write \begin{tabular}{lGll} to get a grey middle column.

Cheers,
Joachim

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Joachim Schrod Email: jsc...@acm.org
Roedermark, Germany

Danie

unread,
Nov 1, 2005, 1:53:41 AM11/1/05
to

Peter Jakobi wrote:
> Hello,
>
> i am writing on a LaTeX document. There are many tables in it. Now i
> want to set the background color of some cells to green or red. Is
> there any possibility to set the cell backgound??

xcolor has a very handy feature that enhances colortbl with alternating
row colors:

\documentclass{article}
\usepackage{colortbl}
\usepackage[table]{xcolor}
\begin{document}
\rowcolors[]{1}{blue!20}{blue!0}
\begin{tabular}{ll}
\rowcolor{red!30}
\textbf{First name} & \textbf{Last name}\\
Els & Danie \\
Smith & John \\
Doe & John \\
Doe & Jane \\
\end{tabular}
\end{document}


Danie Els (dnjels at sun dot ac dot za)

Herbert Voss

unread,
Nov 1, 2005, 2:20:21 AM11/1/05
to
Danie wrote:
> Peter Jakobi wrote:

>>i am writing on a LaTeX document. There are many tables in it. Now i
>>want to set the background color of some cells to green or red. Is
>>there any possibility to set the cell backgound??
>
>
> xcolor has a very handy feature that enhances colortbl with alternating
> row colors:
>
> \documentclass{article}
> \usepackage{colortbl}

this statement is not needed, xcolor loads colortbl anyway
in fact of the option [table]

> \usepackage[table]{xcolor}


Herbert

--
http://TeXnik.de/
http://PSTricks.tug.org/
ftp://ftp.dante.de/tex-archive/info/math/voss/mathmode/Mathmode.pdf
http://www.dante.de/faq/de-tex-faq/
http://www.tex.ac.uk/cgi-bin/texfaq2html?introduction=yes

0 new messages