# tikz, tikz circuits, relative coordinates

I am trying to draw a dimensioned line, <---- 2 cm ---- > in the x, and y directions on a circuit diagram. Using absolute coordinates, there is no problem. However, the display is faulty using relative coordinates, which cuts off part of the circuit. I haven't been able to correct this problem satisfactorily. I welcome any suggestions. A MWE example is included for each case.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC,positioning}
\begin{document}
% circuit with absolute coordinates
\begin{tikzpicture}[circuit ee IEC,
set resistor graphic = var resistor IEC graphic,>=stealth']
\draw (0,0) -- (0,2)
(0,2) to[resistor={info'={R}}](3,2)
(3,2) -- (3,0)
(3,0) to[battery={info'={$V$}}](0,0);
\draw [<->] (-0.6,0) -- (-0.6,2) node[midway,fill=white]{\small{y cm}};
\draw [<->] (-0.2,2.6) -- (3,2.6) node[midway,fill=white]{\small{x cm}};
\end{tikzpicture}
% circuit with relative coordinates
\begin{tikzpicture}[circuit ee IEC, >=stealth',%
set resistor graphic = var resistor IEC graphic]
\node (A)                        {};
\node (B)  [above = 2cm of A]    {};
\node (C)  [right = 3cm of B]    {};
\node (D)  [right = 3cm of A]    {};
\draw (A.base) -- (B.base)
(B.base) to[resistor={info'={R}}](C.base)
(C.base) -- (D.base)
(D.base) to[battery={info'={$V$}}](A.base);
\draw [<->] (A.west) -- (B.west) node[midway,fill=white]{\small{y cm}}; %!
\draw [<->] (B.north) -- (C.north) node[midway,fill=white]{\small{x cm}}; %!
\end{tikzpicture}
\end{document}

-

## 1 Answer

You need to shift the dimension lines so they don't coincide with the circuit lines. Since you're using nodes to position your elements, you'll need to add the shift length to each coordinate specification, so (A) -- (B) would become ([yshift=1cm] A) -- ([yshift=1cm] B) if you wanted to shift the line from A to B up one centimetre (see Shift line connecting anchors for more information).

Instead of using \nodes for defining the points, I would suggest using \coordinates. They don't need an empty node text, and they don't take up any space, which makes alignment easier. They don't have any anchors (apart from center), so you don't need to decide which anchor to use.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC,positioning}
\begin{document}
% circuit with relative coordinates
\begin{tikzpicture}[circuit ee IEC, >=stealth',%
set resistor graphic = var resistor IEC graphic]
\coordinate (A)                     ;
\coordinate [above = 2cm of A] (B)  ;
\coordinate [right = 3cm of B] (C)  ;
\coordinate [right = 3cm of A] (D)  ;
\draw (A) -- (B)
(B) to[resistor={info'={R}}](C)
(C) -- (D)
(D) to [battery={info'={$V$}}](A);
\draw [<->] ([xshift=-0.5cm]A) -- ([xshift=-0.5cm]B) node[midway,fill=white]{\small{y cm}}; %!
\draw [<->] ([yshift=0.5cm]B) -- ([yshift=0.5cm]C) node[midway,fill=white]{\small{x cm}}; %!
\end{tikzpicture}
\end{document}

-
very good suggestion. Will have to review tikz manual section on Specifing Coordinates. I thought \coordinate s could only be used like \coordinate (a) at (2,3). Better alignment is an additional perk. – zun Apr 16 '12 at 0:29