Search code examples
wolfram-mathematicamathematica-frontend

How to align first column and first row in Grid independently from others?


How to specify separate alignments for the first column (excluding first row in this column), first row (excluding first element in this row) and all other elements in the Grid? It is preferable to do this just with Alignment option of Grid preserving tight control given by Item[] with Alignment option for more tight purposes.

P.S. This question comes from previous question but I wish to get individual control over alignments of horizontal and vertical table headings here.


Solution

  • I have found several ways to achieve what I want. The most direct solution is:

    Grid[Table[Row@(Range[a]), {a, 1, 4}, {7}], 
     Alignment -> {Right, 
       Automatic, {{{2, -1}, {1, 1}} -> Left, {{1, 1}, {2, -1}} -> 
         Center}}, Dividers -> {{2 -> True}, {2 -> True}}]
    

    enter image description here

    Other solutions include:

    Grid[Table[Row@Range[a], {a, 1, 4}, {7}], 
     Alignment -> {{Left, {Right}}, 
       Automatic, {{1, 1}, {1, -1}} -> Center}, 
     Dividers -> {{2 -> True}, {2 -> True}}]
    Grid[Table[Row@Range[a], {a, 1, 4}, {7}], 
     Alignment -> {Right, 
       Automatic, {1 -> Left, {{1, 1}, {2, -1}} -> Center}}, 
     Dividers -> {{2 -> True}, {2 -> True}}]
    Grid[Table[Row@Range[a], {a, 1, 4}, {7}], 
     Alignment -> {Right, 
       Automatic, {1 -> Left, {{1, 1}, {1, -1}} -> Center}}, 
     Dividers -> {{2 -> True}, {2 -> True}}]
    Grid[Table[Row@Range[a], {a, 1, 4}, {7}], 
     Alignment -> {Right, 
       Automatic, {{{1, 1}, {1, -1}} -> Center, 1 -> Left}}, 
     Dividers -> {{2 -> True}, {2 -> True}}]
    

    enter image description here