RowSpacings allows one to change row spacings in a Grid.
Help says:
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
Notice, where it says the remaining rows above.
What I want is to make all starting rows use some spacing, but the last row to use different spacing.
This example does the documented way (the remaining rows)
n = 5;
data = Table[Random[], {n}, {n}];
Grid[data, Frame -> All, RowSpacings -> {6, 1}, Alignment -> Center]
But I wanted to do the reverse, i.e. set the last row to something, and all rows before it to another. Only way I could do it is the long way, i.e. by writing down all the spacings for all the rows until the last one:
n = 5;
data = Table[Random[], {n}, {n}];
Grid[data, Frame -> All,
RowSpacings -> {Sequence @@ Table[1, {n - 2}], 6},Alignment -> Center]
The above is just another way to write
Grid[data, Frame -> All, RowSpacings -> {1, 1, 1, 6}, Alignment -> Center]
I also tried things like
Grid[data, Frame -> All, RowSpacings -> {{1}, 6}, Alignment -> Center]
Grid[data, Frame -> All, RowSpacings -> {{1 ;; 3}, 6}, Alignment -> Center]
but they do not work. I could not find a short cut like in the first example above.
Any one knows a trick to tell RowSpacings
to set only the last Row to some specific value, and all rows up to it to some other one, without the use of the above hack?
This is not a big deal really to do it as I did, I just was wondering if I am overlooking one of those trick syntax usage in Mathematica, that is all.
thanks,
To center the last one, you can double the number of columns to 4 and set each item to span 2 . If the last item is odd, start on the second column so it spans columns 2 and 3. With a bit of math and SCSS, this can be generalized to work with any number of columns.
The grid-row CSS shorthand property specifies a grid item's size and location within the grid row by contributing a line, a span, or nothing (automatic) to its grid placement, thereby specifying the inline-start and inline-end edge of its grid area.
The grid-area property can be used as a shorthand property for the grid-row-start , grid-column-start , grid-row-end and the grid-column-end properties.
To change the row height for the whole grid, set the property rowHeight to a positive number. For example, to set the height to 50px, do the following: const gridOptions = { rowHeight: 50, // other grid options ... } Changing the property will set a new row height for all rows, including pinned rows top and bottom.
Assuming you don't have other reasons to use RowSpacings
+ GridBox
combination, using Spacings
option for Grid
Grid[data, Spacings -> {Automatic, Dimensions[data][[1]] -> 6},
Frame -> All, Alignment -> Center]
gives what you need.
EDIT: More conveniently, Grid[data, Spacings -> {Automatic, -2-> 6}, Frame -> All, Alignment -> Center]
where -2
refers to the second from last element of the row indices that go from 1 to 1+number of rows
EDIT 2: Using GridBox
, the following produces the same output:
GridBox[data, RowLines -> True, ColumnLines -> True,
GridFrame -> True, RowAlignments -> Center,
ColumnAlignments -> Center,
GridBoxSpacings -> {"RowsIndexed" -> {-2 -> 6}}] //DisplayForm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With