IME, the results of Alignment
specifications within a Grid
environment are completely unpredictable.
I give several examples below illustrating this unpredictability.
My questions are:
Is there a way to understand these examples that dispels the seeming inconsistency among, and/or between them and the documentation?
If the answer to the previous question is "No", how can one get predictable alignment behavior within a
Grid
object?
Example 1a
Note that, despite a specification of Center
for vertical alignment in the first column, the items in this column are not centered vertically.
Grid[
{
{Item["sine" , Alignment -> {Right, Center}], Plot[Sin[x], {x, 0, 2 Pi}]},
{Item["cosine", Alignment -> {Right, Center}], Plot[Cos[x], {x, 0, 2 Pi}]}
},
Frame -> All,
FrameStyle -> Thickness[Tiny]
]
Example 1b
In this case, using a numeric (0) instead of symbolic (Center
) specification for vertical alignment produces the intended result.
Grid[
{
{Item["sine" , Alignment -> {Right, 0}], Plot[Sin[x], {x, 0, 2 Pi}]},
{Item["cosine", Alignment -> {Right, 0}], Plot[Cos[x], {x, 0, 2 Pi}]}
},
Frame -> All,
FrameStyle -> Thickness[Tiny]
]
Example 1c
Grid[
{
{Item["sine" , Alignment -> {1, 0}], Plot[Sin[x], {x, 0, 2 Pi}]},
{Item["cosine", Alignment -> {1, 0}], Plot[Cos[x], {x, 0, 2 Pi}]}
},
Frame -> All,
FrameStyle -> Thickness[Tiny]
]
In this case, the numeric alignment specification seems to work only for the vertical alignment.
Example 2a
In this case, the numeric alignment specification don't seem to work at all.
Grid[
Table[Item[{i, j}, Alignment -> {i, j}], {i, -1, 1}, {j, -1, 1}],
Frame -> All,
FrameStyle -> Thickness[Tiny],
ItemSize -> {7, 10}
]
Example 2b
In contrast, symbolic specs work fine here.
With[{initial = <|Center -> "C",
Left -> "L", Right -> "R",
Bottom -> "B", Top -> "T"|>},
Grid[
Table[Item[{initial[i], initial[j]}, Alignment -> {i, j}],
{i, {Left, Center, Right}},
{j, {Bottom, Center, Top}}],
Frame -> All,
FrameStyle -> Thickness[Tiny],
ItemSize -> {7, 10}
]
]