# Stretch Grid to fit width of containing object?

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:

-

## 2 Answers

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:

-

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


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).

-
Another really useful feature that does not appear to be in the Documentation. (Or is it?) Thanks. –  mfvonh May 15 '14 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 '14 at 15:43
This works in version 7, where Mike's method unfortunately appears not to. +1 –  Mr.Wizard May 15 '14 at 22:09
I note that Mike used Fit himself here: (7499) –  Mr.Wizard May 15 '14 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 '14 at 22:22