# Scaling components in CircuiTikz with necommand

My question refers to: Scaling components in CircuiTikz

I would like to scale single circuitikz components to various sizes, e.g. with the command

/tikz/circuitikz/bipoles/length=1cm


Is it possible to use it with '\newcommand'? And how?

\draw (0,0) to[/tikz/circuitikz/bipoles/length=1cm,inductor] (3,0);


which works perfectly fine. But it does not work with

\newcommand{\compScale}[1]{/tikz/circuitikz/bipoles/length=#1cm}


in the preamble and

\draw (0,0) to[\compScale{1},inductor] (3,0);


I get the error:

! Package pgfkeys Error: I do not know the key '/tikz/circuitikz/bipoles/length =1cm' and I am going to ignore it. Perhaps you misspelled it.


In the manual, you can find that the suggested way to scale the components is to use their class scale parameter. Changing the bipole base length is ok, but on a general term (you should do it for a whole circuit, or at least a whole path. Check the manual, around page 23, scaling of components).

The correct way is to use the class scaling (unfortunately, you have to use a specific key for any class of components; I could think of adding a generic scaling in the future, although I am not sure of its usefulness).

Like (read the comments; the compScale macro is the one from the fine answer by a friendly cat):

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

\newcommand{\compScale}[1]{/tikz/circuitikz/bipoles/length=#1cm}
%
% use a specific scaled component, maybe with a parameter.
%
\tikzset{
bigL/.style={L, inductors/scale=1.5},
scaled L/.style={L, inductors/scale=#1},
scaled/.default=1, % or whatever
}
\begin{document}
\begin{circuitikz}
\draw (0,0) to[/tikz/circuitikz/bipoles/length=2cm,inductor=L, o-o] ++(3,0) to [L=L, o-o] ++(3,0);
\end{circuitikz}

\bigskip

\begin{circuitikz}
\draw (0,0) to[style/.expanded=\compScale{2},inductor=L, o-o] ++(3,0) to [L=L, o-o] ++(3,0);
\end{circuitikz}

\bigskip

\begin{circuitikz}
\draw (0,0) to[bigL, l=L, o-o] ++(3,0) to [scaled L=0.8, l=L, o-o] ++(3,0);
\end{circuitikz}

\end{document}


(Notice the artifacts on the poles due to the local changes of bipoles/lenght)

Welcome! You need to expand the macro.

\documentclass{article}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}
\draw (0,0) to[/tikz/circuitikz/bipoles/length=1cm,inductor] (3,0);
\end{circuitikz}

\newcommand{\compScale}[1]{/tikz/circuitikz/bipoles/length=#1cm}
\begin{circuitikz}
\draw (0,0) to[style/.expanded=\compScale{1},inductor] (3,0);
\end{circuitikz}

\begin{circuitikz}
\draw (0,0) to[style/.expanded=\compScale{2},inductor] (3,0);
\end{circuitikz}

\end{document}


I guess that, if you explain what you really want to do, there will be much better options. Building on John Kormylo's comment, one could define a style cscale that scales the component by a factor.

\documentclass{article}
\usepackage{circuitikz}
\makeatletter
\tikzset{cscale/.code={\pgf@circ@Rlen=#1\pgf@circ@Rlen},cscale/.default=1}
\makeatother
\begin{document}
\begin{circuitikz}
\draw (0,0) to[cscale=1,inductor] (3,0);
\end{circuitikz}

\begin{circuitikz}
\draw (0,0) to[cscale=2,inductor] (3,0);
\end{circuitikz}
\end{document}


• cscale is in fact the better option. though, there occurs the same problem concerning the pole size as Rmano´s answer shows Mar 20 '20 at 10:04