[Tex/LaTex] Column color using the colortbl package

colortbltables

I'm trying to regenerate the example output on page 2 in the manual for the colortbl package.

Using the \columncolor command how can I construct the example image shown below? I'm starting with the code shown further down on the page.

Example generated with the colortbl package.

From the manual:

The basic format is:

\columncolor[<color model>]{<colour>}[<left overhang>][<right overhang>]

The first argument (or first two if the optional argument is used) are standard
color package arguments, as used by \color.

The last two arguments control how far the panel overlaps past the widest
entry in the column. If the right overhang argument is omitted then it defaults to left overhang. If they are both omitted they default to \tabcolsep (in tabular) or \arraycolsep (in array).

If the overhangs are both set to 0pt then the effect is as Table 1 in the image above

|>{\columncolor[gray]{.8}[0pt]}l|
 >{\color{white}%
  \columncolor[gray]{.2}[0pt]}l|

The default overhang of \tabcolsep produces Table 2 in the image above

|>{\columncolor[gray]{.8}}l|
 >{\color{white}%
  \columncolor[gray]{.2}}l|

You might want something between these two extremes. A value of .5\tabcolsep
produces the following effect, e.g. Table 3 in the image above.

|>{\columncolor[gray]{.8}[.5\tabcolsep]}l|
 >{\color{white}%
  \columncolor[gray]{.2}[.5\tabcolsep]}l|

This package should work with most other packages that are compatible with
the array package syntax.

This is my starter code:

\documentclass[]{book}

\usepackage{color}
\usepackage{colortbl}
\usepackage{array}

\begin{document}

    \begin{tabular}{|l|c|}
        one & two\\
        three & four
    \end{tabular}

    \vskip 10mm 

    \begin{tabular}{|l|c|}
        one & two\\
        three & four
    \end{tabular}

    \vskip 10mm 

    \begin{tabular}{|l|c|}
        one & two\\
        three & four
    \end{tabular}       

\end{document}

Best Answer

I've just used the tabular column specification you supplied:

enter image description here

\documentclass{article}

\usepackage[table]{xcolor}

\begin{document}

Table~1 \qquad
%\begin{tabular}{ |l|l| }
\begin{tabular}{
  |>{\columncolor[gray]{.8}[0pt]}l|
   >{\color{white}%
    \columncolor[gray]{.2}[0pt]}l|
  }
  one   & two \\
  three & four
\end{tabular}

\bigskip

Table~2 \qquad
%\begin{tabular}{ |l|l| }
\begin{tabular}{
  |>{\columncolor[gray]{.8}}l|
   >{\color{white}%
    \columncolor[gray]{.2}}l|
  }
  one   & two \\
  three & four
\end{tabular}

\bigskip

Table~3 \qquad
%\begin{tabular}{ |l|l| }
\begin{tabular}{
  |>{\columncolor[gray]{.8}[.5\tabcolsep]}l|
   >{\color{white}%
    \columncolor[gray]{.2}[.5\tabcolsep]}l|
  }
  one   & two \\
  three & four
\end{tabular}

\end{document}
Related Question