6
$\begingroup$

IME, the results of Alignment specifications within a Grid environment are completely unpredictable.

I give several examples below illustrating this unpredictability.

My questions are:

  1. Is there a way to understand these examples that dispels the seeming inconsistency among, and/or between them and the documentation?

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

Mathematica graphics


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

Mathematica graphics


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

Mathematica graphics

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

Mathematica graphics


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

Mathematica graphics

$\endgroup$
3
  • 1
    $\begingroup$ numbered alignments in grid have been broken for many version. low priority apparently $\endgroup$ Commented Apr 7, 2017 at 1:15
  • $\begingroup$ @MikeHoneychurch: symbolic ones appear to be broken also, judging by the Example 1a $\endgroup$
    – kjo
    Commented Apr 7, 2017 at 10:37
  • $\begingroup$ Meh, I liked the original exhibits better :-) $\endgroup$
    – LLlAMnYP
    Commented Apr 7, 2017 at 15:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.