I was wondering what the best way is to extend the cells in a GraphicsGrid so that my text fits without line breaks. My problem is illustrated by the graphic produced by the code below:

  {Graphics[{Blue, Rectangle[{1, -1}]}], 
   Style["Antidisestablishmentarianism", FontSize -> 30], 
  {Graphics[{Red, Rectangle[{1, -1}]}], 
   Style["Pneumonoultramicroscopicsilicovolcanoconiosis", FontSize -> 30],

enter image description here

I've been looking for ways to extend the cells on the right of the GraphicsGrid so that the text fits in on one line. In the code above, I've used SpanFromLeft to extend the cells a little. I would have to use many SpanFromLeft commands in order to fit the word next to the red square. So I was hoping that someone knew of a better way of doing this.

  • $\begingroup$ yes, but then I can't control image size, and I need to do that $\endgroup$ – Mas May 12 '14 at 12:13
  • $\begingroup$ To clear things up, I meant the size of the whole Grid. Essentially what I want is for the cells on the right hand side to be wider; just wondering if there's a better way of doing this than repeated SpanFromLeft's $\endgroup$ – Mas May 12 '14 at 12:54

Tell me if that fits you:

grid = Grid[
  {Graphics[{Blue, Rectangle[{1, -1}]}, ImageSize -> 100], 
   Style["Antidisestablishmentarianism", FontSize -> 30], SpanFromLeft}, 
  {Graphics[{Red, Rectangle[{1, -1}]}, ImageSize -> 100], 
   Style["Pneumonoultramicroscopicsilicovolcanoconiosis", FontSize -> 30], SpanFromLeft}
 }, ItemSize -> {{10, 60}}]

Then taking that answer:

  ImportString[ExportString[#, "PDF"], "TextOutlines" -> True] &@ grid,
  ImageSize -> 100]

enter image description here

Then ImageSize can be used as will:

enter image description here

  • $\begingroup$ That would work. I was kind of hoping there was a simple autofit option $\endgroup$ – Mas May 12 '14 at 13:02
  • $\begingroup$ The text autofits with Grid. Using the Show[] part allows you to change the ImageSize. $\endgroup$ – Öskå May 12 '14 at 13:03
  • 1
    $\begingroup$ @Öskå After applying ImportString[ExportString[#, "PDF"]] & you have no text: every glyph is outlined. It is the standard way to outline fonts in Mathematica. $\endgroup$ – Alexey Popkov May 12 '14 at 13:41
  • $\begingroup$ @AlexeyPopkov I don't get if this is a problem or not.. :) $\endgroup$ – Öskå May 12 '14 at 13:47
  • 1
    $\begingroup$ @Max Check What should I do when someone answers my question? and Accepting Answers: How does it work? regarding accepting answers. That concerns your two last questions with valuable answers. $\endgroup$ – Öskå May 12 '14 at 23:25

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.