circuitikz 中的直电压箭头

circuitikz 中的直电压箭头

我想要直的电压箭头circuitikz,但都是弯的。有人有新的解决方案吗?弯的箭头太丑了。

\documentclass[a4paper,10pt]{scrartcl}
\usepackage{tikz}
\usepackage[european]{circuitikz}
\begin{document}
\begin{circuitikz}[scale=2,transform shape] \draw
 (0,0) to [battery1] (0,2)
 (0,0) --(4,0)
 (0,2) to [R, l=$\mathrm{R_{vor}}$, v=U] (2,2)
 (2,2) -- (4,2)
 (2,2) to [thRp, l=$\mathrm{R_{PT}}$, v=U] (2,0)
 (4,2) to [voltmeter] (4,0)
;\end{circuitikz}
\end{document}

答案1

根据此评论,以下可能是一个可能的解决方案(注意:它刚刚用初始示例进行了测试,因此可能需要更多的测试工作)。

我引入了一个新选项german(按照此评论) 负责绘制直箭头:使用 激活它\ctikzset{voltage=german}

代码:

\documentclass[a4paper,10pt]{scrartcl}
\usepackage[european]{circuitikz}


\makeatletter

\newif\ifpgf@circuit@germanvoltage
\ctikzset{voltage/german/.code = {\pgf@circuit@germanvoltagetrue } }

%% Output routine for generic bipoles

\def\pgf@circ@drawvoltagegeneric{
    \pgfextra{
        \ifnum \ctikzvalof{mirror value}=-1
                        \ifpgf@circuit@bipole@voltage@below\pgf@circuit@bipole@voltage@belowfalse\else\pgf@circuit@bipole@voltage@belowtrue\fi
        \fi

        \ifpgf@circuit@bipole@voltage@below
            \def\pgf@circ@voltage@angle{90}
        \else
            \def\pgf@circ@voltage@angle{-90} 
        \fi 

        \edef\pgf@temp{/tikz/circuitikz/bipoles/\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}/voltage/distance from node}
        \pgfkeysifdefined{\pgf@temp}
            { \edef\distacefromnode{\ctikzvalof{bipoles/\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}/voltage/distance from node}} }
            { \edef\distacefromnode{\ctikzvalof{voltage/distance from node}} }
        \edef\pgf@temp{/tikz/circuitikz/bipoles/\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}/voltage/bump b}
        \pgfkeysifdefined{\pgf@temp}
            { \edef\bumpb{\ctikzvalof{bipoles/\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}/voltage/bump b}} }
            { \edef\bumpb{\ctikzvalof{voltage/bump b}} }
    }

    coordinate (pgfcirc@mid) at ($(\tikztostart) ! \distacefromnode ! (\ctikzvalof{bipole/name}.left)$)
    coordinate (pgfcirc@Vfrom) at ($(pgfcirc@mid) ! -\ctikzvalof{voltage/distance from line}\pgf@circ@Rlen ! \pgf@circ@voltage@angle:(\ctikzvalof{bipole/name}.left)$) 

    coordinate (pgfcirc@mid) at ($(\tikztotarget) ! \distacefromnode ! (\ctikzvalof{bipole/name}.right)$)
    coordinate (pgfcirc@Vto) at ($(pgfcirc@mid) ! \ctikzvalof{voltage/distance from line}\pgf@circ@Rlen ! \pgf@circ@voltage@angle : (\ctikzvalof{bipole/name}.right)$)

    \ifpgf@circuit@bipole@voltage@below
        coordinate (pgfcirc@Vcont1) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.-110)$)
        coordinate (pgfcirc@Vcont2) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.-70)$)
    \else
        coordinate (pgfcirc@Vcont1) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.110)$)
        coordinate (pgfcirc@Vcont2) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.70)$)
    \fi

    \ifpgf@circuit@germanvoltage
      \ifpgf@circuit@bipole@voltage@below
        coordinate (pgfcirc@Vcont1) at ($(\ctikzvalof{bipole/name}.center) ! \ctikzvalof{voltage/bump a} ! (\ctikzvalof{bipole/name}.-120)$)
        coordinate (pgfcirc@Vcont2) at ($(\ctikzvalof{bipole/name}.center) ! \ctikzvalof{voltage/bump a} ! (\ctikzvalof{bipole/name}.-60)$)
    \else
        coordinate (pgfcirc@Vcont1) at ($ (\ctikzvalof{bipole/name}.center) ! \ctikzvalof{voltage/bump a} ! (\ctikzvalof{bipole/name}.120)$)
        coordinate (pgfcirc@Vcont2) at ($ (\ctikzvalof{bipole/name}.center) ! \ctikzvalof{voltage/bump a} ! (\ctikzvalof{bipole/name}.60)$)
      \fi
    \fi

    \ifpgf@circuit@europeanvoltage
        \ifpgf@circuit@germanvoltage
          \ifpgf@circuit@bipole@voltage@backward
            (pgfcirc@Vcont2)  -- node[currarrow, sloped,  allow upside down, pos=1] {} (pgfcirc@Vcont1)
          \else
            (pgfcirc@Vcont1)  -- node[currarrow, sloped,  allow upside down, pos=1] {} (pgfcirc@Vcont2)
          \fi
        \else
          \ifpgf@circuit@bipole@voltage@backward
            (pgfcirc@Vto) .. controls (pgfcirc@Vcont2)  and (pgfcirc@Vcont1) .. 
                node[currarrow, sloped,  allow upside down, pos=1] {} 
            (pgfcirc@Vfrom) 
          \else
            (pgfcirc@Vfrom) .. controls (pgfcirc@Vcont1)  and (pgfcirc@Vcont2) ..
                node[currarrow, sloped,  allow upside down, pos=1] {}
            (pgfcirc@Vto)   
          \fi  
        \fi      
    \else
        \ifpgf@circuit@bipole@voltage@backward
            (pgfcirc@Vfrom) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{\scriptsize$+$}   
            (pgfcirc@Vto) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{$-$}
        \else
            (pgfcirc@Vfrom) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{\scriptsize$-$}   
            (pgfcirc@Vto) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{$+$}
        \fi 
    \fi
}
\makeatother


\begin{document}
\begin{circuitikz}[scale=2,transform shape] 
\ctikzset{voltage=german}
\draw
 (0,0) to [battery1] (0,2)
 (0,0) --(4,0)
 (0,2) to [R, l=$\mathrm{R_{vor}}$, v=U] (2,2)
 (2,2) -- (4,2)
 (2,2) to [thRp, l=$\mathrm{R_{PT}}$, v=U] (2,0)
 (4,2) to [voltmeter] (4,0)
;
\end{circuitikz}
\end{document}

结果:

在此处输入图片描述

相关内容