# The very bottom of CellMargins is missing

Bug introduced in 8 or earlier and persists through 12.0

[...] It does appear that CellMargins is not interacting correctly with WindowSize->All, and I have forwarded an incident report to our developers with the information you provided. I have also included your contact information so that you can be notified once this gets resolved. [...]

Which I believe confirms that this is a bug. I'd appreciate checking that in earlier versions of MMA.

DialogInput has by default those annoying margins settings (missing a bottom one):

DialogInput[Pane@RandomImage[]]


What is the best/shortest way to make them even.

Let's not touch stylesheets here.

It seems that the problem is more general. I was suspecting that somwhere deep in definitions of DialogInput some options are prepended but here I'm just using basic code to generate the issue:

NotebookPut @ Notebook[
List @ Cell @ BoxData @ ToBoxes @ Pane[
RandomImage[], ImageMargins -> 0, FrameMargins -> 0
],
WindowSize -> All,
WindowElements -> None,
"CellInsertionPointCell" -> None,
WindowFrameElements -> {"CloseBox"},
ShowCellBracket -> False,
CellMargins -> 10
]


There is a straightforward way to set CellMargins to be zero:

DialogInput[
DialogNotebook[{ExpressionCell[Pane[RandomImage[], ImageMargins -> 8],
CellMargins -> 0]}]]


Instead of ImageMargins we can rely on CellFrameMargins:

DialogInput[
DialogNotebook[{ExpressionCell[RandomImage[], CellMargins -> 0, CellFrameMargins -> 8,
CellFrame -> True, CellFrameColor -> None]}]]


On my system (Windows 7 x64) with Mathematica 10.4 the CellFrameMargins method gives more accurate results than ImageMargins (compare the screenshots):

DialogInput[
DialogNotebook[{ExpressionCell[Pane[RandomImage[], ImageMargins -> 1],
CellMargins -> 0]}]]

DialogNotebook[{ExpressionCell[RandomImage[], CellMargins -> 0, CellFrameMargins -> 1,
CellFrame -> True, CellFrameColor -> None]}]]


From your second example in the question I believe that this behavior is determined by the WindowSize -> All Notebook option which makes the window

large enough to fit all visible contents

(emphasis mine).

It seems that FrontEnd crops CellMargins because they "aren't visible". But with this explanation the inconsistency is that it crops them only at the bottom but not on the right even if we switch off displaying of the cell bracket:

NotebookPut@
Notebook[{Cell@
BoxData@ToBoxes@Pane[RandomImage[], ImageMargins -> 0, FrameMargins -> 0]},
WindowSize -> All, WindowElements -> None, ShowCellBracket -> False,
WindowFrameElements -> {"CloseBox"}, CellMargins -> 10]


If we add another cell we can see that CellMargins are actually respected:

NotebookPut@
Notebook[Table[
Cell@BoxData@ToBoxes@Pane[RandomImage[], ImageMargins -> 0, FrameMargins -> 0], {2}],
WindowSize -> All, WindowElements -> None, ShowCellBracket -> False,
WindowFrameElements -> {"CloseBox"}, CellMargins -> 10]


So I'm inclined to think that we have a bug in handling of the WindowSize -> All option: the expected behavior for this option is to treat CellMargins as visible contents and make the window to be sufficiently large to include the whole CellMargins.

• Yep, that's shorter than mine. I believe I've used something like that once but I forgot due to the confusion about all those DialogNotebook/CreateWindow/Notebook and friends. Do you possibly have any idea what's the root of the problem?
– Kuba
Apr 15 '16 at 6:31
• @Kuba I think it's a bug. I have read the Dialog.nb stylesheet but haven't found anything what could explain this. I also wasn't able to reproduce this with the default stylesheet (but I haven't spend much time on this). Apr 15 '16 at 8:24
• The second example in the question includes the default.nb stylesheet. I just had to get rid of some elements to make this effect visible. I've sent a support question, CASE:3579534 created, will keep you informed.
– Kuba
Apr 15 '16 at 8:29
• @Kuba Thanks, I overlooked the second example. I have updated the answer with new findings. Apr 15 '16 at 8:51
• @Kuba Added CellFrameMargins-based workaround and the comparison. Apr 15 '16 at 9:08

I gave up looking for neat solution. Here's brute force.

Since the bottom CellMargins are not respected then let's not use any! :) We can use Pane and its ImageMargins to take control over padding.

DialogInput[
DynamicModule[{},
Pane[RandomImage[], ImageMargins -> 8],
Initialization :> (SetOptions[EvaluationCell[], CellMargins -> 0])
]
]


So in general instead of RandomImage[] put the code you would have used in DialogInput.

• I love brute force solutions :)
– M.R.
Apr 15 '16 at 0:21

It really expects that you have some buttons along the bottom.

DialogInput[Column[{Pane @ RandomImage[], Button["OK", DialogReturn[0]]}]]


but you can do it this way

DialogInput[Column[{Pane @ RandomImage[], ""}]]


### Update

I Think it looks better with the bottom margin a bit larger than the top, but if you are being picky about equal margins, try

DialogInput[Column[{Pane@RandomImage[], ""}, Spacings -> 0]]


• But I don't have any Buttons. Both you examples have the bottom margin different than the rest of them.
– Kuba
Apr 14 '16 at 15:39
• @Kuba. see update Apr 14 '16 at 15:51
• Yes, that's good quick fix thanks. Unfortunately it doesn't give a precision/control, over those margins, that I'm after.
– Kuba
Apr 15 '16 at 7:31