# TikZ circuits: Resistor is rotated by 90 degrees

I have a problem with TikZ circuit library. The following code produces a circuit, but the resistor is rotated by 90 degrees:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC}

\begin{document}
\begin{tikzpicture} [circuit ee IEC]
\node (pow) [battery]   at (0,0)  {};
\node (res) [resistor]  at (-1,1) {};
\draw (pow) -| (res) -- (-1,2);
\end{tikzpicture}
\end{document}


The resistors long side is orthorgonal to the line. How do I change this so that the long side is along the wire?

• Change the line with the resistor to \node (res) [rotate=90,resistor] at (-1,1) {};. – Count Zero Feb 21 '13 at 17:06
• Why do I have to do this? All the examples in the manual don't to it, there the resistor is aligned correctly. – Foo Bar Feb 21 '13 at 17:07
• You place the node with the resistor independently of the lines. At that time TikZ doesn't know it would need to rotate it later and doesn't modify it either. In the examples of the manual the nodes are actual circuit nodes and the resistors (and whatnot) are decorations of the connecting lines, so rotation will be automatic. – Count Zero Feb 21 '13 at 17:13
• As @CountZero explained, you need a to path: \draw (-1,2) to[resistor] (-1,0) to[battery={at end}] (0,0);. – Qrrbrbirlbel Feb 21 '13 at 17:20

As you place the nodes before you actually draw the lines connecting these nodes the nodes can have absolutely no knowledge about their rotation. This is only possible with to paths that internally use the markings library which makes it possible that nodes are placed on that line. (See /pgf/decoration/mark connection node at the end of section 30.5 “Arbitrary Markings”, p. 331.)

You can easily construct your path with the following code, note that I used at end to

• place the battery at (0,0)
• without having a part of the line behind it (as in your example).

It is not possible to use |- or -| in the same kind of manner without a little effort (see second TikZ picture).

## Code

\documentclass[tikz]{standalone}
\usetikzlibrary{circuits.ee.IEC}
\begin{document}
\begin{tikzpicture}[circuit ee IEC]
\begin{scope}[red]
\node (pow) [battery]   at (0,0)  {};
\node (res) [resistor]  at (-1,1) {};
\draw (pow) -| (res) -- (-1,2);
\end{scope}
\draw (-1,2) to[resistor] (-1,0) to[battery={at end}] (0,0);
\end{tikzpicture}

\begin{tikzpicture}[circuit ee IEC]
\begin{scope}[red]
\node (pow) [battery]   at (0,0)  {};
\node (res) [resistor]  at (-1,1) {};
\draw (pow) -| (res) -- (-1,2);
\end{scope}
\draw (-1,2) to[resistor={at end}] (-1,1) to (-1,1 |- 0,0) to [battery={at end}]  (0,0);
\end{tikzpicture}
\end{document}


## Output 