wolfram-mathematica - 对于仅为网格中的最后一行设置RowSpacing的任何简短语法?

标签 wolfram-mathematica

RowSpacings允许更改网格中的行距。

帮助说:

RowSpacings->{Subscript[s, 12],Subscript[s, 23],...} can be used to specify 
different spacings between different rows. If there are more rows than 
entries in this list, then the last element of the list is used repeatedly 
for the remaining rows

请注意,它上面的其余行。

我想要的是使所有开始的行都使用一定的间距,但使最后一行使用不同的间距。

本示例采用记录方式(其余行)
n = 5;
data = Table[Random[], {n}, {n}];
Grid[data, Frame -> All, RowSpacings -> {6, 1}, Alignment -> Center]

但是我想做相反的事情,即将最后一行设置为某行,并将其之前的所有行设置为另一行。我能做到的唯一方法是漫长的路,即写下所有行的所有间距直到最后一行:
n = 5;
data = Table[Random[], {n}, {n}];
Grid[data, Frame -> All, 
 RowSpacings -> {Sequence @@ Table[1, {n - 2}], 6},Alignment -> Center]

以上只是另一种写法
Grid[data, Frame -> All, RowSpacings -> {1, 1, 1, 6}, Alignment -> Center]

我也尝试过类似的东西
Grid[data, Frame -> All, RowSpacings -> {{1}, 6}, Alignment -> Center]
Grid[data, Frame -> All, RowSpacings -> {{1 ;; 3}, 6}, Alignment -> Center]

但它们不起作用。我找不到像上面第一个示例中那样的捷径。

任何人都知道一种技巧,可以告诉RowSpacings仅将最后一个Row设置为某个特定值,并将所有行设置为另一个特定值,而不使用上述hack吗?

这样做真的不是什么大不了的事,我只是想知道我是否忽略了Mathematica中的那些技巧语法用法之一,仅此而已。

谢谢,

最佳答案

假设您没有其他理由使用RowSpacings + GridBox组合,对Spacings使用Grid选项

Grid[data, Spacings -> {Automatic, Dimensions[data][[1]] -> 6}, 
     Frame -> All, Alignment -> Center]

提供您所需要的。

编辑:更方便的是Grid[data, Spacings -> {Automatic, -2-> 6}, Frame -> All, Alignment -> Center],其中-2指的是从1到1+number of rows的行索引的最后一个元素中的第二个元素

编辑2:使用GridBox,以下产生相同的输出:
GridBox[data, RowLines -> True, ColumnLines -> True, 
  GridFrame -> True, RowAlignments -> Center, 
  ColumnAlignments -> Center, 
  GridBoxSpacings -> {"RowsIndexed" -> {-2 -> 6}}] //DisplayForm

关于wolfram-mathematica - 对于仅为网格中的最后一行设置RowSpacing的任何简短语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8688530/

相关文章:

function - 创建自定义表格表示的函数

wolfram-mathematica - 在 Mathematica 中绘制数轴

wolfram-mathematica - 带有符号输入的 RecurrenceTable 中的错误

wolfram-mathematica - 我如何获得 Mathematica 中所有分布的列表

wolfram-mathematica - 覆盖无序函数的默认显示顺序

matlab - Mathematica 和 Matlab 哪个更适合图像处理学习/原型(prototype)设计?

wolfram-mathematica - 将存储在列表中的参数传递给表达式

wolfram-mathematica - Mathematica中空列表的长度

memory - Mathematica 中的子内核内存控制

colors - 在条形图中使用打火机自定义颜色