9
$\begingroup$

My question is rather simple. I want to put a title into a table.

For example, consider a list with depth two and a title

list = Range[4] & /@ Range[4];
title = "Bravo";

And I want to create a table from list, i.e.,

TableForm[list]

This will generate a table without a title. Let's say I want to make a title "Bravo" on top of the table(which is center-aligned).

Can you suggest a neat way to achieve it? I looked up the possible options for TableForm, but I could not find a relevant one.

$\endgroup$
12
$\begingroup$
Labeled[TableForm[list], title, Top]

enter image description here

Panel[TableForm[list], title, Top, Appearance -> "Frameless"]

enter image description here

Note: To remove quotes in title you can use:

Labeled[TableForm[list], Style[title, ShowStringCharacters -> False], Top]

enter image description here

Update: Post-processing the output of Jen's method to center the label and remove the divider line:

ClearAll[labelF]
labelF = RawBoxes[ToBoxes[#] /. HoldPattern[RowLines -> _] :> Rule[RowLines, False] ] &;

labelF@TableForm[{{list}}, TableAlignments -> Center, TableHeadings -> {None, {title}}]

enter image description here

$\endgroup$
9
$\begingroup$

Here is another approach using only the functionality of TableForm itself:

list = Range[4] & /@ Range[4];
title = "Bravo";
TableForm[{{list}}, TableHeadings -> {None, {title}}]

table

This nests the list deep enough inside {{ }} so that the column labels provided by TableHeadings are applied only to a single column containing the actual table. The result is that the column heading has become a table heading for the inner table.

$\endgroup$
0
$\begingroup$
Column[
{ToString["This is the title"],
TableForm[yourdata]},
Alignment-> Center]
$\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.