Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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]]

Mathematica graphics

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.

Pane, Panel, Frame

share|improve this question
4  
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. –  kguler Feb 3 '12 at 12:59
1  
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. –  kguler Feb 3 '12 at 15:11

3 Answers 3

up vote 5 down vote accepted

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]]

Mathematica graphics

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.

share|improve this answer
    
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
5  
@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
1  
Now that's a definitive answer, thanks! Would you care to do make it a real answer so I can accept it? –  István Zachar Feb 3 '12 at 13:08
    
Included your comment so that I can accept this answer. –  István Zachar Jun 7 '12 at 14:01
    
@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 at 7:49

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:

PlotRangePadding1

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

PlotRangePadding2

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.

PlotRangePadding3

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

share|improve this answer

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

framed with FrameMargins 0 and 1

share|improve this answer
    
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. –  kguler 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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