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.

How can I stretch this Grid to the width of the encapsulating Panel (so that "right" floats on the right side? I want to achieve something along the lines of the menu at the top of the Documentation notebooks.

Panel[
 Grid[
  {{"left", "nextToLeft", "right"}},
  Alignment -> {{Left, Left, Right}, Baseline}],
 ImageSize -> Full]

Looks like this now:

enter image description here

share|improve this question

2 Answers 2

up vote 5 down vote accepted

You could use Scaled item sizes but that still requires you to manually get it right:

Panel[Grid[{{"left", "nextToLeft", "right"}}, 
  Alignment -> {{Left, Left, Right}, Baseline}, 
  ItemSize -> {{Scaled[.1], Scaled[.1], Scaled[.8]}}, Frame -> All, 
  Spacings -> {0, 0}], ImageSize -> Full]

So the way I usually do it is to wrap the right hand item in Pane

Panel[Grid[{
   {"left", "nextToLeft", 
    Framed@Pane["right", {Full, All}, Alignment -> {Right, Center}, 
      ImageMargins -> 0]}
   }, Alignment -> {{Left, Left, Right}, Baseline}],
 ImageSize -> Full]

I've added a frame so you can see what is happening:

enter image description here

share|improve this answer

You can also use ItemSize -> Fit:

 Panel[Grid[{{"left", "nextToLeft", "right"}}, 
       ItemSize ->Fit,
       Alignment -> {{Left, Left, Right}, Baseline},  
       Frame -> False, Spacings -> {0, 0}], 
    ImageSize -> Full] 

Mixed settings like ItemSize -> {{Scaled[.1], 15, Fit}} also work:

 Column[
   Panel[Grid[{{"left", "nextToLeft", "right"}}, 
              Alignment -> {{Left, Center, Right}, Baseline}, ItemSize -> #, 
              Frame -> False, Spacings -> {0, 0}], 
        ImageSize ->Full] & /@ 
   {Fit, {{{15, 20, Fit}}}, {{{Fit, 20, Fit}}}, {{{Scaled[.1], 15, Fit}}}}]

enter image description here

Update: Need help locating references in the docs for ItemSize->Fit. I am quite sure I have seen it somewhere in the documentation, but could not find anything using the usual keywords.

The only example I currently have is burried in this great answer by Mike to a different question (thanks Mr.Wizard).

share|improve this answer
    
Another really useful feature that does not appear to be in the Documentation. (Or is it?) Thanks. –  mfvonh May 15 at 15:20
    
@mfvonh, I am sure I have seen this used somewhere in the docs. But to my surprise I could not find this setting for ItemSize when I searched with keywords Itemsize->Fit, Fit or ItemSize in the docs. –  kguler May 15 at 15:43
    
This works in version 7, where Mike's method unfortunately appears not to. +1 –  Mr.Wizard May 15 at 22:09
    
I note that Mike used Fit himself here: (7499) –  Mr.Wizard May 15 at 22:10
    
@Mr.Wizard, good to know that it is not a Version 9 thing. Amazing you could find Mike's answer using Fit:) I had checked the reference pages for DockedCells but could not find any examples using Fit there. –  kguler May 15 at 22:22

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.