Nas*_*ser 5 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
Run Code Online (Sandbox Code Playgroud)
注意,它表示上面的剩余行.
我想要的是让所有起始行使用一些间距,但最后一行使用不同的间距.
此示例执行记录的方式(其余行)
n = 5;
data = Table[Random[], {n}, {n}];
Grid[data, Frame -> All, RowSpacings -> {6, 1}, Alignment -> Center]
Run Code Online (Sandbox Code Playgroud)
但我想反过来,即将最后一行设置为某个东西,将所有行设置为另一行.只有这样我才能做到这一点很长,即通过写下所有行的所有间距直到最后一行:
n = 5;
data = Table[Random[], {n}, {n}];
Grid[data, Frame -> All,
RowSpacings -> {Sequence @@ Table[1, {n - 2}], 6},Alignment -> Center]
Run Code Online (Sandbox Code Playgroud)
以上只是另一种写作方式
Grid[data, Frame -> All, RowSpacings -> {1, 1, 1, 6}, Alignment -> Center]
Run Code Online (Sandbox Code Playgroud)
我也尝试过类似的东西
Grid[data, Frame -> All, RowSpacings -> {{1}, 6}, Alignment -> Center]
Grid[data, Frame -> All, RowSpacings -> {{1 ;; 3}, 6}, Alignment -> Center]
Run Code Online (Sandbox Code Playgroud)
但他们不起作用.我找不到上面第一个例子中的捷径.
任何人都知道一个技巧告诉你RowSpacings
只将最后一行设置为某个特定值,并将所有行设置为其他一行,而不使用上述黑客攻击?
这真的不像我做的那么大,我只是想知道我是否忽略了Mathematica中的一种技巧语法用法,就是这样.
谢谢,
假设您没有其他理由使用RowSpacings
+ GridBox
组合,请使用Spacings
选项Grid
Grid[data, Spacings -> {Automatic, Dimensions[data][[1]] -> 6},
Frame -> All, Alignment -> Center]
Run Code Online (Sandbox Code Playgroud)
给出你需要的东西.
编辑:更方便,Grid[data, Spacings -> {Automatic, -2-> 6}, Frame -> All, Alignment -> Center]
where -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
Run Code Online (Sandbox Code Playgroud)