6

Consider the following TikZ drawing:

enter image description here

Why do the lines not go "all the way"? And why does that line appear below what is supposed to look like a water tank?

\documentclass{memoir}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}
\def\balloonheight{1.5}
\def\ballooonwidth{1}
\def\vwidth{0.3}
\def\vheight{3}
\def\vpos{-3}
\centering
\begin{tikzpicture}
    \tikzstyle{balloon}=[ball color=red];
    \shade[balloon] ellipse (1 and 1.5);

    \coordinate (bottom) at (0,-1.5);

    \coordinate (vtop) at (0,\vpos);
    \coordinate (vbottom) at (0,{\vpos - \vheight} );
    \coordinate (vtopright) at (\vwidth, -3 );
    \coordinate (vtopleft) at (-\vwidth, -3 );

    \draw[rounded corners=8pt, thick,black] (vtopright) |- (vbottom) -| (vtopleft);

    \draw[fill=blue!50!white] decorate [blue,decoration={snake}] {(vtopleft)++(0,-0.5) -- ++(2*\vwidth, 0 )} [rounded corners=8pt] |- (vbottom) -| (vtopleft)++(0,-0.5);

    \draw[orange] (bottom) -- coordinate[midway] (ropemid) (vtop) -- ++(0,-1);

    \coordinate (current) at (4,-1.5);

    \path (current) -- ++(0,0.3) node (current+) {};
    \path (current) -- ++(0,-0.3) node (current-) {};

    \draw[thick] (current+) -- +(-0.5,0) -- ++(0.5,0);
    \draw[thick] (current-) -- +(-0.2,0) -- ++(0.2,0);

    \path (vbottom) -- ++(0,-0.5) node (belowvbottom) {};
    \path (vtopleft) -- ++(0,-1.5) node (+entrance) {};
    \path (vtopright) -- ++(0,-1.5) node (-entrance) {};

    \draw[rounded corners=8pt,thick] (current+) |- ++(1,1) |- (belowvbottom) -- ++(-1,0) |- (+entrance);
    \draw[rounded corners=8pt, thick] (current-) |- (-entrance);

    \draw[thick,rounded corners=8pt] (ropemid) -- ++(2,0) 
    node[fill=white, draw, rectangle,rounded corners,align=center] (pico) {PicoScope} -| (current-);

\end{tikzpicture}
\end{document}
5
  • For 2): your rounded corners value is too big. – Gonzalo Medina Sep 19 '13 at 16:46
  • For 1) Never use node for anything but nodes. Use coordinates instead. – zeroth Sep 19 '13 at 16:48
  • I'm sure this has been asked before. Your nodes, e.g. current+, has non zero inner sep, use node[coordinate] (current+) {} instead. – Torbjørn T. Sep 19 '13 at 16:49
  • or simply coordinate (current+); – zeroth Sep 19 '13 at 16:49
  • Related/possible duplicate for the node vs. coordinate topic: TikZ - curly braces end at the same node, but there is a gap (and probably many more) – Qrrbrbirlbel Sep 19 '13 at 17:07
5

For the closing of the lines, note that drawing to a node (node) draws to the edge of that, to draw to the middle use (node.center). Alternatively, as suggested in the comments define a coordinate instead of a node.

For the line at the bottom of the water tank, as mentioned this is an artefact from large values of rounnded corners creating short edges. You can draw each half separately to avoid this and do the filling separately:

Sample output

\documentclass{memoir}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}
\def\balloonheight{1.5}
\def\ballooonwidth{1}
\def\vwidth{0.3}
\def\vheight{3}
\def\vpos{-3}
\centering
\begin{tikzpicture}
  \tikzstyle{balloon}=[ball color=red];
  \shade[balloon] ellipse (1 and 1.5);

  \coordinate (bottom) at (0,-1.5);

  \coordinate (vtop) at (0,\vpos);
  \coordinate (vbottom) at (0,{\vpos - \vheight} );
  \coordinate (vtopright) at (\vwidth, -3 );
  \coordinate (vtopleft) at (-\vwidth, -3 );

  \fill[blue!50!white] decorate [decoration={snake}]
  {(vtopleft)++(0,-0.5) -- ++(2*\vwidth, 0 )} [rounded corners=8pt]
  |- (vbottom) -| (vtopleft)++(0.1,-0.5);

  \draw decorate [decoration={snake}] {(vtopleft)++(0,-0.5) --
  ++(2*\vwidth, 0 )}; 
  \draw[rounded corners=8pt,thick,black] (vtopright) |- (vbottom);
  \draw[rounded corners=8pt,thick,black] (vbottom) -| (vtopleft); 

  \draw[orange] (bottom) -- coordinate[midway] (ropemid) (vtop) -- ++(0,-1);

  \coordinate (current) at (4,-1.5);

  \path (current) -- ++(0,0.3) node (current+) {};
  \path (current) -- ++(0,-0.3) node (current-) {};

  \draw[thick] (current+) -- +(-0.5,0) -- ++(0.5,0);
  \draw[thick] (current-) -- +(-0.2,0) -- ++(0.2,0);

  \path (vbottom) -- ++(0,-0.5) node (belowvbottom) {};
  \path (vtopleft) -- ++(0,-1.5) node (+entrance) {};
  \path (vtopright) -- ++(0,-1.5) node (-entrance) {};

  \draw[rounded corners=8pt,thick] (current+.center) |- ++(1,1) |-
  (belowvbottom.center) -- ++(-1,0) |- (+entrance); 
  \draw[rounded corners=8pt, thick] (current-.center) |- (-entrance);

  \draw[thick,rounded corners=8pt] (ropemid) -- ++(2,0) 
  node[fill=white, draw, rectangle,rounded corners,align=center]
  (pico) {PicoScope} -| (current-); 
\end{tikzpicture}

\end{document}

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.