I have a rectangle with specified dimensions and I'd like to fill it with text, so that the text uses all (well, as much as possible) of the available area.

I tried to do it with

  TextCell[ExampleData[{"Text", "LoremIpsum"}],
   TextJustification -> 0, TextAlignment -> Center, ImageMargins -> 0], 
  ImageSize -> 1/2 {1920, 1080}, ImageSizeAction -> "ResizeToFit", 
  Alignment -> {Center, Center}]

I'm not concerned about the little gaps caused by the TextJustification option, but ImageSizeAction -> "ResizeToFit" bothers me because it leaves empty spaces at the top and bottom of the rectangle. This becomes more apparent when the rectangle size gets bigger, and I want to make some very large images.

Rectangle size 960x540:

small rectangle

Rectangle size 1920x1080:

bigger rectangle

I would expect that the font size would increase to fill the empty space, but this does not happen.

  • $\begingroup$ Strange indeed. If I magnify my view at some point it behaves correctly. I would try to do it differently because the end user could just change his zoom and ruin the format. Leaving the fonts free to get magnified seems troublesome.By the way, if you don't use ImageSize at all it seems fine. $\endgroup$
    – tchronis
    Mar 2, 2014 at 13:27
  • $\begingroup$ Looks like a bug to me. I used StringTake[ExampleData[...], n] and varied n with a Manipulate. For some string lengths the font is magnified as expected, for others it isn't. $\endgroup$ Mar 2, 2014 at 13:53

1 Answer 1


You can use a scaled font size with FontSize -> Scaled[1/100] that automatically changes with the rectangle size (but all of the text might not be used). This gives the following rectangles:

960 × 540

1920 × 1080

  • $\begingroup$ One limitation is that Scaled depends on the width and not on the height. If the aspect ratio of all the images is the same, then it won't be much of a problem. $\endgroup$
    – Michael E2
    Mar 2, 2014 at 17:30
  • $\begingroup$ Thanks, with FontSize -> Scaled[] and the addition of FontTracking and LineSpacing (and lots of trial and error) I managed to completely fill the rectangle. It should be noted that as soon as the text overflows the rectangle and is cut off, the evaluation takes a really long time - this is most probably a bug. $\endgroup$
    – shrx
    Mar 2, 2014 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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