The very bottom of CellMargins is missing
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]}]]
DialogInput[
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
.
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
.
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]]