2

When I try this:

Framed@Graphics[{Text[
    Style["Text", FontSize -> 50, Bold, Black, Background -> Green, 
     FontFamily -> "Calibri"]]}]

enter image description here

I get a centered text with a large empty space around.

How can I align the text e.g. to left or how can I make the frame as large as the text is?

4
txt = Text[Framed[Style["Text", FontSize -> 150, Bold, Black, 
    FontFamily -> "Calibri"], Background -> Green, ContentPadding -> False]]; 
Graphics[txt, ImageSize -> Rasterize[txt, "RasterSize"]]

enter image description here

Alternatively, use the second argument of Text to specify the position:

txtb = Text[Framed[Style["Text", FontSize -> 150, Bold, Black, 
     FontFamily -> "Calibri"], Background -> Green, ContentPadding -> False], {0, 0}];
Graphics[txtb]

same picture

txt2 = Text[Framed[Style["TextTextTextTextText\nTextTextTextTextText", 
     FontSize -> 64, Bold, Black, FontFamily -> "Calibri", 
     LineSpacing -> {1, -10}], Background -> Green, ContentPadding -> False]];
Graphics[txt2, ImageSize -> Rasterize[txt2, "RasterSize"]]

enter image description here

Using the second approach:

txt2b = Text[Framed[Style["TextTextTextTextText\nTextTextTextTextText", 
     FontSize -> 64, Bold, Black, FontFamily -> "Calibri", 
     LineSpacing -> {1, -10}], Background -> Green, ContentPadding -> False], {0, 0}];
Graphics[txt2b]

same picture

3

You need to adjust ImageSize

Framed[Graphics[{Text[
    Style["Text", FontSize -> 150, Bold, Black, 
     FontFamily -> "Calibri"]]},  ImageSize -> {275, 105}], 
 Background -> Green]

enter image description here

Or

   Framed[Text[
  Style["Text", FontSize -> 150, Bold, Black, 
   FontFamily -> "Calibri"]], Alignment -> Center, 
 Background -> Green, FrameMargins -> 0, ContentPadding -> False, 
 ImageSize -> {277, 108}]

enter image description here

Framed[Text[
  Style["Red Fox jr", FontSize -> 150, Bold, Black, 
   FontFamily -> "Calibri"]], Alignment -> Center, 
 Background -> Green, FrameMargins -> 0, ContentPadding -> False]

enter image description here

  • This looks good, but the values {275, 105} of ImageSize are set manually. Is it possible to find these values from the given "Text"? – mrz 17 hours ago
  • I don't know how to reduce top and bottom space.. – Okkes Dulgerci 17 hours ago
3

I would use a slightly different approach which gives more flexibility.

Graphics[{Green, EdgeForm[Black], Rectangle[{0, 0}, {2, 1}], (*Green Background*)
 Inset[Style["Text", FontSize -> 150, Bold, Black,FontFamily -> "Calibri"],
 {0, 0}, {Left, Bottom}]}] (*position and alignment*)

enter image description here

Or some tilting

q = Pi/6;
Graphics[{Green, EdgeForm[Black], Rectangle[{0, 0}, {2, 1}], 
 Inset[Style["Text", FontSize -> 100, Bold, Black, FontFamily -> "Calibri"],
 {0.5, 0}, {-1,-0.5}, {Cos[q],Sin[q]}]}]

enter image description here

Look at Inset for more options.


For Text in a box

wordbox[text_, fontsize_, fontcolor_, font_, background_] := 
       Framed[ImageCrop@Rasterize@Style[text, FontSize -> fontsize, Bold, fontcolor, 
       FontFamily -> font, Background -> background],
       Background -> background, FrameMargins -> 0]

wordbox["Text", 100, Blue, "Calibri", Red]
wordbox["Texture", 100, Black, "Calibri", Green]

enter image description here

  • Thank you for the solution. How to you set the rectangle to the minimal size which holds the word "Text"? – mrz 19 hours ago

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.