Suppose there are nth columns in my TableForm of data. Mathematica enables users to label their header. However, is there a way to add header only the nth column? What about adding headings to a set of columns between the $i^{th}$ and $j^{th}$ column?
2 Answers
$\begingroup$
$\endgroup$
Something like
makeHeadings[{imax_Integer, jmax_Integer}, headings, len_Integer] :=
Join[Table["", {imax - 1}], headings, Table["", {len - jmax}]]
Usage:
makeHeadings[{3, 5}, {"a", "b", "c"}, 8]
{"", "", "a", "b", "c", "", "", ""}
Then,
TableForm[Array[a, {3, 8}], TableHeadings -> {None, makeHeadings[{3, 5}, {"a", "b", "c"}, 8]}]
$\begingroup$
$\endgroup$
1
Maybe you can use the grid?
Grid[{{Text["Cln2"], SpanFromLeft}, {a, b, c}, {d, e, f}, {g, h, i}}, Spacings -> {2, 2}]
or as @march suggested:
TableForm[{{a, b, c}, {d, e, f}, {g, h, i}}, TableHeadings -> {None, {"", "Cln2", ""}}]
(*But there is a line above the table*)
-
$\begingroup$ Is there a fast way to do this? That's what I'm looking for. If there are 1000 Columns that I wanted to have a "" heading, I cannot possibly do this for each one.. $\endgroup$– PhyskidCommented Nov 1, 2016 at 15:52
""
) for each of the columns where you don't want a heading. $\endgroup$headings=ReplacePart[ConstantArray["", 1000], 950 -> "Your Title"]
Creates an array of 1000 empty strings then replaces the 950th with a title. $\endgroup$