8
$\begingroup$

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

enter image description here

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:

enter image description here

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.

$\endgroup$
8
$\begingroup$

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[]]]},
   MapThread[
    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

enter image description here

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.