When answering this question, I suddenly realized that it is surprisingly difficult to determine the current width of the output cell contents.
I tried to employ the ResourceFunction "GraphicsInformation" as follows:
cellAreaWidth = First["ImageSize" /. ResourceFunction["GraphicsInformation"][Graphics[{}, ImageSize -> Full]]] 630.75
However, experimentation by trial and error shows that the returned value is always significantly larger than the actual value, what can be due to the following reasons:
The invisible
Notebookwindow (whichExportPacketcreates under the hood) has no frame and no vertical scroll bar.*The
Cellwhere theGraphicsobject is placed isn't a member of aCellGroup, and hence the cell bracket is single, not double.
Also, I tried to calculate the cell area width from the documented option values:
cellAreaWidth = AbsoluteCurrentValue[EvaluationNotebook[], WindowSize][[1]] - Tr[Total[AbsoluteCurrentValue[EvaluationCell[], #] & /@ {CellMargins, CellFrameMargins, CellLabelMargins}][[1]]] - Total[{"Margins", "Thickness", "Widths"} /. Options[EvaluationCell[], CellBracketOptions][[1, 2]], 2] 617.5
The obtained value seems to be very close to the actual value. But then I realized, that AbsoluteCurrentValue[EvaluationNotebook[], WindowSize] returns the full window size, which includes the space taken by the window frame and the vertical scroll bar (and I have no idea how to determine them).* Also, I'm not sure that the space taken by the cell bracket should actually be calculated as the sum of "Margins", "Thickness" and "Widths". And third, the calculated cell bracket width should be multiplied by two, because a generated "Output" cell normally has two cell brackets (because by default it is grouped with the parent "Input" cell). But in this case I get a lesser value.
So, I'm in a confusion.
How to determine the current width of the internal area of an "Output" cell (which is a member of a cell group)?
For tesing, I used the following setup (change the window width, evaluate and check whether the contents of Pane is formatted exactly the same as the contents of the generated "Output" cell):
cellContentsWidth = AbsoluteCurrentValue[EvaluationNotebook[], WindowSize][[1]] - Tr[Total[AbsoluteCurrentValue[EvaluationCell[], #] & /@ {CellMargins, CellFrameMargins, CellLabelMargins}][[1]]] - 2 Total[{"Thickness",(*"Margins",*)"Widths"} /. AbsoluteOptions[EvaluationCell[], CellBracketOptions][[1, 2]], 2] lst = ResourceFunction["CreateSortableUniqueID"][20] Pane[lst, ImageSize -> {cellContentsWidth, Automatic}, ImageSizeAction -> "ShrinkToFit", FrameMargins -> None] * According to the Documentation page for WindowSize,
The setting for
WindowSizespecifies the size of the content area of the window, excluding any frame.
But this statement is clearly false, because when the Notebook window is maximized (using the Maximize button on the window's title bar), its width from WindowSize is exactly equal to the width of the "Region" of the current display:
"Region" /. SystemInformation["Devices", "ConnectedDisplays"] AbsoluteCurrentValue[EvaluationNotebook[], WindowSize] {{{0., 1920.}, {0., 780.}}}
{1920., 747.75}
Checking shows that WindowSize doesn't depend on the presence of WindowFrame, WindowFrameElements and WindowElements:
ws1 = AbsoluteCurrentValue[EvaluationNotebook[], WindowSize][[1]]; SetOptions[EvaluationNotebook[], WindowFrame -> "Frameless", WindowFrameElements -> {}, WindowElements -> {}]; ws2 = AbsoluteCurrentValue[EvaluationNotebook[], WindowSize][[1]]; SetOptions[EvaluationNotebook[], WindowFrame -> Inherited, WindowFrameElements -> Inherited, WindowElements -> Inherited]; ws1 == ws2 True





