控制 tikzpicture 周围的空白填充

控制 tikzpicture 周围的空白填充

我确信有人在这里问过这个问题,但我似乎找不到简单的解决方案。我想使用环境在我的文本侧面放置一个 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,使用 时,这不起作用。

我发现了多个问题(例如 12) 处理用 定义的对象周围的间距\newcommand。其他处理nodes 周围的间距,这与此无关(并且无论如何也无济于事)。

有没有简单的控制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}

相关内容