# Can I prevent changing the background color from changing the cell spacing?

The first image shows what my list of items looks like with no background color. The second shows what setting the background color to light green does to the cell spacing. That is not what I want. I want the cell spacing shown in the first image, with the background color shown in the second image.

Is there a global setting accomplish that goal?

• Which stylesheet are you using and what styles do those cells have? – Kuba Jan 9 at 8:38
• This cells are from a notebook with a customized style sheet based on the Textbook style sheet. But the problem occurs in the default style sheet as well. The style in the cells in the images is "Item1". In the standard style sheet it is "Item". But this behavior is not unique to "Item" style. I happens with most, if not all, other styles that I typically use. – Steven Thomas Hatton Jan 9 at 8:52

There is a 'funny' dependency between Background, CellFrame and CellFrameMargins.

Let's quote ref/CellFrameMargins details and options:

• CellFrameMargins defines the margins for the box used to draw the background color of a cell. The margins will be used to define the extent of the background color even if there is no CellFrame.

• If Background->None is set, then the margins are only applied if a CellFrame is present. If the cell frame isn't drawn on all sides, then the margin will only be applied to the sides with a frame setting.

Which translates to:

1. no background and no frame ==> no margins

2. no background and a frame ==> margins respected for sides that have frame

3. background =!= none ==> margins respected

Your initial case is (1.) and you need to know that "Item" style has CellFrameMargins (which are ignored now) but has no CellFrame.

Once you add Background we have the 3rd case.

## Solution

Having those rules laid out we can come up with a solution. That is the only way is to make CellFrameMargins -> None. Why aren't they None by default for Item? Or why is it so convoluted? Ask WRI Support.

You can do this via stylesheet for "Item" style or you can patch a specific notebook with:

SetOptions[#, CellFrameMargins -> None] & /@ Cells[CellStyle -> "Item"]

• Your suggestion means identifying every CellStyle where I don't want background color to change the spacing. That presumes that CellFrameMargins is not needed elsewhere for that CellStyle. <br/> I really wish the MMA frontend were closer to the w3c.org vision. I even wrote the Stephen Wolfram suggesting as much. But retrofitting a new frontend would probably be prohibitively difficult. I use Mathematica every day, all day long as an authoring tool for my own notes. The combination of features makes it better than anything else available. But I am painfully aware of its "features". – Steven Thomas Hatton Jan 10 at 5:41
• @StevenHatton If Item is not the only one you want to change then yes, you need to deal with it. You don't need to use SetOptions though. Just go to your custom stylesheet and add/edit entries like Cell[StyleData["Item", env], CellFrameMargins->None]. – Kuba Jan 10 at 7:23