# How to set the background of a section to light gray?

How to set the background of a section to light gray and leave background of content below and above the section as default?

-
Why would right-clicking the cell bracket and looking into the "Background Color" option of the pop-up not work? – J. M. Apr 20 '13 at 5:05
@J.M. I guess OP might want it be gray for not only the background of cells but also spaces between cells. – Silvia Apr 20 '13 at 17:13

Try to group the entire section and set the backround color to gray from the "Writing assistant pallete".

You can also use create your own stylesheet by going to "Format->Edit Stylesheet->Choose a style->Section". Then you change the bckround color to gray using the "Writing assistant pallete". Every time you create a new section, the backround color will be automatically gray

-

If you wish to do this programmatically instead of using the mouse in the front end, you can place the following code after the section you wish to change the color of, then it should select the section and change the background:

SelectionMove[SelectedNotebook[], Previous, CellGroup];
obj = SelectionMove[SelectedNotebook[], Previous, CellGroup]
SetOptions[NotebookSelection[], All, Background -> LightGray]


This could be developed into a button if necessary to be re-used, as it may be a bit clunky to past this in after every section you wish to change the color of.

Note that you can change Previous in the SelectionMove commands to Next if you wish to place this code before the Section to be colored. In addition, this construction can be used to change a variety of other cell styling options.

-
It still has white background in between cells. Is that possible at all to make gray? – qazwsx Apr 30 '13 at 14:12