# Get row in Grid to evenly divide?

I'm having an issue making the second row in this grid space out evenly:

Grid[{{Slider[ImageSize -> 300], SpanFromLeft, SpanFromLeft}, {"l",
"c", "r"}},
Alignment -> {{2, 1} -> Left, {2, 2} -> Center, {2, 3} -> Right},
Frame -> All, Spacings -> Automatic]


Response to @MichaelE2: There is still too much space to the right of the slider:

Response to @m_goldberg: At higher magnifications the slider runs outside the grid:

• add the option ColumnsEqual -> True or the option ItemSize -> All? – kglr Jan 15 at 23:27
• It says ColumnsEqual isn't an option for Grid – user5601 Jan 15 at 23:48
• ColumnsEqual makes the columns equally spaced, but it also makes the grid a lot bigger for some reason. ItemSize does the same thing, too big. – user5601 Jan 15 at 23:54
• @user5601 I believe it make all columns equal in width to the item in position {1, 1}, the slider. The SpanFromLeft seems to be ignored in considering column widths. – Michael E2 Jan 16 at 13:07
• About your response to me: you didn't use my code. What do you expect me to say? -- If it is somehow connect to my comment, my comment only explained how the widths of the columns are calculated when you use ItemSize -> All. The widths is set to the widest column, which is the width of the slider. – Michael E2 Jan 19 at 0:32

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


• Is there a way to tweak this to get rid of the added space? – user5601 Jan 19 at 5:17
• @user5601 What added space? You specify the slider should have an image size (width) of 300. There is a small margin around each element plus a frame. IIRC, the overall image size is 313. Do you want to get rid of the margins? If so, set the width of Pane (the second argument) to 300. – Michael E2 Jan 19 at 13:40
• Thanks that does it. – user5601 Jan 19 at 22:44

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


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.
• See my updates - try changing the notebook magnification. – user5601 Jan 18 at 22:23
• @user5601. Yes, it doesn't play well with changes in notebook magnification. Michael E2 approach is better in that it not affected by magnification changes. – m_goldberg Jan 19 at 1:57