1
$\begingroup$

Writing:

list = ConstantArray[0, {2, 35}];
doc = 
  CreateDocument[ExpressionCell[TableForm[list, TableSpacing -> {2, 2}], "Output"]];
Export["test.pdf", doc];

I get the following pdf document:

enter image description here

where it is evident that it does not automatically go to the end, but cuts part of the table.

Any suggestions for automatic line wrapping?

$\endgroup$
1
$\begingroup$

Use TableSpacing -> {2, 1} to shrink the width.

Alternatively, to line wrap after 24 items.

doc = CreateDocument[ExpressionCell[TableForm[
    Flatten[Partition[#, UpTo[24]] & /@ list, 1],
    TableSpacing -> {2, 2}], "Output"]]

Edit

To automatically adjust

cellsize[n_] := ImageDimensions[Rasterize[
   cell = ExpressionCell[TableForm[
      Flatten[Partition[#, UpTo[n]] & /@ list, 1],
      TableSpacing -> {2, 2}], "Output"]]]

list = ConstantArray[0, {2, 35}];

x = 24;

cellsize[24]

{582, 80}

582 is the minimum width. Now making a list with larger items.

list = ConstantArray[1234, {2, 35}];

cellsize[24]

{1086, 80}

While[First[cellsize[x]] > 582, --x]
doc = CreateDocument[cell];
$\endgroup$
  • $\begingroup$ @Chris_Degnen: yes, in the minimum example shown without doubt. But I would need something automatic, because the tables I deal with are always 35 columns, but in general I do not know what they contain. $\endgroup$ – TeM Mar 7 '18 at 14:06
  • $\begingroup$ @Chris_Degnen: simply perfect! Thank you! $\endgroup$ – TeM Mar 7 '18 at 15:29

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.