# How to get rid of Panel margins?

I have a feeling that there is something wrong in general with Mathematica's way of dealing with margins and spaces among/around objects in Graphics, Grid-s, and alike. This is a constant problem for me, and for many others I assume. I usually end up to do some pixel-pushing or other workarounds, but this is getting more and more annoying with every year. Consider the following example:

 Panel[
Graphics[{Circle[]},
ImageSize -> 300, ImageMargins -> 0, ImagePadding -> 0,
Frame -> True, FrameTicks -> None, PlotRange -> {{-1, 1}, {-1, 1}},
PlotRangePadding -> 0, Background -> White,
Method -> {"ShrinkWrap" -> True}],
FrameMargins -> 0, ImageMargins -> 0, ImageSize -> All,
Background -> Lighter[Pink, .6]]


I have two questions related to the code above:

Q1: How to get rid of the pink frame margin without setting Panel's FrameMargins explicitly to a negative number? I would assume, a zero-width margin is ... zero-width.

Q2: Why does the left right and bottom part of the Frame of the internal Graphics disappear and how can I prevent it?

Edit

Various workarounds can be used, e.g. Pane or Framed. The problem with these is that they don't have the look and feel Panel provides:

CreateDialog[Pane[{1, 2, 3}], WindowTitle -> "Pane"];
CreateDialog[Framed@Pane[{1, 2, 3}], WindowTitle -> "Framed Pane"];
CreateDialog[Panel[{1, 2, 3}], WindowTitle -> "Panel"];


While Panel looks good in a dialog window, the other two do not.

• With styling options you can make both Pane and Framed look just like Panel; e.g. you can set BaseStyle->"Panel" and FrameStyle->GrayLevel[.7] etc to get the same looks. But I think the real advantage of Panel is its Deployed option which Pane and Framed does not support. – kglr Feb 3 '12 at 12:59
• Oh good, I didn't know about BaseStyle -> "Panel". I think the Deployed option can be substituted by a Deploy wrapper. Now I already suggested to @Szabolcs to make an answer out of his comment but I wish you two would couple up and write an answer combining both of your comments :) – István Zachar Feb 3 '12 at 13:12
• You are right; any expression can be wrapped with Deploy to the same effect. I think @Szabolc's comment explains the puzzling behavior for us all. – kglr Feb 3 '12 at 15:11

In these situations I like to use Pane instead of Panel. It has no frame or extra margins.

Pane[Graphics[{Circle[]}, ImageSize -> 300, Frame -> True,
FrameTicks -> None]]


Does this help?

In case if you just want a Panel with no margins, not even the small margins that are left after FrameMargins -> 0:

The problem is that the Panel margin is styled by the operating system and will look different on different platforms. For example, on Windows XP it has an "engraved" look. This would be not possible without some extra margin. If we take away the system-styled margins, then all we're left with is a Pane.

• Yes it helps, but it would be nice if I could do it with Panel. Does it mean that Panel is buggy? – István Zachar Feb 3 '12 at 12:20
• @István It means that I misunderstood your question. So you just want a Panel with no margins, not even the small margins that are left after FrameMargins -> 0, right? The problem is that the Panel margin is styled by the operating system and will look different on different platforms. For example, on Windows XP it has an "engraved" look. This would be note possible without some extra margin. If we take away the system-styled margins, then all we're left with is a Pane. – Szabolcs Feb 3 '12 at 13:03
• @Szabolcs I'm sure you are right about OS depending behaviour of Panel, but is this written somewhere? Or further, how to check which objects looks depend of OS? Sure, Sliders etc but this is an observation, not a documented fact. – Kuba Feb 19 '14 at 7:49
• @Kuba I just assumed that if a control looks like a standard GUI control that I also see in other programs, then it must be rendered by the OS, so it must be OS-dependent. Perhaps this is not so obvious for Panels on Windows because of the very plain appearance. On OS X they're quite heavily styled. BTW it's possible to use a generic, platform independent appearance with Style[..., ControlsRendering -> "Generic"]. This rendering is also used when exporting to PDF/EPS. – Szabolcs Feb 19 '14 at 16:58

Framed is a way to avoid the frustrations with Panel; that is, ...Margins settings work as one would expect: With FrameMargins->0 and FrameMargins->1 the following

 Row[{Framed[
Graphics[{Circle[]}, ImageSize -> 300, ImageMargins -> 0,
ImagePadding -> 4, Frame -> True, FrameTicks -> None,
PlotRange -> {{-1, 1}, {-1, 1}}, PlotRangePadding -> .4,
Background -> White, Method -> {"ShrinkWrap" -> True}],
FrameMargins -> 0, ImageMargins -> 0, ImageSize -> All,
Background -> Lighter[Pink, .6]], "   ",
Framed[Graphics[{Circle[]}, ImageSize -> 300, ImageMargins -> 0,
ImagePadding -> 4, Frame -> True, FrameTicks -> None,
PlotRange -> {{-1, 1}, {-1, 1}}, PlotRangePadding -> .4,
Background -> White, Method -> {"ShrinkWrap" -> True}],
FrameMargins -> 1, ImageMargins -> 0, ImageSize -> All,
Background -> Lighter[Pink, .6]]}]


gives

• Thanks kguler, this is working fine, but does not solve all my problems. See edit in my post. – István Zachar Feb 3 '12 at 12:32
• @Istvan, possibly a cut/paste error in your second example: Framed@Pane versus just Framed. – kglr Feb 3 '12 at 12:45
• It does not matter, the dialog output will look like the same. – István Zachar Feb 3 '12 at 12:59

With respect to your second question,

Q2: Why does the left and bottom part of the Frame of the internal Graphics disappear and how can I prevent it?

Did you mean to say "right and bottom part of the Frame..."?

In any case, you might want to experiment with PlotRangePadding. For, example, PlotRangePadding -> 0.01 produces the following:

You can also adjust the PlotRangePadding on the {{left, right}, {bottom,top}}, as in PlotRangePadding -> {{0, 0.01}, {0.01, 0}} (see below):

or PlotRangePadding -> {{0, 0.01}, {0.03, 0}}`

I don't understand why adding the additional padding to the bottom causes the black line to appear. I had thought the black lines at the left and top were to convey shadows (to create the illusion that the panel were slightly sunken), but a bottom shadow works against this interpretation.

I don't think this solves your problem but it may shed some light on it.