Message Boards Message Boards

0
|
5304 Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Can the PageWidth for an Output cell be selectively set?

Posted 4 years ago

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.

POSTED BY: 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

POSTED BY: Neil Singer

This works and is probably more what you want:

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

Regards,

Neil

POSTED BY: Neil Singer
Posted 4 years ago

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

POSTED BY: Andrew

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

Style[
   StringJoin[RandomChoice[Characters["abcdefghijklmnopqrstuvwz"], 200]],
   LineBreakWithin -> False
]
POSTED BY: Kuba Podkalicki
Posted 4 years 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.

POSTED BY: Andrew
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