1

This question inquires as to an extension of Daniel N.'s answer found in How to enhance the background of a Tikzpicture or a Tcolorbox

Consider the slightly modified code:

\documentclass[border=1cm]{book}
\usepackage{lipsum}

\usepackage{wrapfig} \usepackage[justification=centering]{caption} \usepackage{graphicx}

\usepackage{tikz} \usetikzlibrary{positioning} \usetikzlibrary{decorations.pathmorphing} \usetikzlibrary{shadows.blur} \usetikzlibrary{shadings}

\begin{document} \thispagestyle{empty}

\definecolor{pylight}{RGB}{247, 235, 205} \definecolor{py}{RGB}{243, 224, 181} \definecolor{pydark}{RGB}{221, 182, 110} \definecolor{pyhighlight}{RGB}{254, 235, 204}

\pgfdeclareverticalshading{parchment}{100bp}{% color(0bp)=(pydark); color(25bp)=(pydark); color(30bp)=(py); color(50bp)=(pylight); color(70bp)=(py); color(75bp)=(pydark); color(100bp)=(pydark)% } \pgfdeclareradialshading{rparchment}{\pgfpoint{0cm}{0cm}}{% color(0bp)=(pylight); color(13bp)=(pylight); color(20bp)=(py); color(40bp)=(pydark); color(60bp)=(pydark!50!black); color(100bp)=(black)% } \tikzset{ pencildraw/.style={% decorate, decoration={% random steps, segment length=1.1ex, amplitude=.5ex% } }, drop shadow/.style={ blur shadow={% shadow xshift=.5pt, shadow yshift=-.5pt, shadow blur steps=9, shadow blur extra rounding=1.5pt% }, }, parchment fill/.style={ pencildraw, fill=pyhighlight, postaction={shading=parchment, opacity=1}, postaction={shading=rparchment, opacity=.7} } }

\includegraphics[width=0.2\textwidth]{example-image-a}

\begin{tikzpicture} \shade node[preaction={fill=black,opacity=.5,transform canvas={xshift=1mm,yshift=-1mm}},parchment fill, drop shadow, text width=0.87\textwidth, inner sep=5mm, align=justify] {\fontsize{13}{16}\selectfont {\textbf{\textit{\lipsum[2]}}}} ; \end{tikzpicture} \end{document}

which produces:

enter image description here

What I would like to do is be able to insert the A image into the simulated parchment in the upper left hand corner, and wrap the text around it in a manner akin to wrapfigure

This seems like it should be a simple task, as I have been able to do successfully in the past, but for some reason, I have not been able to find where to insert \includegraphics[width=0.2\textwidth]{example-image-a} in the tikzpicture without incurring errors.

QUESTION: Can somebody help modify the code of the tikzpicture in order to insert the image in the upper left hand corner and then wrap the text around it?

Thank you.

DDS
  • 8,816
  • 4
  • 9
  • 36

1 Answers1

2

For a single paragraph, you can use \hangindent. Wrapfig can handle multiple paragraphs, which makes it more complicated (and fragile).

I wasn't sure what to use for the height of the first line (to align the tops). 13pt and \ht\strutbox were both too big. Also, I wasn't sure what [align=justify] does, but however you specify it, what you need is a \parbox.

\documentclass[border=1cm]{book}
\usepackage{lipsum}

\usepackage{wrapfig} \usepackage[justification=centering]{caption} \usepackage{graphicx}

\usepackage{tikz} \usetikzlibrary{positioning} \usetikzlibrary{decorations.pathmorphing} \usetikzlibrary{shadows.blur} \usetikzlibrary{shadings}

\begin{document} \thispagestyle{empty}

\definecolor{pylight}{RGB}{247, 235, 205} \definecolor{py}{RGB}{243, 224, 181} \definecolor{pydark}{RGB}{221, 182, 110} \definecolor{pyhighlight}{RGB}{254, 235, 204}

\pgfdeclareverticalshading{parchment}{100bp}{% color(0bp)=(pydark); color(25bp)=(pydark); color(30bp)=(py); color(50bp)=(pylight); color(70bp)=(py); color(75bp)=(pydark); color(100bp)=(pydark)% } \pgfdeclareradialshading{rparchment}{\pgfpoint{0cm}{0cm}}{% color(0bp)=(pylight); color(13bp)=(pylight); color(20bp)=(py); color(40bp)=(pydark); color(60bp)=(pydark!50!black); color(100bp)=(black)% } \tikzset{ pencildraw/.style={% decorate, decoration={% random steps, segment length=1.1ex, amplitude=.5ex% } }, drop shadow/.style={ blur shadow={% shadow xshift=.5pt, shadow yshift=-.5pt, shadow blur steps=9, shadow blur extra rounding=1.5pt% }, }, parchment fill/.style={ pencildraw, fill=pyhighlight, postaction={shading=parchment, opacity=1}, postaction={shading=rparchment, opacity=.7} } }

\begin{tikzpicture} \shade node[preaction={fill=black,opacity=.5,transform canvas={xshift=1mm,yshift=-1mm}},parchment fill, drop shadow, inner sep=5mm] {\parbox{0.87\textwidth}{\fontsize{13}{16}\selectfont \hangindent=\dimexpr 0.2\textwidth+\columnsep\relax \hangafter=-4 \noindent\llap{\raisebox{\dimexpr 0.6\baselineskip-\height}[0pt][0pt]% overlap indentation {\includegraphics[width=0.2\textwidth]{example-image-a}}\hspace{\columnsep}}% \textbf{\textit{\lipsum[2]}}}} ; \end{tikzpicture} \end{document}

demo

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • Thank you for this very nice answer. – DDS Aug 01 '21 at 01:17
  • IIRC, there is a package which uses \hangindent internally for this purpose, but I can't remember the name. – John Kormylo Aug 01 '21 at 14:34
  • You might be able to use lettrine as well, at least on the left side. – John Kormylo Aug 01 '21 at 15:51
  • Many thanks for your comments, as well as for your answer. – DDS Aug 01 '21 at 16:50
  • If I may, I would like to ask if it is possible (or rather, how may one) lower the text slightly, so that the first line of text is not flush with the top of the image? I have not been able to figure this out without incurring undesirable results. Thank you. – DDS Aug 03 '21 at 23:21
  • This is handled by \raisebox which works by moving the baseline for the image. The estimated height of the text was 0.6\baselineskip whereas \height refers to the contents (\includegraphics). – John Kormylo Aug 04 '21 at 14:10
  • Thank you kindly for this information. – DDS Aug 04 '21 at 16:34
  • 1
    Also, the first optional argument can be set to a positive value to move both the image and the text down (like using a \strut). The second optional argument needs to stay at 0pt. – John Kormylo Aug 04 '21 at 21:30
  • That is good to know. I've finally been able to accomplish what I want, albeit not in one ``fell swoop.'' I have, however, found that by adjusting a few of the parameters simultaneously, I can arrive at what I have been looking for. Thanks again for your help. – DDS Aug 05 '21 at 01:21