# Framing a combination of cells in the notebook

In my notebook, I have the following cells, which I tried to put around a single frame with a light blue background color.

After entering the cells, I selected all four, then clicked the frame button in the Writing Assistant palette. Unfortunately, I did not get a single frame.

Can some suggest how I can get just a single frame around all four cells? The centered cells are from the Writing Assistant, Math Cells, Centered Math Cell.

They do not match what I want:

Perhaps I should ask how can put all of my writing in one cell.

Thank you, Mr. Wizard:

I selected the four cells, then used Mr. Wizard's Frame Multiple Cells button, which was created by his code, and here is the result:

I added the red color to the word definition after using Mr. Wizard's button.

Using the Writing Assistant Pallete:

It turns out that if I select my four cells, then click on the Merge Cells icon on the Writing Assistant tablet, it's done! Then use the Writing Assistant tablet to add a frame and color the background.

This question is closely related to Automatically use InputOnly style and it can also be done with CellFrame and CellMargins. Here is a Button to automate the process.

Button["Frame Multiple Cells",
With[{cells = Cells[NotebookSelection[InputNotebook[]]]},
Function[{frame, pos},
MapAt[
SetOptions[#,
CellMargins -> {{66, 10}, {0, 0}},
CellFrame   -> {{2, 2}, frame},
Background  -> LightBlue] &,
cells,
pos
]
],
{{{0, 2}, {0, 0}, {2, 0}}, {1, 2 ;; -2, -1}}
]
]
] // CreatePalette


Notes:

• Setting a Background color affects the spacing of the cells; without it they squeeze together.

• To keep the frame continuous to the Output cell I had to disable automatic grouping.

• Wow! It worked beautifully. See my update to my original post. – David Jul 16 '15 at 2:37
• Automatic grouping? Not sure what that is or if its disabling will affect what I normally do? – David Jul 16 '15 at 2:41
• This is so good, I'd like to add it to my Palettes menu or my writing assistant. Is that possible? – David Jul 16 '15 at 2:42
• Does disabling automatic grouping slow down printing of the notebook? – David Jul 16 '15 at 5:01
• Note that setting the option CellGroupingRules -> "NormalGrouping" (in the button) overrides the automatic grouping so that the frame is continuous. – Michael E2 Jul 16 '15 at 5:38