Positioning two boxes inside a LC circuit in Circuitikz

boxescircuitikzpositioning

I am trying to introduce two boxes inside an LC circuit, but I encounter two problems: the first concerns the positioning of these two boxes, I cannot align them perfectly with the node, I cannot find the right value to give on the position, the second it concerns the box on the right where I cannot send the "cavity" on a new line.

\documentclass[a4paper, 12pt]{book}
\usepackage{circuitikz}
\usepackage{float}
\begin{document}
    \begin{figure}[H]
        \centering
        \begin{circuitikz}
            \draw
            (0,0) -- (2,0)
            (0,2) -- (2,2)
            (0,0) to[C, l^=$C$] (0,2)
            (2,0) to[L, l^=$L$] (2,2)
            (0.5,2) -- (0.5,2.5)
            (1.5,2) -- (1.5,2.5)
            (-1,2.5) -- (0.5,2.5)
            (3, 2.5) -- (1.5,2.5)
            node[draw,rectangle] at (-1.5,2.5){V}
            node[draw,rectangle] at (3,2.5){E.M. \\ Cavity};
        \end{circuitikz}
        \label{fig:lc-circuit-cavity}
    \end{figure}
\end{document}

I'm not very familiar with this package, but I needed it to make a series of circuits.

Best Answer

Pure guessing, what you like to draw:

enter image description here

Is this correct image?

\documentclass[a4paper, 12pt]{book}
\usepackage{circuitikz}


\begin{document}
    \begin{figure}[ht]
        \centering
        \begin{circuitikz}
            \draw
            (0,0)   to[C=$C$] ++ (0, 2) -- ++ ( 2,0) 
                    to[L=$L$] ++ (0,-2) -- ++ (-2,0)
            %
            (0.5,2) |- ++ (-1.5,0.5) node[left, draw] {V}
            (1.5,2) |- ++ ( 1.5,0.5) node[right,draw, align=center] {E.M.\\ Cavity};
        \end{circuitikz}
        \label{fig:lc-circuit-cavity}
    \end{figure}
\end{document}

Edit: Package circuitikz is based on tikz package. This means, that you circuitikz˙ scheme you can use any of elements defined in tikz package.

In package circuitikz are defined elements of electrical circuits. They form two families: path-style components and * node style* components. In your case are used *path style. They you ca draw as \draw (<coordinate 1>) to [component name and annotations>] (<coordinate 2>). To them you can append elements from tikz as is done in above MWE (Minimal Working Example):

\draw (<coordinate 1>) to [component name and annotations>] (<coordinate 2>) node [right] {<text>}`

where node can has any of style provided by tikz.

At drawing you can use absolute coordinate (as you do in your MWE) or relative as is used in above MWE. It is draw in two parts. In the first is a "loop" with C and L connected by lines, in the second parts are drawn lines with nodes at the end. Lines are drawn with orthogonal connection (used are |- path with the same meaning as they have in tikz images)

Details of them yo can find in the package documentation.

Related Question