在盒子裡畫蛇裝飾 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}

相關內容