2

I am trying to draw some snake decorations in a box using tikz library but couldn't achieve what I want. Why there is mis-alignment between the actual markings and the snakes. I am using the following code for this.

\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
    What exactly do you want to achieve? If we knew your goal, it'd be easier to know what to do. – Alenanno Apr 26 '15 at 10:44
  • @Alenanno I simply want to draw snake decorations in place of text 'xxxxxxxxxxx'. – Shahzad Apr 26 '15 at 10:51
1

May be you have to adjust the baseline in

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

to get

enter image description here

\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}
  • Even after copy-pasting the above code, I am not getting the same output as posted in your image. Between, the output in the image is what I exactly want. – Shahzad Apr 26 '15 at 10:58
  • @Shahzad You have to compile 2-3 times. – user11232 Apr 26 '15 at 11:00
  • Yes. I did compiled for several times but its not producing the desired output. – Shahzad Apr 26 '15 at 11:03
  • @Shahzad Are you using the latest tikz? i.e. version 3? – user11232 Apr 26 '15 at 11:11
  • Yes. Its version 3.0.0. – Shahzad Apr 26 '15 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.