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:


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


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


3 Answers 3


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.


A slight variation:

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

A slight variation of a slight variation:

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

MapAt[frRow, tab, 1] // Grid

Mathematica graphics


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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