Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am regularly annoyed by the fact, that a neatly arranged Print statement gets ruined by a large piece of data, which - instead of linewrapping "in place" - is pushed below the preceding label. See example:

Print[
  "test line 1...............: ", {1, 2, 3}, "\n",
  "test line 2...............: ", 
  Pane[Table["testestestestestestestestest", {10}], 800], "\n",
  "test line 3...............: ", {1, 2, 3}
  ];

which produces the following output:

Mathematica graphics

Question

Is it possible to tell the Pane object to wrap its content in a way that does not force the Table to shift to the next line, but is linewrapped in-place (i.e. right next to "test line 2")? Of course I can specify an explicit width for Pane, but since I don't know how big is my screen (user's screen), how large in pixels is the label text ("test line 2"), and many other factors, it just seems useless to give a magic number that should cover all situations. Full and All does not work either. Any idea?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

The option ImageSize with the value Scaled should give better results, and it will adapt to the size of the notebook window. You will still need to define the value of Scaled to allow for likely widths of the label in the first column.

Print["test line 1...............: ", {1, 2, 3}, "\n", 
  "test line 2...............: ", 
  Pane[Table["testestestestestestestestest", {10}], 
   ImageSize -> Scaled[0.5]], "\n", 
  "test line 3...............: ", {1, 2, 3}];

enter image description here

I agree that Grid is a better option here. But if you stick with Print, for example because you want to keep this output as a side effect of evaluation, you might also want to consider wrapping that long table output in TableForm.

share|improve this answer
    
Exactly what I was looking for, thanks. –  István Zachar Jan 19 '12 at 10:01

Just realized, that the simplest method would be to use Grid instead of Print. Still it would be nice to solve this by using Print and Pane.

Grid[{
  {"test line 1...............: ", {1, 2, 3}},
  {"test line 2...............: ", 
   Pane[Table["testestestestestestestestest", {10}], 800]},
  {"test line 3...............: ", {1, 2, 3}}
  }, Alignment -> {Left, Center}, Spacings -> {.5, 1}]

output:

Mathematica graphics

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.