Skip to main content
3 of 3
deleted 34 characters in body
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

Here a test text. I use a gray background to show how large the bounding box actually is.

t = Graphics[Text["Test", BaseStyle -> {128}, Background -> Gray]]

Mathematica graphics

d = ImageDimensions[ImageCrop[t]];
Graphics[{
  FaceForm[], EdgeForm[Red],
  Text["Test", {0, 0}, {-1, -1}, BaseStyle -> {128}],
  Rectangle[{0, 0}, Offset[d, {0, 0}]],
  PointSize[0.05], Point[{0, 0}]
}]

Mathematica graphics

If you want a closer cut for your bounding box, just remove the Background option and ImageCrop again. However, note that offsets in the Text function are with respect to the bounding box Mathematica uses (indicated by the gray box).

t = Graphics[Text["Test", BaseStyle -> {128}]];
d = ImageDimensions[ImageCrop[t]];
Graphics[{
  FaceForm[], EdgeForm[Red],
  Text["Test", {0, 0}, {-.97, -0.6}, BaseStyle -> {128}],
  Rectangle[{0, 0}, Offset[d, {0, 0}]],
  PointSize[0.05], Point[{0, 0}]
}]

Mathematica graphics

Note the {-.97, -0.6} offset?

Sjoerd C. de Vries
  • 66.2k
  • 15
  • 189
  • 327