# How to make the code of a circuitikz diagram more flexible?

I am a beginner in LaTeX, and TikZ, trying to use them for industrial documents. The sample code below (largely made with previous help) shows a circuit made with circuitikz. However I have now the need to make some variants of this circuit, and wonder if the code could be made more flexible using another approach, such as \foreach or other solution, minimizing the number of hard coded coordinates, and therefore simplifying the adjustments of some dimensions. Any help appreciated.

\documentclass{article}
\usepackage{tikz}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}[scale =1]
% Side vertical lines
\draw [ultra thick, gray!50] (0,-5)-- (0,2);
\draw [ultra thick, gray!50] (5,-5) -- (5,2);
% Black resistors
\draw (0,1) to[R=$R_1$,*-*] (2,1);
\draw (3,0) to [R=$R_1$,*-*] (5,0);
\draw (0,-1) to[R=$R_1$,*-*] (2,-1);
\draw (3,-2) to[R=$R_1$,*-*] (5,-2);
\draw (0,-3) to[R=$R_1$,*-*] (2,-3);
\draw (3,-4) to[R=$R_1$,*-*] (5,-4);
% Blue resistors
\begin{scope}[color=blue]
\draw (2,1) to [R=$R_2$] (3,0);
\draw (2,-1) to[R=$R_2$] (3,0);
\draw (2,-1) to [R=$R_2$] (3,-2);
\draw (2,-3) to[R=$R_2$] (3,-2);
\draw (2,-3) to[R=$R_2$] (3,-4);
\end{scope}

% the side messages
\node [anchor=south,rotate=90, gray] at (current bounding box.west) {\Large\textbf {Pin side}};
\node [anchor=north,rotate=90,gray] at (current bounding box.east) {\Large\textbf{Socket side}};

\end{circuitikz}
\end{document}

-
Can you include a few details about the type of changes required in the variants? – percusse May 27 '12 at 9:30
I personally don't like circuitikz so much, instead I use the library provided with tikz. (You can load it by adding \usetikzlibrary{circuits.ee.IEC} in the preamble of your document. circuits.ee.IEC can be replaced by circuits.logic.US or circuits.logic.IEC, depending on your needs.) There for instance you have more flexibility in customizing your symbols, if that's what you're after. But as percusse said, we need to know what you have in mind. – Count Zero May 28 '12 at 19:23

It's hard to say what exactly you want to do. I made a few changes on the code and it looks now like this:

\documentclass{article}
\usepackage{tikz}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}[scale =1]
% Side vertical lines with labels
\draw [ultra thick, gray!50] (0,-5) -- (0,2) node [midway, above, rotate=90, gray]       {\Large\textbf{Pin side}};
\draw [ultra thick, gray!50] (5,-5) -- (5,2) node [midway, below, rotate=90, gray] {\Large\textbf{Socket side}};

% Black resistors
\draw (0,1) to[R=$R_1$,*-*] (2,1);
\draw (3,0) to [R=$R_1$,*-*] (5,0);
\draw (0,-1) to[R=$R_1$,*-*] (2,-1);
\draw (3,-2) to[R=$R_1$,*-*] (5,-2);
\draw (0,-3) to[R=$R_1$,*-*] (2,-3);
\draw (3,-4) to[R=$R_1$,*-*] (5,-4);
% Blue resistors
\begin{scope}[color=blue]
\draw (2,1) to [R=$R_2$] (3,0)
to [R=$R_2$] (2,-1)
to [R=$R_2$] (3,-2)
to [R=$R_2$] (2,-3)
to [R=$R_2$] (3,-4);
\end{scope}
\end{circuitikz}
\end{document}


As you can see, i have moved the labes for the two vertical lines directly to the command where the lines are drawn. I have also altered the drawing of the blue resistors.

With this solution the coordinates are still in the code but with a lot less repetitions.

-
My idea was to replace most of the hard coded dimensions by a set of parameters, ie number of (black) resistors front", "xlength of black (horizontal) resistors front", "xlength of blue (sloped) resistors", "xlength of black (horizontal resistors rear)" (possibly identical to the first black ones, and to use this kind of parameter to calculate the coordinates... – Yves May 29 '12 at 11:15