1

I have read wrapfigure inside a tikzpicture and although the title is similar the intent does not seem to be the same.

I want to have some text wrapping my figure/picture as in the example here : https://fr.overleaf.com/learn/latex/Inserting_Images with the mesh and the contour figures.

I have another constraint: I need to use the latex structure that I will add my text and figure into, which is already built for another purpose, consisting of a tikzpicture.
So if you see lots of packages there, they are here for a reason that doesn't appear in this short example. Except for wrapfig that I added to be able to use wrapfigure.

Here is the example I would like it to work:

\documentclass{article}
\usepackage{tcolorbox, graphicx, tikz, xfp, pgf, wrapfig}

\usetikzlibrary{decorations.pathmorphing}

\usepackage[paperwidth=1000pt, paperheight=1000pt, margin=100pt]{geometry} \begin{document} \begin{tcolorbox}[boxsep=0pt, left=0pt, right=0pt, top=0pt, bottom=0pt, sharpish corners, opacityframe=0, opacityback=0, boxrule=0pt] \begin{tikzpicture}[x=1pt, y=1pt]

        \draw[xshift=100, yshift=100] node[draw, dotted, anchor=south west, text width=500, align=justify, inner sep=\padding, fill=white] {
            \begin{wrapfigure}{l}{0.25\textwidth}
                \centering
                \includegraphics[width=200pt]{example-image-a}
            \end{wrapfigure}

            Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
        };

    \end{tikzpicture}
\end{tcolorbox}

\end{document}

My issue is that the text is going over the picture and not wrapping it.

Text over the picture !

  • Why the need for a tikz picture? Just having the wrapfigure should do, unless I’m misunderstanding what you want. – Archange Oct 07 '21 at 06:38
  • @Archange I need all the rest for other things I have removed in the example above. Aside from this, I am placing nodes at precise locations and I need the tikzpicture. – Filippo Guenzi Oct 07 '21 at 06:39
  • Do your nodes affect your text or only your figure? In the latter case, just put the tikzpicture inside the wrapfigure. In case it affects your text, then you probably need to have the tikzpicture separated from both the wrapfigure and text while using an overlay. – Archange Oct 07 '21 at 06:44
  • I get a first error of `! Illegal unit of measure (pt inserted). \relax l.1005 \ProcessOptionsKV[p]{Gm}` do you not get that? – David Carlisle Oct 07 '21 at 07:00
  • all three options here should be lengths not integers \usepackage[paperwidth=1000, paperheight=1000, margin=100]{geometry} – David Carlisle Oct 07 '21 at 07:01
  • @DavidCarlisle Yes I get that too, but was ignoring it, not knowing how to treat it. Because in my latex they are function results from Lua. And I don't know how to add the unit. Thank you – Filippo Guenzi Oct 07 '21 at 07:05
  • I modified my example because what I really need to do is to place my figure and text inside a node. And luckily it stopped complaining about the previous error. The compilation goes better now but the goal is not achieved. The text goes over the image and does not wrap around it. – Filippo Guenzi Oct 07 '21 at 07:11
  • Never ignore any error, TeX makes no attempt to make sensible PDF if you scroll past an error, it is just a possible debugging aid, not usable output. – David Carlisle Oct 07 '21 at 07:11
  • I might add that wrapfig is fragile and is not the only way to wrap text around an image. OTOH, it is easy to use and can handle multiple paragraphs. – John Kormylo Oct 07 '21 at 13:30
  • @Archange Each node in my tikzpicture should have a picture and text wrapping around it. For example you could imagine a genealogical tree where instead of simply having names I have boxes (the nodes) with the person picture and text describing the person. (The tikzpicture is necessary to place the boxes at the right place.) – Filippo Guenzi Oct 11 '21 at 14:35

2 Answers2

1

enter image description here

You can avoid the error by doing the wrapfig in a box before entering tikz

\documentclass{article}
\usepackage{tcolorbox, graphicx, tikz, xfp, pgf, wrapfig}

\usetikzlibrary{decorations.pathmorphing}

\newsavebox\zzbox

\usepackage[paperwidth=1000pt, paperheight=1000pt, margin=100pt]{geometry} \begin{document} \begin{tcolorbox}[boxsep=0pt, left=0pt, right=0pt, top=0pt, bottom=0pt, sharpish corners, opacityframe=0, opacityback=0, boxrule=0pt]

    \sbox\zzbox{\parbox{\textwidth}{%
       \begin{wrapfigure}{l}{0.25\textwidth}

            \centering
           \includegraphics[width=200pt]{example-image-a}
        \end{wrapfigure}

        Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?

}} \begin{tikzpicture}[x=1pt, y=1pt] \usebox\zzbox \end{tikzpicture} \end{tcolorbox}

\end{document}

David Carlisle
  • 757,742
  • the issue is that I node lots of nodes inside my tikzpicture with node text wrapping around my node image. They really need to be inside the tikz picture. Has really Tikz nothing to respond to that need? I'll check the tikz documentation further. – Filippo Guenzi Oct 07 '21 at 07:18
  • @FilippoGuenzi sorry I had trouble guessing the desired output from even this case I can not guess your larger example. tikz is mostly about positioning things by cordinates and wrapfig is mostly about text that automatically flows and line wraps these are rather contradictory aims even without the fact that tikz and wrapfig are both complicated packages with tricky interactions. This shows how to put a wrapfig in a node. You can not put a wrapfig in two nodes at the same time so I do not understand your "lots of nodes" comment. – David Carlisle Oct 07 '21 at 07:21
  • If I am not mistaken, the entire contents of the tcolorbox is first stored in a savebox, definitely for breakable tcolorboxes. – John Kormylo Oct 07 '21 at 13:56
  • @DavidCarlisle I have a tikzpicture with lots of nodes inside it. Each one is a box where so far I put text in it. Each box represents something different. In addition to the text I would also like to put a picture in each box and the text to wrap around that image. For example I could wish to make a genealogical tree where instead of simply having names I have boxes with the person picture and text describing it. (The tikzpicture is necessary to place the boxes at the right place.) In my case I have a lot of text and wrapping around the picture is preferable to having two columns. – Filippo Guenzi Oct 08 '21 at 13:40
  • so why does this answer not apply to that use @FilippoGuenzi ? – David Carlisle Oct 08 '21 at 13:54
  • @DavidCarlisle oh I didn't understand it in the first place. You define the boxes outside the tikzpicture to reference them later from inside. Nice I will try that. Thank you. – Filippo Guenzi Oct 08 '21 at 17:54
  • @FilippoGuenzi as you use each box immediately you should only need to allocate one box but just do the node content in a savebox and use it in the node to avoid nesting issues – David Carlisle Oct 08 '21 at 17:55
  • @DavidCarlisle sorry but I don't understand. All that is new to me. Can you give in your response an example with two nodes 200px large, each with its own content, as if they were placed on a diagonal, just to test that you can place them where you want? – Filippo Guenzi Oct 08 '21 at 19:07
  • @DavidCarlisle I personally tried to put \usebox\zzbox in a \draw node{ } but the text goes out of the node and I have errors. – Filippo Guenzi Oct 08 '21 at 19:24
1

Here is a solution (that comes from what a tikz/pgf contributor suggested to me).

\documentclass{article}
\usepackage{tcolorbox, graphicx, tikz, xfp, pgf, wrapfig}

\usetikzlibrary{decorations.pathmorphing}

\usepackage[paperwidth=1000pt, paperheight=1000pt, margin=100pt]{geometry} \begin{document} \begin{tcolorbox}[boxsep=0pt, left=0pt, right=0pt, top=0pt, bottom=0pt, sharpish corners, opacityframe=0, opacityback=0, boxrule=0pt] \begin{tikzpicture}[x=1pt, y=1pt]

        \node[xshift=100, yshift=100, draw,dotted, draw, dotted, anchor=south west, text width=500, align=justify, inner sep=10pt, fill=white] {%
            \begin{minipage}{500pt}
                \begin{wrapfigure}{l}{200pt}
                    \vspace*{-13pt}
                    \includegraphics[width=200pt]{example-image-a}
                \end{wrapfigure}

                \input{knuth.tex}
                \input{knuth.tex}
            \end{minipage}%
        };

        \node[xshift=400, yshift=400, draw,dotted, draw, dotted, anchor=south west, text width=500, align=justify, inner sep=10pt, fill=white] {%
            \begin{minipage}{500pt}
                \begin{wrapfigure}{l}{200pt}
                    \vspace*{-13pt}
                    \includegraphics[width=200pt]{example-image-b}
                \end{wrapfigure}

                \input{knuth.tex}
                \input{knuth.tex}
            \end{minipage}%
        };

    \end{tikzpicture}
\end{tcolorbox}

\end{document}

(where the negative vspace was added to align properly the image with the text on the vertical axis and there might be a cleaner way to do it)

which gives me

nodes with text wrapping around their picture