[Tex/LaTex] Cell colouring a multirow in LyX

colorlyxmultirowtables

I've got a multirow cell and I need to make it all have one background colour, but I'm having trouble achieving this. I've defined my color (lightgreen) in the preamble, but don' know how to apply it to the multirow. So, in LyX I've got this Tex Code:

\multirow{8}{2.5cm}{

Then of course I've got my text, which isn't in a Tex Code block, following by

}

I've tried putting \cellcolor{lightgreen} in various places with mixed results, but usually it only colours the top row of the multirow.

I realise that there are a few similar questions to this on here, but they are all written in LaTeX directly, rather than in LyX. I don't know LaTeX really and don't really have time to learn it fully right now, so any help getting this to work in LyX would be greatly appreciated!

Best Answer

The method suggested by Gonzalo Medina in a comment works also in LyX.

Having created your table, add an ERT (TeX code box, with Ctrl + L) and type \cellcolor{LightGreen} in the first cell that your multirow should cover. Copy this ERT to the rest of the cells, and in the bottom one, write \multirow{-8}{2.5cm}{<your text>} after the \cellcolor. Note the negative number in the first argument.

In addition, you have to remove the lines above/below the cells that are part of the multirow with the buttons on the toolbar:

enter image description here

If not, the lines will be above the colored area.

LyX and PDF-view (click to enlarge): enter image description here

A final note (you are probably aware of this):

Unless the multirow feature in LyX has been used elsewhere, you have to add that package to the preamble, in Document --> Settings --> LaTeX preamble. The xcolor package with the table option must be loaded to be able to color the cells:

\usepackage{multirow} 
\usepackage[table]{xcolor}