5
$\begingroup$

I have a very old notebook in which many cells had the CellMargins option set manually. What's the easiest way to remove all those manual option settings?

$\endgroup$
2
  • $\begingroup$ @R.M I think it only looks for incompatibilities, and I'm guessing CellMargins has been around for a long time. $\endgroup$
    – tkott
    Commented Apr 28, 2012 at 21:39
  • $\begingroup$ @R.M.: no, the compatibility check does $not$ ask about CellMargins. After all, that's a legitimate cell option still. $\endgroup$
    – murray
    Commented Apr 28, 2012 at 21:40

1 Answer 1

8
$\begingroup$

Add the following line to the end of the notebook you want to update:

NotebookPut[NotebookGet[] /. Verbatim[Rule][CellMargins, e__] -> Sequence[]];

And evaluate it. You should get a new notebook for which all CellMargins have been deleted.


Looks like you can use the UI pretty easily to do this. First, highlight all the cells (if you want all the cells to have the same margins, just hit CTRL+a.

Then, go to Format -> Options Inspector (also can use CTRL+SHIFT+O). In the search box, you can type in CellMargins:

Here, I've set the marings to be {{66,10},{5,25}}. It looks like the default is {{66,10},{5,10}} and the settings are {{left,right},{top,bottom}}

$\endgroup$
7
  • $\begingroup$ I did $not$ ask how to change the CellMargin option (I certainly know how to do that using the Options Inspector). I want to $remove$ the option entirely from all cells (so that the margins will be whatever the stylesheet sets by default). $\endgroup$
    – murray
    Commented Apr 28, 2012 at 21:42
  • 1
    $\begingroup$ @murray All cells have the CellMargins attribute, I don't think you can "remove" it. Do you mean you would like to restore it separately for each cell type that it is in? I.e., an input cell has the default style for the default stylesheet? If so, that certainly wasn't clear from your question, and questions for which users don't know about the options inspector have come up, so I don't know how I could've known all that. $\endgroup$
    – tkott
    Commented Apr 28, 2012 at 21:47
  • $\begingroup$ No, all cells do $not$ have a CellMargins attribute as part of their expression--although of course they are in effect given cell margin settings by the cell style. E.g., in a new nb create any Input cell then look at its expression; you will $not$ see any CellMargins option there! $\endgroup$
    – murray
    Commented Apr 28, 2012 at 21:52
  • $\begingroup$ @murray not all cells have an explicit CellMargins, but I believe the front end keeps track of it as a default. But I do see what you mean: see my edit. $\endgroup$
    – tkott
    Commented Apr 28, 2012 at 21:59
  • $\begingroup$ @murray, the little cross at the left of the options in the options inspector, when removed, removes the explicit option settings, and shows whatever value is inherited. Now you certainly know how to remove the options using the options inspector too $\endgroup$
    – Rojo
    Commented Apr 28, 2012 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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