0
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ You could just use an empty string ("") for each of the columns where you don't want a heading. $\endgroup$ – march Nov 1 '16 at 15:27
  • $\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...@march $\endgroup$ – Physkid Nov 1 '16 at 15:52
  • 3
    $\begingroup$ headings=ReplacePart[ConstantArray["", 1000], 950 -> "Your Title"] Creates an array of 1000 empty strings then replaces the 950th with a title. $\endgroup$ – N.J.Evans Nov 1 '16 at 16:46
1
$\begingroup$

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]}]

enter image description here

$\endgroup$
0
$\begingroup$

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*)
$\endgroup$
  • $\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$ – Physkid Nov 1 '16 at 15:52

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.