# CircuiTikZ: Create a command to resize a single component

As frequently asked, I want to resize a single component in a circuitikz environment, which is achieved by passing /tikz/circuitikz/bipoles/length=<length> to the component options. I have the following example:

\documentclass{article}
\usepackage[american]{circuitikz}

\begin{document}
\begin{circuitikz}
\draw node[ground,/tikz/circuitikz/bipoles/length=2cm]{} to [C] (0,2) to [L] (2,2) to [C] (2,0) to node[ground,/tikz/circuitikz/bipoles/length=2cm]{} (2,0);
\draw (2,2) to [pC] (4,2) to [R](4,0) to node[ground,/tikz/circuitikz/bipoles/length=2cm]{} (4,0)
(5,2) node[npn](npn1) {}
(4,2) to [short] (npn1.base)
(npn1.emitter) to [R,/tikz/circuitikz/bipoles/length=1cm] (5,0)
to node[ground]{}(5,0)
(npn1.collector) to[R,/tikz/circuitikz/bipoles/length=1cm] (5,4)
to[short](4,4) to [R] (4,2)
(5,4) node[vcc] (5,4){$Vcc$}
;
\end{circuitikz}
\end{document}


I want to scale all the ground nodes but one to have a length of 2cm, and for that I want to create a command, something like \newcommand{\setsize}[1]{/tikz/circuitikz/bipoles/length=#1} but that does not seem to work. It's just to not having to write all the times /tikz/circuitikz/.... That command should work with other components too.

• Have you tried with a style like the one used by @marmot in tex.stackexchange.com/a/495862/38080? Tomorrow I'll try a more general answer... – Rmano Jun 19 '19 at 20:50
• If only I knew how to program in LaTeX (I just know the basics) – Martín Jun 19 '19 at 21:06
• How about \tikzset{my ground/.style={ground,/tikz/circuitikz/bipoles/length=2cm}} and then using my ground instead of ground. Note that (as far as I understand) ground is a shape, and TikZ is clever enough to find that out, so instead of node[shape=ground] it suffices to say node[ground]. This also means that in order to change the standard behavior of ground you cannot use append style (nor append code), but you would have to "hack" it. I would like to argue that it is much better to use your style. – user121799 Jun 20 '19 at 3:05
• /tikz/circuitikz/bipoles/length is also stored as \pgf@circ@Rlen. This is used to compute all other dimensions. – John Kormylo Jun 20 '19 at 3:58
• Circuitikz stores the dimensions for its components using, for example, \ctikzset{monopoles/ground/width/.initial=0.25}. You can lose the /.initial to reset it. – John Kormylo Jun 20 '19 at 4:06

This answer provides you with a way to redefine ground but also with a warning. Let's first recall why (or how) node[ground] works. ground is a shape, not a style. So TikZ sees that there is no style ground defined and then checks the shapes, where it finds it. One could thus intercept at the first stage and just define

\tikzset{ground/.style={shape=ground,/tikz/circuitikz/bipoles/length=2cm}}


Now TikZ will find a style ground, say "Aha, the OP wants me to use the ground shape, and to set the bipole length to 2cm. Aye, madam/sir/duck/koala!". This is the full example:

\documentclass{article}
\usepackage[american]{circuitikz}
\tikzset{ground/.style={shape=ground,/tikz/circuitikz/bipoles/length=2cm}}
\begin{document}
\begin{circuitikz}
\draw node[ground]{} to [C] (0,2) to [L] (2,2) to [C] (2,0) to node[ground]{} (2,0);
\draw (2,2) to [pC] (4,2) to [R](4,0) to node[ground]{} (4,0)
(5,2) node[npn](npn1) {}
(4,2) to [short] (npn1.base)
(npn1.emitter) to [R,/tikz/circuitikz/bipoles/length=1cm] (5,0)
to node[ground]{}(5,0)
(npn1.collector) to[R,/tikz/circuitikz/bipoles/length=1cm] (5,4)
to[short](4,4) to [R] (4,2)
(5,4) node[vcc] (5,4){$Vcc$}
;
\end{circuitikz}
\end{document}


This does work, at least in this example. Note, however, that this is not the most stable approach. What if something intercepts before that? A less vulnerable approach would be to say

\tikzset{my ground/.style={shape=ground,/tikz/circuitikz/bipoles/length=2cm}}


and then to use my ground instead of ground in the nodes. To motivate this approach a bit more consider the scenario in which someone defines a style \tikzset{circle/.style={shape=rectangle}} and causes a lot of confusion. On the other hand, apart from this caveat this method allows you to modify all shapes of circuitikz and also tikz.

• Marmot, could be an idea, but it's also easy to add it for the shapes you need... There are more than 200 shapes in the package, and the to idiom complicate things. BTW, I am munging about a change to enable more styling, see github.com/circuitikz/circuitikz/issues/218 if you want to chime in. – Rmano Jun 20 '19 at 5:47
• @Rmano My next task (which I keep postponing and postponing) will be to provide the information which libraries are needed for all the examples in the pgfmanual... Anyway, thanks for doing all this! – user121799 Jun 20 '19 at 5:49