2
$\begingroup$

I am looking to put quite a bit of text in a graphic. I want the text to be in a box with rounded corners and the box to drop a shadow. I want each paragraph to have a small hanging indent (LineIndent -> 1). I also want each paragraph in the box to have a different margin color that would flag the different types of paragraphs to the reader. Ideally, I would like that color to be a rectangle that is intense at the top and bottom and fades or gradients out in the middle. Perhaps a different way to say this is that, instead of a background color, I want the text to get only the left side of a box around it, that to be thick, colored and to fade out and back in.

This is a sketch of the direction I am going:

enter image description here

Here is a sample of code that does not work:

Graphics[{Circle[], 
  Text[Boxed@
    Style["The lazy fox jumped over the quick dog. The lazy fox \
jumped over the quick dog. The lazy fox jumped over the quick dog. \
The lazy fox jumped over the quick dog. The lazy fox jumped over the \
quick dog.", Background -> LightRed, FontFamily -> "Georgia"]
   , {1, 1}]
  }]

Many thanks for your help.

$\endgroup$

1 Answer 1

5
$\begingroup$

Something to get you started:

frame[col_] := ImageResize[Image[Rasterize[
     Cell[BoxData@ToBoxes@Graphics[{
          {LinearGradientFilling[{0, 0.45, 0.55, 1} -> {col, 
              Lighter[col, 0.9], Lighter[col, 0.9], col}, Bottom],
           Rectangle[{0, 0}, {3, 20}]},
          AbsoluteThickness@1,
          Black,
          Rectangle[{-1, 10}, {0, 11}],
          Rectangle[{3, 20}, {4, 21}],
          Rectangle[{4, -1}, {5, 0}],
          Rectangle[{6, 0}, {7, 20}]
          },
         PlotRangePadding -> None,
         ImageSize -> {8, 22}
         ],
      CellMargins -> {{0, 0}, {0, 0}},
      CellFrameMargins -> {{0, 0}, {0, 0}}
      ],
     RasterSize -> 2 {8, 22},
     ImageSize -> 2 {8, 22}
     ], ImageResolution -> Automatic], 8, Resampling -> "Nearest"];
Image[ImageResize[frame[Red], 120, Resampling -> "Nearest"], 
 ImageSize -> 50]

This produces an image that can be used as a 9-patch appearance:

enter image description here

We can now use this appearance for the panels for the individual paragraphs, and apply the remaining styling:

Graphics[
 {DropShadowing[],
  Text@Style[Framed[
     Pane[
      Column[
       {
        Panel[
         "The lazy fox jumped over the quick dog.The lazy fox jumped \
over the quick dog.The lazy fox jumped over the quick dog.", 
         Appearance -> {"Default" -> frame[Red]}],
        Panel[
         "The lazy fox jumped over the quick dog.The lazy fox jumped \
over the quick dog.The lazy fox jumped over the quick dog.", 
         Appearance -> {"Default" -> frame[Blue]}]
        },
       Left
       ],
      UpTo@150
      ],
     RoundingRadius -> 5,
     Background -> White
     ],
    PanelBoxOptions -> {BaseStyle -> {FontFamily -> "Georgia", 
        LineIndent -> 1, TextAlignment -> Left}}
    ]
  }
 ]

enter image description here

$\endgroup$
6
  • $\begingroup$ I am having trouble reproducing your results in my 13.1 version. My text gets covered with all the columns of your first graph and they do not start to the left of the text; they function as its background. Could you please explain your code more? Also, your text is centered; I cannot figure out where would an Alignment->Left option belongs. $\endgroup$
    – Nicholas G
    Apr 7, 2023 at 17:07
  • 1
    $\begingroup$ @NicholasG Sorry, completely forgot about the TextAlignment option, I added it now. As for the other issue: It seems version 13.1 has some "interesting" behavior for Rasterize, should be fixed now $\endgroup$
    – Lukas Lang
    Apr 7, 2023 at 18:36
  • $\begingroup$ I am stumped at italicizing or making bold some words in the text. If I use Row@{Style[...],Style[...],...} the text gets messed up with extra line breaks and different widths. Any ideas? $\endgroup$
    – Nicholas G
    Apr 16, 2023 at 23:41
  • 1
    $\begingroup$ You can use "normal text " <> ToString[Style["styled text ", Italic], StandardForm] <> "more normal text", or equivalently, use the Format menu to style the string as you want $\endgroup$
    – Lukas Lang
    Apr 17, 2023 at 9:30
  • 1
    $\begingroup$ That's because you forgot the second argument (StandardForm) of ToString - at least for me, your example works as expected if I add that $\endgroup$
    – Lukas Lang
    Apr 18, 2023 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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