[Tex/LaTex] Rotate voltmeter CircuiTikz

circuitikz

I'm using Latex and CircuiTikz to draw circuits but I can't rotate de voltmeter without making a disaster. Any idea? Here is an example.

\begin{circuitikz}
\draw
(0,0) to[ammeter] (3,0)
      to (4,0)
      to[lamp] (4,-2)
      to (0,-2)
      to[sV] (0,0);
\draw (3,0) to[voltmeter] (3,-2);
\end{circuitikz}

enter image description here

Best Answer

I see that in the last version of circuitikz, the definitions for ammeter and voltmeter have been changed, so if your version is 0.3.0 or newer, use the following code. If you don't need the diagonal arrow, comment the last two \pgfusepath{draw}. However I notice that now the circles don't touch the wires (I wonder why). If you want to correct this behaviour, replace the lines

\pgfpathcircle{\pgfpointorigin}{.9\pgf@circ@res@up}
<...>
\pgfpathlineto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@up}}

with

\pgfpathcircle{\pgfpointorigin}{\pgf@circ@res@up}
<...>
\pgfpathlineto{\pgfpoint{-1.06\pgf@circ@res@other}{1.06\pgf@circ@res@up}}

but then you have to do the same in the ammeter definition. enter image description here

\documentclass{standalone}
\usepackage{circuitikz}
\makeatletter
\def\pgf@circ@myvoltmeter@path#1{\pgf@circ@bipole@path{myvoltmeter}{#1}}
\tikzset{myvoltmeter/.style = {\circuitikzbasekey, /tikz/to
                               path=\pgf@circ@myvoltmeter@path}}
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/voltmeter/height}}{myvoltmeter}{\ctikzvalof{bipoles/voltmeter/height}}{\ctikzvalof{bipoles/voltmeter/width}}{
    \def\pgf@circ@temp{right}
    \ifx\tikz@res@label@pos\pgf@circ@temp
        \pgf@circ@res@step=-1.2\pgf@circ@res@up
    \else
        \def\pgf@circ@temp{below}
        \ifx\tikz@res@label@pos\pgf@circ@temp
            \pgf@circ@res@step=-1.2\pgf@circ@res@up
        \else
            \pgf@circ@res@step=1.2\pgf@circ@res@up
        \fi
    \fi

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}       
    \pgfpointorigin \pgf@circ@res@other =  \pgf@x  \advance \pgf@circ@res@other by -\pgf@circ@res@up
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@zero}}
    \pgfusepath{draw}

    \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

        \pgfscope
            \pgfpathcircle{\pgfpointorigin}{.9\pgf@circ@res@up} % change this if you want to touch the wires
            \pgfusepath{draw}       
        \endpgfscope    

    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgftransformrotate{90}
    \pgfsetarrowsend{latex}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@up}} % change this if you want to touch the wires
    \pgfusepath{draw} % comment this if you don't need the diagonal arrow
    \pgfsetarrowsend{}


    \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfusepath{draw} % comment this if you don't need the diagonal arrow

    \pgfnode{circle}{center}{\textbf{V}}{}{}
}
\makeatother
\begin{document}
\begin{circuitikz}
\draw
(0,0) to[ammeter] (3,0)
      to (4,0)
      to[lamp] (4,-2)
      to (0,-2)
      to[sV] (0,0);
\draw (3,0) to[myvoltmeter] (3,-2);
\end{circuitikz}
\end{document}
Related Question