![控制 tikzpicture 周围的空白填充](https://linux22.com/image/319687/%E6%8E%A7%E5%88%B6%20tikzpicture%20%E5%91%A8%E5%9B%B4%E7%9A%84%E7%A9%BA%E7%99%BD%E5%A1%AB%E5%85%85.png)
我确信有人在这里问过这个问题,但我似乎找不到简单的解决方案。我想使用包装图环境在我的文本侧面放置一个 tikzfigure,如下所示:
\documentclass{article}
\usepackage{lipsum}
\usepackage{wrapfig}
\usepackage{tikz}
\begin{document}
\lipsum[1]
\begin{wrapfigure}{r}{0pt}%
\vspace{-1cm}% Doesn't do anything
\begin{tikzpicture}%
[every node/.style={inner sep=0,outer sep=0}]%There are no nodes, so doesn't do anything
\foreach \z in {0,6,...,36}%
\shade[ball color=blue] (0,\z pt) circle (3pt);%
\end{tikzpicture}
\end{wrapfigure}
\lipsum[2-3]
\end{document}
这使
问题是文本上方和下方的间距太大(恕我直言)。使用时,inludegraphics
我可以添加vspace
以将其推到位。但是tikzpicture
,使用 时,这不起作用。
我发现了多个问题(例如 1,2) 处理用 定义的对象周围的间距\newcommand
。其他处理node
s 周围的间距,这与此无关(并且无论如何也无济于事)。
有没有简单的控制tikzpicture
? 周围填充的方法(欢迎关闭重复内容)
答案1
不要使用 的宽度0pt
,而要使用 这样的合理值5/6pt
。并为图片跨越的行数提供一个合适的值([4]
此处)
\documentclass{article}
\usepackage{lipsum}
\usepackage{wrapfig}
\usepackage{tikz}
\begin{document}
\lipsum[1]
\begin{wrapfigure}[4]{r}{7pt}%
\vspace*{-4mm}% This works now
\begin{tikzpicture}%
[every node/.style={inner sep=0,outer sep=0}]%There are no nodes, so doesn't do anything
\foreach \z in {0,6,...,36}%
\shade[ball color=blue] (0,\z pt) circle (3pt);%
\end{tikzpicture}%
\end{wrapfigure}
\lipsum[2]
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi.
\begin{wrapfigure}[4]{r}{7pt}%
\vspace*{-4mm}% This works now
\begin{tikzpicture}%
[every node/.style={inner sep=0,outer sep=0}]%There are no nodes, so doesn't do anything
\foreach \z in {0,6,...,36}%
\shade[ball color=blue] (0,\z pt) circle (3pt);%
\end{tikzpicture}%
\end{wrapfigure}
Morbi
auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies
et, tellus. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
magna, vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit mollis.
Suspendisse ut massa. Cras nec ante. Pellentesque a nulla. Cum sociis
natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Aliquam tincidunt urna. Nulla ullamcorper vestibulum turpis. Pellentesque
cursus luctus mauris.
\end{document}
您可以将图片放在一个框中并使用该框的宽度,如下所示:
\documentclass{article}
\usepackage{lipsum}
\usepackage{wrapfig}
\usepackage{tikz}
\newsavebox{\mypicture}
\sbox{\mypicture}{%
\begin{tikzpicture}%
[every node/.style={inner sep=0,outer sep=0}]%There are no nodes, so doesn't do anything
\foreach \z in {0,6,...,36}%
\shade[ball color=blue] (0,\z pt) circle (3pt);%
\end{tikzpicture}%
}
\begin{document}
\lipsum[1]
\begin{wrapfigure}[4]{r}{\wd\mypicture}%
\vspace*{-4mm}% This works now
\usebox{\mypicture}
\end{wrapfigure}
\lipsum[2]
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi.
\begin{wrapfigure}[4]{r}{\wd\mypicture}%
\vspace*{-4mm}% This works now
\usebox{\mypicture}
\end{wrapfigure}
Morbi
auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies
et, tellus. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
magna, vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit mollis.
Suspendisse ut massa. Cras nec ante. Pellentesque a nulla. Cum sociis
natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Aliquam tincidunt urna. Nulla ullamcorper vestibulum turpis. Pellentesque
cursus luctus mauris.
\end{document}