2

Is this a bug or am I doing something wrong? When using pure TIKZ everything works as expected:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
        \draw (0,0) -- ++(2,0) -- +(0,-1) +(0,0) -- +(2,0);
    \end{tikzpicture}
\end{document}

TIKZ with relative coordinates working correctly

But when doing the same with CircuiTIKZ, the y coordinate seems to be updated:

\documentclass{standalone}
\usepackage{circuitikz}
\begin{document}
    \begin{tikzpicture}
        \draw (0,0) to[short] ++(2,0) to[C] +(0,-1) +(0,0) to[short] +(2,0);
    \end{tikzpicture}
\end{document}

CircuiTIKZ fails with relative coordinates

1
  • My first example also works as I expect when substituting -- with to. What does adding attributes to to changes? Also \draw (0,0) to +(4,0) ++(2,0) to[C] +(0,-1); seems to produce wrong results, as +(0,-1) ends up at (0,-1)
    – Yasumi
    Aug 28, 2014 at 9:36

1 Answer 1

3

The problem is very simple.

After the first part of the path, (0,0) -- ++(2,0) (which is common), in the first case you use -- +(0,-1) in the second you add a capacity. The capacity symbol shifts the current position of the pen, something that your syntax -- +(0,-1) does not. Actually, you will perceive the same behaviour if you were using:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{circuitikz}
\usetikzlibrary{shapes.misc}
\begin{document}
    \begin{tikzpicture}
        \draw (0,0) -- ++(2,0) -- ++(0,-1) +(0,0) -- +(2,0);
    \end{tikzpicture}

    \begin{tikzpicture}
        \draw (0,0) to[short] ++(2,0) to[C] +(0,-1) +(0,0) to[short] +(2,0);
    \end{tikzpicture}
\end{document}

because -- ++(0,-1) shifts the position as well:

enter image description here

Now, having this in mind, you may want to do the following:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{circuitikz}
\usetikzlibrary{shapes.misc}
\begin{document}
    \begin{tikzpicture}
        \draw (0,0) -- ++(2,0) -- +(0,-1) +(0,0) -- +(2,0);
    \end{tikzpicture}

    \begin{tikzpicture}
        \draw (0,0) to[short] ++(2,0) to[C] +(0,-1) +(0,1) to[short] +(2,1);
    \end{tikzpicture}
\end{document}

so you will get:

enter image description here

4
  • But \draw (0,0) to +(4,0) ++(2,0) to +(0,-1); the first to seems not to update the pen to (4,0). Because the second line ends up at (0,-1). I haven't wrapped my head arround the arcane doings of to. Thanks for your nicely illustrated answer!
    – Yasumi
    Aug 28, 2014 at 10:06
  • Correct answer: \draw (0,0) to ++(4,0) --(2,0) to +(0,-1);. Try to learn why it is correct: the pgfmanual has a very detailed explanation on all combinations of -- +, -- ++ etc.. Aug 28, 2014 at 10:10
  • But --(2,0)(draw line to point (2,0)) introduces an absolute coordinate and thus explicitly move to the point (2,0). This would break, if I'd changed the first moveto (0,0) to something different. So you probably meant ++(-2,0)?
    – Yasumi
    Aug 28, 2014 at 10:23
  • Indeed, you're right. The point I was trying to highlight in my previous message is the difference between + and ++ operators. Aug 28, 2014 at 10:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .