I need to add some text to rectangles that I am using as a scale bar. I want the text right above the rectangle and centered. Here’s my code:
Show[{Graphics[{Red, Rectangle[{0, 0}, {45, 15}]}, ImageSize -> 48], Graphics[Text[Style["TEXT", 12, "TR", Black, Bold]]]}]
Desired result:
How can I do that?
Edit: Ideally it should also work if the text is longer than the scale bar, like so:
Graphics[{Red, Rectangle[{0, 0}, {19, 15}], Text[Style["TEXT", 14, "TR", Black, Bold], {10, 22}]}, ImageSize -> 19]
The bar crops some of the text: