# How to cap ImageSize at the notebook width?

Graphics[{Circle[]}, ImageSize -> Automatic] creates a figure which is 360 pixels wide (same as Medium), if it fits in the notebook window. Otherwise, its size is reduced to fit.

Is it possible to have a size specification which is similarly capped at the notebook width, but has a default size different from 360 pixels?

Graphics[{Circle[]}, ImageSize -> UpTo[500]] does not do this.

The use case is having a large figure on screen, but making sure it fits on the page when printing.

Is it possible to get it done without Dynamic? If not, what is the best way with Dynamic? The following uses the window width instead of the actual available space:

Graphics[Circle[],
ImageSize -> Dynamic@Min[500, First@CurrentValue[WindowSize]]]


I am looking for solutions which work just like ImageSize -> Automatic, except that the default size is something else than 360 pixels. I strongly prefer solutions that do not require a running kernel.

• ImageResize[Graphics[{Circle[]}], 500] – J42161217 Apr 18 '17 at 11:42
• @Jenny_mathy That will first rasterize the figure, then resize it with low quality. If we want to rasterize, it would be better to use Rasterize[fig, ImageSize -> 500]. But I do not want to rasterize it. – Szabolcs Apr 18 '17 at 11:58
• I take it that Full is too big? "When the cell is printed, ImageSize->Full corresponds to the full width of the content area of the page." – Alan Apr 18 '17 at 13:09
• @Alan Yes. It may cause the bottom of the figure to be cut off. Even if it doesn't, after a certain point further magnification is not a benefit. I would rather see several small plots above each other than a single huge one. However, 360 pixels is a bit too small for my current application. It causes labels in a BarChart to overlap (even after 90 deg rotation). – Szabolcs Apr 18 '17 at 13:21
• There is not serious problem of course. But if there is a way to do this, it would be nice. – Szabolcs Apr 18 '17 at 13:22

I'm not sure it is what you want, but have you tried

CurrentValue[EvaluationNotebook[], "GraphicsBoxOptionsImageSizeRaw"] = 500


This instantly resizes all graphics inside a notebook to 500 pixels as long as your notebook window is large enough.

As @Kuba pointed out, this can be used as option for Graphics

Graphics[{Circle[]},
ImageSize -> Automatic,
BaseStyle -> "GraphicsBoxOptionsImageSizeRaw" -> 200]


Another possibility due to @CarlWoll is

Graphics[Circle[], ImageSizeRaw -> {500}]


## How I found it

Initially, I was sure I had seen an option for that so I looked through

AbsoluteOptions[\$Notebooks]


It turned out that what I had in mind was the option "DefaultNewGraphics" which is something else. My next thought was that it is very likely that this is exposed through CurrentValue. We have a question about all possible current values which led me, only the devil knows how, to this pastebin. A quick scan revealed the "GraphicsBoxOptionsImageSizeRaw" setting.

• Almost. I wonder if this is settable at the level of Graphics. It seems to be settable in BoxData as GraphicsBoxOptions->{ImageSizeRaw->130}. This is definitely useful in practice, though not exactly what I asked in the question. – Szabolcs May 9 '17 at 14:16
• Well, @Kuba just gave the answer. Can you include that in the answer? And who shall I give the bounty to now? :) – Szabolcs May 9 '17 at 14:17
• @Szabolcs Already on it. – halirutan May 9 '17 at 14:18
• An alternate version is: Graphics[Circle[], BaseStyle -> {GraphicsBoxOptions -> {ImageSizeRaw -> {700}}}]. Notice the use of {700} instead of 700. – Carl Woll May 9 '17 at 14:37
• Or even Graphics[Circle[], ImageSizeRaw->{500}] – Carl Woll May 9 '17 at 15:55

This is not a general solution but an improvement for Dynamic approach. It will run completely FrontEnd side:

Graphics[Circle[]
, ImageSize -> Dynamic @ If[
FEPrivateLess[CurrentValue[{WindowSize, 1}] - 100, 500]
, Full
, 500
, 500
]
]


-100 is unfortuantely manual, will try to get margins+toolbars width somehow.

• Looks like you need First@CurrentValue["DocumentAndWindowSize"]`. – Alexey Popkov May 10 '17 at 6:54
• @AlexeyPopkov looks like this + CellMargins should be enough. Having trouble combining them though :/ – Kuba May 10 '17 at 11:31