绘制不均匀气泡

绘制不均匀气泡

我需要绘制一个非均匀的文本气泡并将文本放入其中。

JW4Ot.jp

答案1

这是一个气泡:

\documentclass{standalone}
\usepackage{tikz
\usetikzlibrary{calc,fit,intersections}
\begin{document}
\begin{tikzpicture}
    \draw  plot [smooth,tension=1.3] coordinates {(1.cm+rand*.1cm,.2cm+rand*.1cm) (0cm+rand*0cm,-1cm+rand*.1cm) (-1cm+rand*0.1cm,0cm+rand*0.1cm) (0cm+rand*0.1cm,1cm+rand*0.1cm) (1.cm+rand*.1cm,-.2cm+rand*.1cm)};
\end{tikzpicture}
\end{document}

气泡

您可以随时对坐标进行硬编码,而不是使用我使用的随机坐标。

在其中添加文字非常简单

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,fit,intersections}
\begin{document}
\begin{tikzpicture}
    \draw  plot [smooth,tension=1.3] coordinates {(1.cm+rand*.1cm,.2cm+rand*.1cm) (0cm+rand*0cm,-1cm+rand*.1cm) (-1cm+rand*0.1cm,0cm+rand*0.1cm) (0cm+rand*0.1cm,1cm+rand*0.1cm) (1.cm+rand*.1cm,-.2cm+rand*.1cm)};
    \node[text width=1.4cm] at(0,0) {\small{This is some text in a bubble}};
\end{tikzpicture}
\end{document}

带有文本的气泡

这里使用起来更好一些:

\documentclass{standalone}
\usepackage{shapepar}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{calc,fit,intersections}
\newcommand\bubblenodetext[3]{\node [draw=none, shape=circle, text width=0cm, inner sep=5mm] at (#1,#2) (bubblenode){\shapepar{\circleshape} #3\par};
    \def\startendoffset{3mm}
    \draw  plot [smooth,tension=1.3] coordinates {($(bubblenode.east)+(\startendoffset,\startendoffset)$) (bubblenode.south) (bubblenode.west) (bubblenode.north) ($(bubblenode.east)+(\startendoffset,-\startendoffset)$)};
}
%change draw=none to draw=red to see the line bounding the text. 
\newcommand\randombubblenodetext[3]{\node [draw=none, shape=circle, text width=0cm, inner sep=2mm] at (#1,#2) (bubblenode){\shapepar{\circleshape} #3\par};
    \def\startendoffset{3mm}
    \def\randomfactor{3mm}
    \draw  plot [smooth,tension=1.3] coordinates {($(bubblenode.east)+(\startendoffset+rnd*\randomfactor,\startendoffset+rand*\randomfactor)$)
        ($(bubblenode.south)+(rand*\randomfactor,-rnd*\randomfactor)$) 
        ($(bubblenode.west)+(-rnd*\randomfactor,rand*\randomfactor)$) 
        ($(bubblenode.north)+(rand*\randomfactor,rnd*\randomfactor)$) 
        ($(bubblenode.east)+(\startendoffset+rnd*\randomfactor,-\startendoffset+rand*\randomfactor)$)};
}

\begin{document}
\begin{tikzpicture}
    \bubblenodetext {0}{0}{Now we automate the bubble.  We can still fill it with text.}
    \randombubblenodetext{5}{0}{This is a slightly random bubble.  We can still fill it with text.}
\end{tikzpicture}
\end{document}

自动魔法气泡

在右边的例子中,我还减少了内部分隔符——你需要在这里取得平衡,因为文本实际上并不响应我绘制的形状,而是响应一个圆圈(参见第 10 行的注释)。代码是无耻地从零伯爵的回答在 TikZ 中将文本调整到形状

需要调整才能获得您想要的外观:inner sep tension,,(您可能希望将其设置为 0)\startendoffset\randomfactor

相关内容