Looking at the solution from Alexey Popkov I have seen that the RawInputForm
(Shift-Ctl-r) of the generated output is
Grid[{{TextCell[Row[{"This goes to the first column"}], PageWidth -> 150],
TextCell[Row[{"and this to the second one"}], PageWidth -> 150], Null,
Null}, {TextCell[Row[{"x=", x}], PageWidth -> 150],
TextCell[Row[{"x^2="}], PageWidth -> 150], TextCell[Row[{x^2}],
PageWidth -> 150], TextCell[Row[{"Squares are easily computed by hand."}], PageWidth -> 150]},
{TextCell[Row[{"x=", x}], PageWidth -> 150], TextCell[Row[{"Sqrt[x]="}],
PageWidth -> 150], TextCell[Row[{Sqrt[x]}], PageWidth -> 150],
TextCell[Row[{"Square roots are more difficult."}], PageWidth -> 150]},
{TextCell[Row[{"x=", 2}], PageWidth -> 150], TextCell[Row[{"Sqrt[x]="}],
PageWidth -> 150], TextCell[Row[{Sqrt[2]}], PageWidth -> 150],
TextCell[Row[{"easy as a symbol"}], PageWidth -> 150]},
{TextCell[Row[{"x=", 2.}], PageWidth -> 150], TextCell[Row[{"Sqrt[x]="}],
PageWidth -> 150], TextCell[Row[{1.4142135623730951}],
PageWidth -> 150], TextCell[Row[{"endless numerical work."}],
PageWidth -> 150]}}, Alignment -> Left,
ItemSize -> {Automatic, Automatic}]
Looking closer at it shows me that each TextCell
is equipped with an option PageWidth -> 150
. If I remove those options beginning at the second row, the appearance of the output remains looks as before after applying TraditionalForm
to the cell (mark the cell bracket, then press Shift-Ctl-t).
Then I have modified the widths of the columns like this:
Grid[{{TextCell[Row[{"This goes to the first column"}], PageWidth -> 80],
TextCell[Row[{"and this to the second one"}], PageWidth -> 150], Null,
Null}, {TextCell[Row[{"x=", x}]], TextCell[Row[{"x^2="}]],
TextCell[Row[{x^2}]], TextCell[
Row[{"Squares are easyly computed by hand."}]]},
{TextCell[Row[{"x=", x}]], TextCell[Row[{"Sqrt[x]="}]],
TextCell[Row[{Sqrt[x]}]], TextCell[
Row[{"Square roots are more difficult."}]]},
{TextCell[Row[{"x=", 2}]], TextCell[Row[{"Sqrt[x]="}]],
TextCell[Row[{Sqrt[2]}]], TextCell[Row[{"easy as a symbol"}]]},
{TextCell[Row[{"x=", 2.}]], TextCell[Row[{"Sqrt[x]="}]],
TextCell[Row[{1.4142135623730951}]],
TextCell[Row[{"endless numerical work."}]]}}, Alignment -> Left,
ItemSize -> {Automatic, Automatic}]
and after Shift-Ctl-t the column width of the first column becomes smaller (maintaining the nice property mentioned by Alexey when I reduce the window width).
This might give a hint how to prepare for different column widths. - My example was less than optimal since the first line has less columns than the following ones, resulting in the two entries Null
in the first line of the two-dimensional list to be shown.
One might further vary Alexey's output prepending it with a row only defining the columns widths and no text like this:
Grid[{{TextCell[Row[{""}], PageWidth -> 80], TextCell[Row[{""}],
PageWidth -> 80], TextCell[Row[{""}], PageWidth -> 150],
TextCell[Row[{""}], PageWidth -> 150]},
{TextCell[Row[{"This goes to the first column"}]],
TextCell[Row[{"and this to the second one"}]], Null, Null},
{TextCell[Row[{"x=", x}]], TextCell[Row[{"x^2="}]], TextCell[Row[{x^2}]],
TextCell[Row[{"Squares are easily computed by hand."}]]},
{TextCell[Row[{"x=", x}]], TextCell[Row[{"Sqrt[x]="}]],
TextCell[Row[{Sqrt[x]}]], TextCell[
Row[{"Square roots are more difficult."}]]},
{TextCell[Row[{"x=", 2}]], TextCell[Row[{"Sqrt[x]="}]],
TextCell[Row[{Sqrt[2]}]], TextCell[Row[{"easy as a symbol"}]]},
{TextCell[Row[{"x=", 2.}]], TextCell[Row[{"Sqrt[x]="}]],
TextCell[Row[{1.4142135623730951}]],
TextCell[Row[{"endless numerical work."}]]}}, Alignment -> Left,
ItemSize -> {Automatic, Automatic}]
This observation gives rise to a not yet solved idea to provide two functions:
PrintTableHeadline[headline_String, MaximumColumnWidths->list]
where headline
is a string consisting of the column headlines, separated by \t
and list
is a list of numbers representing the column widths (preferably in some practical unit like cm or mm).
Then PrettyPrint
should adopt the column widths from the last call to PrintTableHeadline
, accept all kinds of parameters like Print and separate the generated output to the columns like before.
It remains the problem to append subsequent output as a new row to an existing Grid
.