Message Boards Message Boards

GROUPS:

Can the PageWidth for an Output cell be selectively set?

Posted 1 year ago
1725 Views
|
5 Replies
|
0 Total Likes
|

Is possible to set the PageWidth of an output cell without having to manually use the Format->Word Wrapping menu? For example, how could one add to the following Input expression to cause the output to have PageWidth->Infinity?

 StringJoin[RandomChoice[Characters["abcdefghijklmnopqrstuvwz"], 200]]

CellPrint seems too low-level since it ignores the settings of other options, such as cell margins. SetOptions works fine if I want the wrapping to be the same for all Output cells (which I don't). I tried working with CurrentValue, but did not have any success.

I also tried

SetOptions[$Output, PageWidth -> Infinity]
StringJoin[RandomChoice[Characters["abcdefghijklmnopqrstuvwz"], 200]]

but it had no effect.

Thanks in advance for any tips/pointers,

Andrew.

5 Replies

Andrew,

You can do that by selecting the cell and setting the option. The first line just selects the previous output cell. The second line sets the width for that line. (you also have multiple other options for the width).

SelectionMove[PreviousCell[], All, Cell]; 
SetOptions[NotebookSelection[], PageWidth -> "Infinity"]

Is this what you were looking for (a way to take an already generated cell and change its width)?

Regards,

Neil

This works and is probably more what you want:

StringJoin[RandomChoice[Characters["abcdefghijklmnopqrstuvwz"], 200]]
SetOptions[NotebookSelection[], PageWidth -> "Infinity"]

Regards,

Neil

Posted 1 year ago

Thank you, Neil. That second option is exactly what I needed. And it works with or without the quotes around Infinity.

Here, is an alternative to the PageWidth -> Inifnity:

Style[
   StringJoin[RandomChoice[Characters["abcdefghijklmnopqrstuvwz"], 200]],
   LineBreakWithin -> False
]
Posted 1 year ago

Kuba,

Your alternative seems to be a better choice for Grid. The following does not work:

Grid[{StringJoin /@ 
   Partition[
    RandomChoice[Characters["abcdefghijklmnopqrstuvwz"], 200], 50]}, 
 Frame -> All]
SetOptions[NotebookSelection[], PageWidth -> "Infinity"]

But your approach:

Style[Grid[{StringJoin /@ 
    Partition[
     RandomChoice[Characters["abcdefghijklmnopqrstuvwz"], 200], 50]}, 
  Frame -> All], LineBreakWithin -> False]

does work.

I am curious why the SetOptions code is not working, especially when I can manually set that cell (Format->Word Wrapping) to not word wrap and it behaves as I would expect.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract