开发者

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开发者_运维百科.


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

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

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

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


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

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


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]

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜