[Tex/LaTex] Fitting circuitikz labels into boxes

circuitikzfittikz-pgf

I tried to draw an equivalent circuit for a resistor using the following code:

\documentclass{standalone}
\usepackage[european,cuteinductor]{circuitikz}
\usetikzlibrary{positioning, fit, calc}

\begin{document}
\begin{circuitikz}
    \draw (0,0) to[short,-*] ++(2,0) coordinate(left)
    to[R=$R$, name=r] ++(2,0)
    to[L=$L$,-*] ++(2,0) coordinate(right)
    to[short] ++(2,0)

    (left) to[short] ++(0,1)
    to[C=$C$, name=c] ($(right)+(0,1)$)
    to[short] (right)

    node[fit=(left)(right)(c)(r),draw, dashed, label={Resistor}, inner sep=10pt]{};
\end{circuitikz}
\end{document}

This resulted in:

Imgur

Fit does not take the "C" label above the capacitor into account.
I fixed this by putting an additional coordiate above the capacitor:

\documentclass{standalone}
\usepackage[european,cuteinductor]{circuitikz}
\usetikzlibrary{positioning, fit, calc}

\begin{document}
\begin{circuitikz}
    \draw (0,0) to[short,-*] ++(2,0) coordinate(left)
    to[R=$R$, name=r] ++(2,0)
    to[L=$L$,-*] ++(2,0) coordinate(right)
    to[short] ++(2,0)

    (left) to[short] ++(0,1)
    to[C=$C$, name=c] ($(right)+(0,1)$)
    to[short] (right)

    coordinate[above=10pt of c] (top)
    node[fit=(left)(right)(top)(r),draw, dashed, label={Resistor},
    inner sep=10pt] {};
\end{circuitikz}
\end{document}

which looks reasonable:

Imgur

Is there a better way to tell fit that it should also fit the "C" label above the capacitor?

Best Answer

As you are already loading calc tikzlibrary, you can use it to modify c coordinate inside fit:

\documentclass{standalone}
\usepackage[european,cuteinductor]{circuitikz}
\usetikzlibrary{positioning, fit, calc}

\begin{document}
\begin{circuitikz}
    \draw (0,0) to[short,-*] ++(2,0) coordinate(left)
    to[R=$R$, name=r] ++(2,0)
    to[L=$L$,-*] ++(2,0) coordinate(right)
    to[short] ++(2,0)

    (left) to[short] ++(0,1)
    to[C=$C$, name=c] ($(right)+(0,1)$)
    to[short] (right)

    node[fit={(left)(right)($(c.north)+(0,.5)$)(r)},draw, dashed, label={Resistor},
    inner sep=10pt] {};

\end{circuitikz}
\end{document}

enter image description here