旋转电压表 CircuiTikz

旋转电压表 CircuiTikz

我正在使用 Latex 和 CircuiTikz 绘制电路,但无法旋转电压表,否则会造成灾难。有什么想法吗?这是一个例子。

\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}

在此处输入图片描述

答案1

有一个更简单的方案可以实现该目标。建议的方法定义一个mymeter带有 2 个参数的命令\#1=name\#2=angle即旋转。基本上,它voltmeter通过绘制具有旋转能力的 mymeter 来重新定义。

\newcommand{\mymeter}[2] 
{  % #1 = name , #2 = rotation angle
\begin{scope}[transform shape,rotate=#2]
\draw[thick] (#1)node(){$\mathbf V$} circle (11pt);
\draw[rotate=45,-latex] (#1)  +(-17pt,0) --+(17pt,0);
\end{scope}
}

在此处输入图片描述

代码

\documentclass[border=1cm,varwidth]{standalone}  
\usepackage{tikz,amsmath}
\usepackage[american,siunitx]{circuitikz}
\usetikzlibrary{arrows}

\newcommand{\mymeter}[2] 
{  % #1 = name , #2 = rotation angle
\begin{scope}[transform shape,rotate=#2]
\draw[thick] (#1)node(){$\mathbf V$} circle (11pt);
\draw[rotate=45,-latex] (#1)  +(-17pt,0) --+(17pt,0);
\end{scope}
}

\begin{document}

OP's circuit:

\medskip

\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}

\medskip

Result of proposed approach:

\medskip

\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,color=white,name=M](3,-2);
\mymeter{M}{0}  % try 90, 0, -90
\end{circuitikz}
\end{document}

答案2

我看到在 的最新版本中circuitikz,电流表和电压表的定义已经更改,因此如果您的版本是 0.3.0 或更新版本,请使用以下代码。如果您不需要对角箭头,请注释掉最后两个\pgfusepath{draw}。但是我注意到现在圆圈不接触电线(我不知道为什么)。如果您想纠正此行为,请将行替换为

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

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

但你必须在电流表定义中做同样的事情。 在此处输入图片描述

\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}

答案3

使用版本 0.9.5(2019 年 10 月 12 日),这可以通过rmeter(圆形仪表)实现

\begin{circuitikz}
    \draw
    (0,0) to[ammeter] (3,0)
    to (6,0)
    to[lamp] (6,-2)
    to (0,-2)
    to[sV] (0,0);
    \draw (3,0) to[voltmeter] (3,-2);
    \draw
    (4,0) to[rmeter, n=rm1] (4,-2)
    (rm1.center) node [anchor=center] () {V}
    ;
    \draw
    (5,0) to[rmeterwa, n=rm2] (5,-2)
    (rm2.center) node [anchor=center] () {A}
    ;
\end{circuitikz}

在此处输入图片描述

相关内容