Get row in Grid to evenly divide?

Pane[
 Grid[{
   {Slider[ImageSize -> 300], SpanFromLeft, SpanFromLeft},
   {"l", "c", "r"}}, 
  Alignment -> {Center, Baseline,
    {{2, 1} -> Left, {2, 2} -> Center, {2, 3} -> Right}}, 
  Frame -> All, ItemSize -> Scaled[1/3]],
 First@ImageDimensions@
   Rasterize@Grid[{{Slider[ImageSize -> 300]}}, Frame -> All]]

enter image description here


Maybe this will work for you.

With[{size = 300},
  Grid[
    {{Slider[ImageSize -> size], SpanFromLeft}, {"l", "c", "r"}},
    ItemSize -> {{{1 + size/3/CurrentValue["FontMWidth"]}}, 1},
    Alignment -> {{Left, Center, Right}},
    Frame -> All]]

grid

The above code is concise and works for your specific example because, although the alignment specification affects all rows, the slider can't move, so the alignments are only seen in the 2nd row. If in real work, you want only the 2nd row to be affected, then use:

With[{size = 300},
  Grid[
    {{Slider[ImageSize -> size], SpanFromLeft}, {"l", "c", "r"}},
    ItemSize -> {{{1 + size/3/CurrentValue["FontMWidth"]}}, 1},
    Alignment -> {Center, Automatic, {{2, 1} -> Left, {2, 3} -> Right}},
    Frame -> All]]

Notes

  1. In the specification of the 1st row of the grid only one SpanFromLeft need be given.
  2. In the 2nd version of code, {2, 2} -> Center, is not needed in the 3rd element of the alignment specification because the specification of Center in the 1st element sets that as the default.

Tags:

Grid Layouts