3
$\begingroup$

Suppose that I use Grid to display a table tab. I did the following, which frames all cells:

tab = {{"a", "b"}, {"1", SpanFromLeft}, {"2", SpanFromLeft}, {"3", SpanFromLeft}};
Grid[tab, Frame -> All]

and gives this output:

gridall

But, how do I programatically generate a table in which only the header cells are framed?

gridsome

(I created the above by erasing cell dividers manually, using Paint, but for larger tables, I would like to do this programatically.) Thanks.

$\endgroup$
5
$\begingroup$

You can explicitly frame only those elements and not frame the rest. For example:

Grid[tab, Frame -> {None, None, {{1, 1} -> True, {1, 2} -> True}}]

enter image description here

To extend this to grids with $n$ columns in the header, you could replace the last element of the RHS of the Frame option with

Table[{1, i} -> True, {i, n}]

where n is an integer.

$\endgroup$
3
$\begingroup$

A slight variation:

Grid[MapAt[Item[#, Frame -> True] &, tab, {{1, 1}, {1, 2}}]]
$\endgroup$
2
$\begingroup$

A slight variation of a slight variation:

frRow = Item[#, Frame -> 1] & /@ # &;

MapAt[frRow, tab, 1] // Grid

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.