文章目录(Table of Contents)
Grid with Frame->All: How to not draw frames around empty cells?(在使用Grid中的Frame->All时,如何不要在空白的单元格加边框)
问题
原文
If I have a grid of values that doesn't divide evenly, for example a list of 17 values, and split it into a 7x3 grid, then draw frames around each element:
Grid[Partition[Range@17,UpTo@7],Frame->All]
This creates grid lines around the 4 empty elements in the last row:
How do I get Grid to not frame those empty elements? I'd still want the bottom borders around 11-14 and the right border on 17, if that makes sense.
I can sort of do it with it TableForm:
TableForm[Partition[Framed[#,ImageSize->40]&/@Range@17,UpTo@7],TableSpacing->0]
...but the frame lines look a little bit weird. There's gaps at the top of each vertical line, and they're twice as thick as the horizontal lines (probably because there's the left and right sides of each being pushed together).
Grid's lines are much cleaner; is there a way to do it? Thanks!
翻译
如果我有一个不均匀分割的网格,例如有17个值的列表,并把他们分割成7*3的网格,然后在每个元素外画出边框:
Grid[Partition[Range@17,UpTo@7],Frame->All]
这样画出的格子在最后一行有四个空的元素:
我应该如何使用Grid
而不给空的元素加上边框?我仍然想要底部的边框在11-14和最右边的边框是17,如果那样是有意义的话。
我可以使用TableForm
来做到这点。
TableForm[Partition[Framed[#,ImageSize->40]&/@Range@17,UpTo@7],TableSpacing->0]
...但是边框看起来有一点奇怪。在每个垂直的线顶部有空隙,他们的水平线是两倍(可能是因为左右两侧的垂直线被压在了一起)
Grid
的线条更加清除,是否有使用Gird
的方法来做这些?谢谢。
高票回答
原文
You may use Item.
Grid[Map[Item[#, Frame -> All] &, Partition[Range@17, UpTo@7], {2}]]
Hope this helps.
翻译
你可以使用函数Item
Grid[Map[Item[#, Frame -> All] &, Partition[Range@17, UpTo@7], {2}]]
希望这个对你有帮助
一些单词及句子
- weird:奇怪的
- I can sort of do it with
TablForm
:我可以使用函数TableForm
做到这点。 - If I have a grid of values that doesn't divide evenly, for example a list of 17 values, and split it into a 7x3 grid, then draw frames around each element:如果我有一个不均匀分割的值的网格,例如17个值的列表,并将其拆分为7x3网格,则在每个元素周围绘制框架
- 微信公众号
- 关注微信公众号
- QQ群
- 我们的QQ群号
评论