Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 5 down vote accepted

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.

share|improve this answer

A slight variation:

Grid[MapAt[Item[#, Frame -> True] &, tab, {{1, 1}, {1, 2}}]]
share|improve this answer

A slight variation of a slight variation:

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

MapAt[frRow, tab, 1] // Grid

Mathematica graphics

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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