我读过了将图形包裹在 tikzpicture 中虽然标题相似,但意图似乎并不相同。
我想用一些文字包裹我的图形/图片,如下例所示:https://fr.overleaf.com/learn/latex/Inserting_Images带有网格和轮廓图形。
我还有另一个限制:我需要使用 latex 结构来添加我的文本和图形,该结构已经为另一个目的构建,由 tikzpicture 组成。
因此,如果您在那里看到很多包,它们出现在这里的原因并未出现在这个简短的示例中。除了我添加的 wrapfig 以便能够使用 wrapfigure。
这是我希望它起作用的示例:
\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}
我的问题是文本覆盖了图片,而不是包裹图片。
答案1
您可以在输入 tikz 之前在框中执行 wrapfig 来避免错误
\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}
答案2
这是一个解决方案(这是来自 tikz/pgf 贡献者向我建议的)。
\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}
(其中添加了负 vspace 以使图像与垂直轴上的文本正确对齐,并且可能有更简洁的方法来做到这一点)
这让我