如何独立于其他对齐网格中的第一列和第一行?

发布于 2024-11-30 04:07:54 字数 378 浏览 2 评论 0原文

如何为网格中的第一列(不包括该列中的第一行)、第一行(不包括该行中的第一个元素)和所有其他元素指定单独的对齐方式?最好仅使用 GridAlignment 选项来完成此操作,保留 Item[]Alignment 给出的严格控制用于更严格目的的选项。

PS这个问题来自 上一篇问题,但我希望在这里单独控制水平和垂直表格标题的对齐方式。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不气馁 2024-12-07 04:07:54

我找到了几种方法来实现我想要的。最直接的解决方案是:

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

在此处输入图像描述

其他解决方案包括:

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

在此处输入图像描述

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

情未る 2024-12-07 04:07:54

看起来 Alignment 使用与 Grid 中的 Background 相同的语法,因此查看 Options > 可能会有所帮助。例如,Grid 文档中的背景

例如,假设您想要将第一行和第一列中的项目对齐到右上角,将所有其他项目对齐到左下角,您可以执行类似

Grid[RandomInteger[10, {5, 5}], ItemSize -> {3, 3}, Frame -> All, 
 Alignment -> {Left, Bottom, {{1, 1} -> {Right, Top}}}]

项目 {1,1} 具有不同对齐方式的网格

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

grid with different alignment for item {1,1}

草莓味的萝莉 2024-12-07 04:07:54

如果我理解您的要求,我会倾向于使用 Item 执行此操作,如下所示:

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]

在此处输入图像描述

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]

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文