Question:

How to reduce margins of text in GraphicsRow?

Adam: 3 days ago

I used the code GraphicsRow[{Text["1"], Graphics[Disk[]], Graphics[Disk[]]}] to generate a row of graphics, but one of them is actually some text. I found that GraphicsRow will try to put an "image frame" to make the text area have the same overall size as other graphics in this row. If the text is short, it has too much white margin on both sides; if the text is long, it adds a line break. My question is, is their a way I can adjust the "image frame size" of the text, so the text (or text grid) can fit in the row with a proper width?

enter image description here

enter image description here

Answer:
Lily: 3 days ago

There's an undocumented option "ManualSizes" but you have to manually set all the ImageSizes. Sometimes if the heights are different, strange things happen. You can use Rasterize[g, "RasterSize"] to help figure out the ImageSizes.

Also, Text does not scale if the graphics are resized; in other words, if you drag one of the resize corners or edges of the graphics, you may cut off part of the text or introduce extra space. (This is true of Graphics[] in general.)

textwidth[t_] := First@Rasterize[Style[Text[t], "Graphics"], "RasterSize"];

lbl = "1";
GraphicsRow[{
  Graphics[Text[lbl], ImageSize -> {textwidth[lbl], 200}],
  Graphics[Disk[], ImageSize -> {200, 200}],
  Graphics[Disk[], ImageSize -> {200, 200}]},
 "ManualSizes" -> True]

enter image description here

lbl = Style[StringJoin@CharacterRange["A", "Z"], Large];
GraphicsRow[{
  Graphics[Text[lbl], ImageSize -> {textwidth[lbl], 360}],
  Graphics[Disk[], ImageSize -> {360, 360}],
  Graphics[Disk[], ImageSize -> {360, 360}]},
 "ManualSizes" -> True]

enter image description here