The following code returns a framed text box that is longer than the standard width of `Graphics'.

Graphics@Text@Framed@Style[FooBarFooBarFooBarFooBarFooBarFooBar, 18]

incomplete framed box

Is there a way to automatically increase the size of the Graphics that is returned to fit the entire framed box?

(This question is related to my question Rasterize and Graphics, size difference and its answer. In particular, one cannot use `Rasterize' to determine the width of the box, it seems.)

  • $\begingroup$ Win OS 7 x 64 Mathematica v10.2 - does not reproduce whats stated in OP $\endgroup$ Feb 5, 2016 at 0:09
  • $\begingroup$ I do see what the OP described (i.e. clipping of the frame on the left and right side of the picture) on MMA on Win7-64bit. It's quite weird actually. $\endgroup$
    – MarcoB
    Feb 5, 2016 at 0:38

2 Answers 2


It looks like the front end method to determine the width does not account for the full size of the frame.

To fix/work around you can add margins to the text and rasterize before passing it to Graphics:

  Text[Framed[Style[FooBarFooBarFooBarFooBarFooBarFooBar, 18], 
   ImageMargins -> 50]], RasterSize -> 800]]



As @Algohi pointed out in the comments (thanks!) we could use a pure function to automatically determine the size of the raster, and pass to Graphics, lending to a solution using native Text object with a specified size:

Graphics[Text@#, Options[Rasterize@#, ImageSize]] &[
 Framed[Style[FooBarFooBarFooBarFooBarFooBarFooBar, 18]]]

edit raster

  • 1
    $\begingroup$ This will make it automatic Graphics[Text@#, Options[Rasterize@#, ImageSize]] &[ Framed[Style[FooBarFooBarFooBarFooBarFooBarFooBar, 18]]] $\endgroup$ Feb 5, 2016 at 1:16
  • $\begingroup$ @Algohi N ice- I incorporated this into an edit. Thanks! $\endgroup$ Feb 5, 2016 at 1:25

To make it automatic without rasterizing use ImageSize->Full:

Graphics[Text@Framed@Style[FooBarFooBarFooBarFooBarFooBarFooBar, 18], 
 ImageSize -> Full]


Graphics[Text@Framed@Style[FooBarFooBarFooBarFooBarFooBarFooBar, 18], 
 ImageSize -> {Full, Automatic}]
  • 2
    $\begingroup$ Both options increase the maximal automatic Graphics size from 360 to 432 but the problem persists. $\endgroup$
    – Berg
    Feb 5, 2016 at 7:55
  • $\begingroup$ @Berg What OS are you using? On Mac the entire framed text is visible. i.e. it is not longer than the standard width of Graphics as per your opening sentence. $\endgroup$ Feb 5, 2016 at 22:43
  • $\begingroup$ I use Win 10 with MMA 10.3.1. Also, I use a 4K display and because of that a magnification of 2 (because of the low quality user interface of MMA this sometimes breaks things). $\endgroup$
    – Berg
    Feb 6, 2016 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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