在盒子里绘制蛇装饰 tikz

在盒子里绘制蛇装饰 tikz

我正在尝试使用tikz库在盒子里画一些蛇形装饰,但无法实现我想要的效果。为什么实际标记和蛇之间不一致。我为此使用了以下代码。

\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{decorations.pathmorphing, shapes, arrows, shadows, positioning}

\newcommand{\tikzmark}[2]{%
 \tikz[overlay,remember picture] \node[text=black,
       inner sep=2pt] (#1) {#2};}

 \begin{document}

 \begin{figure}[ht]
 \centering
 \tikzstyle{box}=[draw, fill=pink!10, text centered, drop shadow]
 \begin{tikzpicture}[overlay, remember picture]
 \node (main) [box, minimum height=20em, minimum width=10em,align=left] 
 {
  \tikzmark{a}{}xxxxxxxx\tikzmark{b}{}\\
  \tikzmark{c}{}xxxxxxxx\tikzmark{d}{}\\
 };

 \draw [-,decorate,decoration=snake] (a.center) -- (b.center);
 \draw [-,decorate,decoration=snake] (c.center) -- (d.center);
 \end{tikzpicture}
 \end{figure}
 \end{document}

答案1

也许你必须调整基线

\newcommand{\tikzmark}[2]{%
 \tikz[baseline=-0.5ex,overlay,remember picture] \node[text=black,
       inner sep=2pt] (#1) {#2};}

要得到

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{decorations.pathmorphing, shapes, arrows, shadows, positioning}

\newcommand{\tikzmark}[2]{%
 \tikz[baseline=-0.5ex,overlay,remember picture] \node[text=black,
       inner sep=2pt] (#1) {#2};}

 \begin{document}

 \begin{figure}[ht]
 \centering
 \tikzstyle{box}=[draw, fill=pink!10, text centered, drop shadow]
 \begin{tikzpicture}[overlay, remember picture]
 \node (main) [box, minimum height=20em, minimum width=10em,align=left]
 {
  \tikzmark{a}{}xxxxxxxx\tikzmark{b}{}\\
  \tikzmark{c}{}xxxxxxxx\tikzmark{d}{}\\
 };

 \draw [-,decorate,decoration=snake] (a.center) -- (b.center);
 \draw [-,decorate,decoration=snake] (c.center) -- (d.center);
 \end{tikzpicture}
 \end{figure}
 \end{document}

相关内容