Reputation: 9425
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.
Upvotes: 4
Views: 1458
Reputation: 24336
If I understand your requirements, I would favor doing this with Item
as follows:
x = Array[\[HappySmiley] &, {5, 5}];
x = ReplacePart[x,
i : Except[{1, 1}, {_, 1} | {1, _}] :>
Item[x~Extract~i, Alignment -> Left]
];
Grid[x, ItemSize -> {3, 3}, Frame -> All]
Upvotes: 3
Reputation: 9425
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}}]
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}}]
Upvotes: 5
Reputation: 24420
It looks like Alignment
uses the same syntax as the Background
in Grid
so it might help to look at Options > Background
in the documentation for Grid
for examples.
For example, suppose you want to align the item in the first row and first column top-right and all other items bottom-left, you could do something like
Grid[RandomInteger[10, {5, 5}], ItemSize -> {3, 3}, Frame -> All,
Alignment -> {Left, Bottom, {{1, 1} -> {Right, Top}}}]
Upvotes: 3