text background 

> how to shade the background of text gray?
\usepackage{color}
\parbox{\columnwidth}{text text text.}
> in a table?
\usepackage{colortbl}

& RTFM :-)

/usr/share/doc/tetex-doc/latex/carlisle/colortbl.ps.gz

Edward Goldobin

background shading a table row 

Date:          Sun, Jul 8 2001 4:37 pm
Groups:        comp.text.tex
> i can background shade a row of text with the following sequence:
>   \colorbox[gray]{0.90}{\makebox[\textwidth][l]{#1}}
> how can i do that for a row of a tabular-table?

Use the colortbl package. It has a \rowcolor command.

Piet van Oostrum

Shaded table cells 

Date:          Wed, Dec 11 1996 12:00 am
Groups:        comp.text.tex
> Is it possible to shade the background of individual
> cells of a table, ideally with differing gray levels?

Look at David Carlisle's colortbl.sty (on CTAN in macros/latex/contrib/supported/carlisle). It'll also sing and dance for you.

Shaded table cells 

colortbl or colortab packages on ctan. (I prefer the former, but may be biased)

David Carlisle

Need Help on tables 

> What I am looking for is really a way of making a cell or a range of cells
> look different from others.

In colortbl, there are two options are there, one is columncolor and the other is rowcolor. Using this two commands, you will differentiate one column or row from another.

Saravanan,M

Date:          Fri, Nov 26 2004 9:24 pm
Groups:        comp.text.tex

dear latex wizards. I am working pdflatex with color and colortbl. Now, I am trying to get colortbl to really color an entire row. The problem is that I need some @{hspace{}}'s in the tabular control definition to increase some of my column spacing. But \rowcolor{} leaves these spaces white, ignoring the row color. If I define overhang, it happily overpaints some of my numbers in other cells.

one solution might be to get rid of the @{hspace} commands altogether, but this is such a nice feature that I would hate to part with it. is there a better fix?

> definition to increase some of my column spacing.  But \rowcolor{}
> leaves these spaces white, ignoring the row color.

Sounds like a failing. Does it work if you (temporarily) set \extracolsep instead? Nope.

Try it with >{hspace{}}, but remember that @ suppresses \tabsolsep whereas > adds to it.

Well, >{hspace{}} works for one-line entries, but not for paragraph entries. (It just indents the first line.)

A messy solution is

>{\addtolength\leftskip{1cm}}p{<width+1cm>}

Donald Arseneau

Graying every second row of a tabular 

Date:          Thurs, Jul 3 1997 12:00 am
Groups:        comp.text.tex
> Is it possible to shade (i.e., put a gray background behind)
> every second row of a tabular? I want something like this:

Try colortbl.sty from CTAN. For making this alternative shading automatic instead of manual you may need to define your own version of \tabularcr in the table, but try to find out reading the docs of colortbl before taking my guess for it.

David Kastrup

Graying every second row of a tabular 

> > Is it possible to shade (i.e., put a gray background behind)
> > every second row of a tabular? I want something like this:
> Try colortbl.sty from CTAN.  [...]

AFAIK it is also described in the Graphics Companion.

Ryurick M. Hristev

alternate coloing rows with longtable and colortbl 

Date:          Mon, Dec 21 1998 12:00 am
Groups:        comp.text.tex

I'm trying to make a long table and i want to color rows alternatively to make the table more readable. I tryed to use the package ifthen and a new counter to determine in which row i am, but there's no color in the output. LaTeX doesn't complain either :-)

\newcounter{line}
\newcommand{\co}{\addtocounter{line}{1}}
\begin{longtable}{|>{\co\ifthenelse{\isodd{line}}{\rowcolor[gray]{0.95}}{}\bfseries
}l%
|l|l|>{\centering}p{1.5cm}|>{\sc}c|c|}

Where am i wrong? is there another possibility? I'd like to find a better solution than using \rowcolor in every 2 lines, especially if i have to add a row in the table later.

thanks in advance for your help…

alternate coloing rows with longtable and colortbl 

>I'm trying to make a long table and i want to color rows
>alternatively to make the table more readable.

The code we use in the tex-live docs does:

\definecolor{pale}{gray}{.9}
\newcount\colrow
\gdef\RowColor{pale}
\def\SetRowColor{%
 \rowcolor{\RowColor}%
 \global\advance\colrow by1\relax
 \ifodd\colrow
   \gdef\RowColor{pale}%
 \else
   \gdef\RowColor{white}%
 \fi
}

this is in essence identical to what you've done, except that it explicitly sets the colour for every line. the difference is that the table (which is auto-generated from a set of .bib files) has the \SetRowColor command explicitly inserted into each row (by the the \bibitem command, as it happens).

the above code is by seb rahtz; needless to say, david carlisle suggested a neater way still (which i've forgotten). perhaps david will explain why your technique (using a `>-clause') doesn't work and sebastian's does.

Robin Fairbairns

alternate coloing rows with longtable and colortbl 

As discussed at some length in a recent thread on this newsgroup you can't use \ifthenelse before a \multicolumn or similar command in a table. \rowcolor counts as similar to \multicolumn for this purpose.

of the counter rather than the name.

David Carlisle

\documentclass{article}

\def\yy{\\\rowcolor{red}}
\usepackage{colortbl,ifthen}
\newcounter{line}
\newcommand\xx{%
  \addtocounter{line}{1}%
  \ifthenelse{\isodd{\value{line}}}{\\\rowcolor[gray]{0.95}}{\\}}

\begin{document}

\begin{tabular}{lll}
aaa&bbb&ccc\xx
1&2&3\xx
one&two&three\xx
aaa&bbb&ccc\xx
1&2&3\xx
one&two&three\xx
aaa&bbb&ccc\xx
1&2&3\xx
one&two&three\xx
\end{tabular}

\end{document}

colortbl 

Date:          Fri, Apr 25 2003 7:29 am
Groups:        comp.text.tex
> the colortbl package does not produce color along any
> row that contains entries such as \d{o}, \b{o}

Sounds like a bug, but probably in something other than colortbl. Can you produce a minimal but complete demonstration file?

Donald Arseneau

colortbl 

Attaching below a minimal test file. colored rows; all other diacriticals, including the The problem is only with these two diacriticals. A black box (sometimes white) along the row results.

%%%   %test file    %%%%
\documentclass{article}
\usepackage{colortbl}
\definecolor{xx}{cmyk}{.20,0,0,0}
\begin{document}
\begin{tabular}{l}
\rowcolor{xx} colortbl works for all diacriticals
except $\backslash$d \{o\}$ and $\backslash$b \{o\}\\
\rowcolor{xx}with \d{o} the row does not produce color\\
\rowcolor{xx} again \b{o} fails to produce colored row
\rowcolor{xx}But, all other diacriticals \=a, \"a, \c{o},
\t{oo}, \H{o}, \v{o}, \u{o} give colored rows
\end{tabular}
\end{document}

P Narayanaswami

colortbl 

> As I wrote, the presence of either \d{o}, or
> \b{o} in any row (where o is any character) fails to produce
> colored rows;

It is a bug in colortbl. I had expected some accents were defined to use raw \halign without empying \everycr, but colortbl subverts \everycr to prevent it being emptied properly.

The comments in colortbl.dtx give no indication why \everycr has to be subverted instead of just set. Give it a try with this patch

\usepackage{colortbl}
\makeatletter
\let\everycr\CT@everycr % restore proper
\g@addto@macro\CT@start{\CT@hookeverycr}
\def\CT@hookeverycr{%
  \everycr{\noalign{\global\let\CT@row@color\relax}}%
  \def\everycr##1{\let\everycr\CT@everycr}}
\makeatother

Donald Arseneau

colortbl 

The suggestion by Donals Arseneau works fine for multicolum tables. Thanks for all the help.

P Narayanaswami

How to shade table cell(s) in LaTeX 

Date:          Wed, Feb 23 2000 10:00 am
Groups:        comp.text.tex
> So, can anyone suggest an easyish way to shade the background of a given
> table cell in LaTeX?

Use the package "colortbl" (and the "graphicx" package for the gray levels); read the documentations. Something like a single cell.

Maurizio Loreti

How to shade table cell(s) in LaTeX 

> \multicolumn{1}{>{\columncolor[gray]{0.8}}c}{text} should shade
> a single cell.

So that's how! I recently wanted to shade some cells, but when I looked at colortbl I couldn't see how to do an individual cell. (Any chance of getting an easier \cellcolor command, David?)

Donald Arseneau

How to shade table cell(s) in LaTeX 

> > cell.  (Any chance of getting an easier \cellcolor command, David?)
>
> But this is just an instance of the the normal way to make any particular
> cell in a table differ from what is set for the column.  Why should there
> be a special command for it just for color?

Because it is not just that. I choose to look at it as cell *content*, and I wanted to *inherit* the justification from the main table template, not specify it again (possibly incompatibly). And if there were @{} or >{} texts in the template I would want to inherit them too.

Donald Arseneau

\cellcolor extension to David Carlisle's colortbl.sty 

Date:          Tues, Oct 24 2000 9:00 am
Groups:        comp.text.tex

I have created a simple extension to David Carlisle's colortbl.sty that provides a \cellcolor command. As the name suggests, it just colors the current cell. It is very similar to the \rowcolor command and is used and implemented in essentially the same way, except that it can be used at the beginning of any cell, not just the first in a row.

There are probably better (i.e., less redundant) ways to implement this, but it works. Please try it out to see if it breaks anything, and send bugs and suggestions to me.

The diff below is taken with respect to colortbl.sty version 1999/03/24 v0.1i.

Justus Piater

How to get better looking tables from LaTeX 

Date:          Thurs, Jun 10 1993 4:31 pm
Groups:        comp.text.tex
> 3) How about being able to shade an entire box in the table? This would be
> useful on occasion for highlighting titles of columns.

colortab.tex / colortab.sty contains macros for coloring/shading lines or cells in tables. But doesn't actually contain any color commands, but instead is meant to adaptable to anybody's color macros. You can use PSTricks, but some non-PostScript drivers also support color, and you can use it with these drivers as well.

I am appending the latest version.

Timothy Van Zandt

How to get better looking tables from LaTeX 

>2) It would be nice to be able to have a \hline which produced a much wider
>line, possibly shaded rather than full black.

There's an article by Anita Hoover in the next TTN showing how to do this.

>4) How about a double line all around the table, with the correct joins where
>horizontal and vertical lines meet? Similarly for double lines within the
>table.

Put it inside an fbox, twice.

Jeremy Gibbons