1
$\begingroup$

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

$\endgroup$
  • 1
    $\begingroup$ why not Row instead of GraphicsRow? $\endgroup$ – kglr Dec 29 '18 at 5:24
  • 1
    $\begingroup$ It seems with Row the spacings between elements cannot be set to different values and it tends to force line break when there are more elements. $\endgroup$ – nanjun Dec 29 '18 at 17:03
2
$\begingroup$
Grid[{{Graphics[{Text["1"]}, ImageSize -> {All, 10}], 
  Graphics[Disk[]], Graphics[Disk[]]}}, 
 Spacings -> {{2 -> 1, 3 -> 5}, 0}]

enter image description here

Grid[{{Graphics[{Text["1234567890123456789012345678901234567890"]}, ImageSize -> {All, 10}], 
  Graphics[Disk[]], Graphics[Disk[]]}}, 
 Spacings -> {{2 -> 1, 3 -> 5}, 0}]

enter image description here

$\endgroup$
2
$\begingroup$

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

$\endgroup$

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.