Message Boards Message Boards

0
|
7923 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

How to put a frame around a group of cells?

Posted 11 years ago
I am new to Mathematica, I am trying to write some notes to my students. I would like to put a frame around a group of cells in the notebook, but when I am trying to change the style of the outer grouping cell to "framed", the inner cells become individually framed. This is not what I want, I would like a frame only outside with the inner cells unframed. Can you please suggest what to do and/or direct me to a tutorial?
Thanks, Ferenc
POSTED BY: Ferenc Beleznay
4 Replies
One approach is to make use of the Cell options CellFrame and CellMargins to build up the frame around multiple cells using partial frames around the set of cells.  Using CellFrame, the first cell has frame elements at the top and sides. The inside cells have frame elements around the sides only.  And the bottom has frame elements on the sides and the bottom. Then using CellMargins the vertical distances between the cells is made 0 so that they abutt.  Here is a programmatic example, but you can use the option inspector to make these changes interactively.  Also one cold write a function that does this for a selection of cells and then put that function into a button and then into a palette if one wished.  (Tweaking this all so it works in a more general case requires also playing with CellFrameMargins option settings. This is just a quick proof of concept example...)
 CellPrint[{TextCell[StringJoin[Table["abcd ", {20}]], "Text",
    CellFrame -> {{True, True}, {False, True}},
    CellMargins -> {{200, 200}, {0, 0}}],
   TextCell[StringJoin[Table["abcd ", {20}]], "Text",
    CellFrame -> {{True, True}, {False, False}},
    CellMargins -> {{200, 200}, {0, 0}}],
   TextCell[StringJoin[Table["abcd ", {20}]], "Text",
    CellFrame -> {{True, True}, {False, False}},
    CellMargins -> {{200, 200}, {0, 0}}],
  TextCell[StringJoin[Table["abcd ", {20}]], "Text",
   CellFrame -> {{True, True}, {True, False}},
   CellMargins -> {{200, 200}, {0, 0}}]}]

Realizing that you are new to Mathematica, this may seem pretty complex. If I have some time later on I can put together a one-button Palette that can do this for you.
POSTED BY: David Reiss
Posted 11 years ago
Thank you for the quick reply. I tried it and it worked to some extent. The problem is that I am trying to use the built-in textbook stylesheet and modify the Example style to put a frame around it and at the same time keeping it open to use different style cells nested within the example cell. I was hoping to find a solution that does not modify the style of the inner cells, just the one cell that groups those together. I am thinking something like the blue lines on the right of the notebook that show the nesting structure of the cells, just with frames instead of lines. Any suggestions?
POSTED BY: Ferenc Beleznay
I am not sure, though I did understand that that was your hope -- modifying a top-level cell in a cellgroup structure to draw a frame around all that are in that cell's purview. Generally this is not possible in this way though I am sure that I could come up with some invention that made it look like it worked ;-)  

The problem is that generally a given cell does not have knowledge of other cells in the notebook in that sort of dynamic fashion.   And the low-level  function that does know if cells are grouped, CellGroupData, has no options. 

Here are two discussions of this on Mathematica StackExchange (the first referring to the second) which don't get much further conceptually than what I was originally suggesting.

http://mathematica.stackexchange.com/questions/29475/is-it-possible-to-frame-a-group-of-cells
http://mathematica.stackexchange.com/questions/6264/automatically-use-inputonly-style

C
learly Mathematica should be able to do things like this. 

If you do not have any inputs in your content that need to be executed, then you might be able to do what you want within a single cell by putting the material in a Framed or a Panel like in the following.
 Column[{
   TextCell[StringJoin[Table["Parrot ", {20}]], "Text"],
   TextCell[StringJoin[Table["Dog ", {20}]], "Text"],
   ExpressionCell[Defer[3/6 + 1/(1 + x)], "Input"],
   TextCell[StringJoin[Table["Piano ", {20}]], "Text"],
   TextCell[StringJoin[Table["Wombat ", {20}]], "Text"]
   },
  Frame -> True,
  FrameStyle -> Directive[Thick, Darker@Red]
]


Framed[
Column[{
   TextCell[StringJoin[Table["Parrot ", {20}]], "Text"],
   TextCell[StringJoin[Table["Dog ", {20}]], "Text"],
   ExpressionCell[Defer[3/6 + 1/(1 + x)], "Input"],
   TextCell[StringJoin[Table["Piano ", {20}]], "Text"],
   TextCell[StringJoin[Table["Wombat ", {20}]], "Text"]
   }
  ],
RoundingRadius -> 5
]


Panel[Column[
  {
   TextCell[StringJoin[Table["Parrot ", {20}]], "Text"],
   TextCell[StringJoin[Table["Dog ", {20}]], "Text"],
   ExpressionCell[Defer[3/6 + 1/(1 + x)], "Input"],
   TextCell[StringJoin[Table["Piano ", {20}]], "Text"],
   TextCell[StringJoin[Table["Wombat ", {20}]], "Text"]
   }
  ]
]

Perhaps I will come up with some other ideas...
POSTED BY: David Reiss
Posted 11 years ago
Yes, I think I will stay within one cell, although it would be nice to have some kind of "option inspector" to modify some properties (e.g. frame, background color...) of groups of cells without modifying the cells themselves. Mathematica clearly knows about grouping, it can put a bracket on the right indicating the scope, but at the moment when I change e.g. the background color for a group, it changes the color of all cells in a group, but not the color of the background behind them.
I was also thinking about modifying the style sheet to change the distance between cells to 0 and changing the upper and lower margins within the cells, but it is too much change, I will instead figure out how to stay within one cell.
POSTED BY: Ferenc Beleznay
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract