4
$\begingroup$

In Mathematica 13, I would like to have text displayed in a rectangular area (that will later be included in graphics), where the size of the rectangle needs to be set in advance. If there's too much text to fit inside the rectangle, I'd like it to be automatically shrunk so that it does fit. (I'd also like to control the justification and so on while still having the text line breaks done automatically.)

I thought that the ImageSizeAction -> "ShrinkToFit" option for Pane was exactly what I needed. But I'm puzzled by what it actually does. As I increase the coded font size, more and more of the rectangle is filled by larger text as expected … to a point. But then as the coded font size increases further, for some reason less and less of the rectangle is filled, and the displayed font size becomes smaller and smaller again.

Why is it doing this? How can I make sure that most of the rectangle is used to display the text?

loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla a sem mattis, tincidunt sem eu, vestibulum quam. Integer sagittis nulla eget pretium accumsan. Proin rutrum bibendum lorem quis maximus. Morbi feugiat lobortis rutrum. Quisque imperdiet porta tincidunt. Integer egestas mi at odio accumsan ullamcorper. Nulla rutrum maximus tellus, facilisis fringilla sapien sollicitudin vel. Sed feugiat arcu at quam accumsan luctus.";
Manipulate[
 Pane[
  TextCell[loremIpsum, FontSize -> f ,
   FontFamily -> "Garamond", TextJustification -> 1, Hyphenation -> False, LineSpacing -> {1, 0}, Background -> RGBColor[0.9, 0.9, 1]]
  , {200, 300}, Alignment -> {Center, Bottom}, 
  ImageSizeAction -> "ShrinkToFit"]
 , {f, 8, 36, 1}]
$\endgroup$
3
  • 1
    $\begingroup$ It seems to work as expected without the TextJustification->1 option $\endgroup$
    – MelaGo
    Sep 2, 2023 at 23:33
  • 1
    $\begingroup$ Even TextJustification -> 0.9 looks OK. $\endgroup$
    – MelaGo
    Sep 2, 2023 at 23:38
  • 1
    $\begingroup$ That is bizarre—! TextJustification -> 0.995 still looks good, TextJustification -> 0.996 is back to weirdness…. $\endgroup$ Sep 2, 2023 at 23:56

0

Your Answer

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

Browse other questions tagged or ask your own question.