Paul A. Rubin wrote:
The following works for me (using package xcolor, which in turn calls
colortbl).
1. In the preamble: \usepackage[table]{xcolor}.
2. In ERT before the table: \rowcolors{1}{gray}. (The first argument
says to start coloring in row 1, the second sets the background color.)
3. Right click in any multicolumn cell and put the following in the
LaTeX command box: |>{\columncolor{gray}}c|. The 'c' is to center
horizontally (use 'l' or 'r' for left or right); this inclusion
apparently overrides the horizontal alignment specified in the drop-down
list of the LyX dialog, and omitting it seems to cause a LaTeX error.
The two '|' characters are replace the left and right cell borders (if
either or both are deleted); include or omit as needed. Note that you
apparently need to close the table dialog for these changes to take effect.
it is also possible to define own column types. See example, which
does the same. The only advantage is, that you get rid of the
ERT, but have to define special column types C and M
Herbert
#LyX 1.3 created this file. For more info see http://www.lyx.org/
\lyxformat 221
\textclass article
\begin_preamble
\usepackage[table]{xcolor}
\newcolumntype{C}{>{\columncolor{gray}}c}
\newcolumntype{M}{>{\cellcolor{gray}}c}
\end_preamble
\language english
\inputencoding auto
\fontscheme default
\graphics default
\paperfontsize default
\spacing single
\papersize Default
\paperpackage a4
\use_geometry 0
\use_amsmath 0
\use_natbib 0
\use_numerical_citations 0
\paperorientation portrait
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\defskip medskip
\quotes_language english
\quotes_times 2
\papercolumns 1
\papersides 1
\paperpagestyle default
\layout Standard
\begin_inset Tabular
<lyxtabular version="3" rows="3" columns="3">
<features>
<column alignment="center" valignment="top" leftline="true" rightline="true"
width="0" special="|C">
<column alignment="center" valignment="top" leftline="true" rightline="true"
width="0" special="|C">
<column alignment="center" valignment="top" leftline="true" rightline="true"
width="0" special="|C|">
<row topline="true" bottomline="true">
<cell alignment="center" valignment="top" topline="true" leftline="true"
usebox="none">
\begin_inset Text
\layout Standard
a
\end_inset
</cell>
<cell multicolumn="1" alignment="left" valignment="top" topline="true"
bottomline="true" leftline="true" rightline="true" usebox="none" special="|M|">
\begin_inset Text
\layout Standard
b c
\end_inset
</cell>
<cell multicolumn="2" alignment="center" valignment="top" topline="true"
leftline="true" rightline="true" usebox="none">
\begin_inset Text
\layout Standard
\end_inset
</cell>
</row>
<row topline="true">
<cell alignment="center" valignment="top" topline="true" leftline="true"
usebox="none">
\begin_inset Text
\layout Standard
d
\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true"
usebox="none">
\begin_inset Text
\layout Standard
e
\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true"
rightline="true" usebox="none">
\begin_inset Text
\layout Standard
f
\end_inset
</cell>
</row>
<row topline="true" bottomline="true">
<cell multicolumn="1" alignment="center" valignment="top" topline="true"
bottomline="true" leftline="true" usebox="none" special="|M|">
\begin_inset Text
\layout Standard
g h
\end_inset
</cell>
<cell multicolumn="2" alignment="center" valignment="top" topline="true"
leftline="true" usebox="none">
\begin_inset Text
\layout Standard
\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true"
rightline="true" usebox="none">
\begin_inset Text
\layout Standard
i
\end_inset
</cell>
</row>
</lyxtabular>
\end_inset
\the_end