circuitikz包中的电压转换命令

circuitikz包中的电压转换命令

我目前正在尝试改变元件和电压箭头之间的距离。但我遇到了问题。

不移位的是左边的电路,移位的是右边的电路。

电压偏移命令似乎适用于每个组件,但我不明白具体是怎么回事。每个组件似乎都与其他组件大小相同,所以我无法相对于它们的大小。它可能相对于它们的初始距离?

有没有办法将电压偏移设置为绝对值。或者有没有办法将电压偏移命令应用于每个组件类型?我可以使用这个:

\draw (2,0) to [R,v=$U_R$, voltage shift = 2] (2,-1)

但我想全局改变它。

梅威瑟:

\documentclass{report}
\usepackage{graphicx} % Required for inserting images

\usepackage{tikz}
\usepackage[european,straightvoltages]{circuitikz}

\ctikzset{resistors/scale=0.55}
\ctikzset{inductors/scale=0.55}
\ctikzset{capacitors/scale=0.6}
\ctikzset{sources/scale=.8}
\ctikzset{bipoles/thickness=1}
\ctikzset{tripoles/thickness=1}
\tikzset{every picture/.style = {transform shape, line width=1pt}}

\begin{document}

\hbox{
    \begin{circuitikz}
     % Switch
    \draw (2,0) node[spdt, rotate=90,anchor=in] (sw) {};
    \draw (sw.out 2)  node[right] {(2)};
    \draw (sw.out 1)  node[left] {(1)};

     %Komponenen
    \draw (0.5,0)  to [V_=$U$] (0.5,-1);
    \draw (2,0) to [R,v=$U_R$] (2,-1) to [L,v=$U_L$] (2,-2);
    \draw (3.5,0) to [C,v=$U_C$] (3.5,-2);

     %Verkabelung
    \draw (0.5,0) to (0.5,1.5) -| (sw.out 1);
    \draw (3.5,0) to (3.5,1.5) -| (sw.out 2);
    \draw (2,-2) to (2,-2.5) -| (0.5,-1);
    \draw (3.5,-2) |- (2,-2.5) node[circ]{};

    \draw (4.5,1) [open,v=$U$] to (4.5,-2);
        
    \end{circuitikz}

    \hspace{2cm}
    
    \ctikzset{voltage shift = 2}
    \begin{circuitikz}
    % Switch
    \draw (2,0) node[spdt, rotate=90,anchor=in] (sw) {};
    \draw (sw.out 2)  node[right] {(2)};
    \draw (sw.out 1)  node[left] {(1)};

    %Komponenen
    \draw (0.5,0)  to [V_=$U$] (0.5,-1);
    \draw (2,0) to [R,v=$U_R$] (2,-1) to [L,v=$U_L$] (2,-2);
    \draw (3.5,0) to [C,v=$U_C$] (3.5,-2);

     %Verkabelung  
    \draw (0.5,0) to (0.5,1.5) -| (sw.out 1);
    \draw (3.5,0) to (3.5,1.5) -| (sw.out 2);
    \draw (2,-2) to (2,-2.5) -| (0.5,-1);
    \draw (3.5,-2) |- (2,-2.5) node[circ]{};

    \draw (4.5,1) [open,v=$U$] to (4.5,-2);
        
    \end{circuitikz}
}

\end{document}

在此处输入图片描述

答案1

我检查过了,是的,如果你愿意的话,这是一个缺陷或者一个错误。

电压标签定位的代码非常古老*,带有许多神奇的数字,而且我担心该straightvoltage选项的测试效果不尽如人意。

我尝试了一些简单的更改,但对向后兼容性的影响是无法控制的。因此,我担心,除非有人介入帮助,否则那边的更改将是一项“退休任务”……

解决方法

较新版本:从版本开始1.6.5,不需要进行修补,因为我添加了一个可调参数来解决这个问题;请参阅https://github.com/circuitikz/circuitikz/pull/750---现在你只需使用\ctikzset{voltage shift sources adjust=0.2}

(最高版本1.6.4):您可以使用以下代码调整电压源的偏移效果,方法是调整0.2修补代码中的(也许我会将其添加到库存代码中,尽管这有点像牛皮纸袋修复)。如您所见,除此之外,还有一些棘手的事情straightvoltages与开放组件有关,我在第三个示例中将其偏移设置为零,从而解决了这些问题。

\documentclass[border=3mm]{standalone}
\usepackage{graphicx} % Required for inserting images
\usepackage[european,straightvoltages]{circuitikz}
%%%% hack: tune the 0.2 here to control the voltage source shift
%%%% the other bug: now the "open component" misbehave, but that's
%%%% another story
\usepackage{etoolbox}
\makeatletter
\patchcmd{\pgf@circ@drawvoltagegenerator}
    {\pgfmathsetmacro{\bumpaplus}{\bumpa + 0.5*\shiftv}}
    {\pgfmathsetmacro{\bumpaplus}{\bumpa + 0.2*\shiftv}}
    {\relax}{\ERROR}
\makeatother
\ctikzset{resistors/scale=0.55}
\ctikzset{inductors/scale=0.55}
\ctikzset{capacitors/scale=0.6}
\ctikzset{sources/scale=.8}
\ctikzset{bipoles/thickness=1}
\ctikzset{tripoles/thickness=1}
\tikzset{every picture/.style = {transform shape, line width=1pt}}

\newcommand{\circuit}[1][]{%
    \begin{circuitikz}
        % Switch
        \draw (2,0) node[spdt, rotate=90,anchor=in] (sw) {};
        \draw (sw.out 2)  node[right] {(2)};
        \draw (sw.out 1)  node[left] {(1)};
        %Komponenen
        \draw (0.5,0)  to [V_=$U$] (0.5,-1);
        \draw (2,0) to [R,v=$U_R$] (2,-1) to [L,v=$U_L$] (2,-2);
        \draw (3.5,0) to [C,v=$U_C$] (3.5,-2);
        %Verkabelung
        \draw (0.5,0) to (0.5,1.5) -| (sw.out 1);
        \draw (3.5,0) to (3.5,1.5) -| (sw.out 2);
        \draw (2,-2) to (2,-2.5) -| (0.5,-1);
        \draw (3.5,-2) |- (2,-2.5) node[circ]{};
        %
        \draw (4.5,1) [open,v=$U$,#1] to (4.5,-2);
    \end{circuitikz}
}

\begin{document}

\circuit
\quad
\ctikzset{voltage shift = 2}
\circuit
\quad
\circuit[voltage shift=0] % explicitly put to zero voltage shift for open

\end{document}

在此处输入图片描述

反正,我的建议是坚持正常的大小和比例,如果你想要一个更小的电路,只需将其缩放即可。我在这里准备了一个小例子来展示效果……

\documentclass{report}
\usepackage[a3paper]{geometry}
\usepackage{graphicx} % Required for inserting images

\usepackage[european,straightvoltages]{circuitikz}
\ctikzset{bipoles/thickness=1}
\ctikzset{tripoles/thickness=1}
\tikzset{every picture/.style = {line width=1pt}}

\newcommand{\circuit}{%
    \begin{tikzpicture}
        % Switch
        \draw (2,0) node[spdt, rotate=90,anchor=in] (sw) {};
        \draw (sw.out 2)  node[right] {(2)};
        \draw (sw.out 1)  node[left] {(1)};
        %Komponenen
        \draw (0.5,0)  to [V_=$U$] (0.5,-1);
        \draw (2,0) to [R,v=$U_R$] (2,-1) to [L,v=$U_L$] (2,-2);
        \draw (3.5,0) to [C,v=$U_C$] (3.5,-2);
        %Verkabelung
        \draw (0.5,0) to (0.5,1.5) -| (sw.out 1);
        \draw (3.5,0) to (3.5,1.5) -| (sw.out 2);
        \draw (2,-2) to (2,-2.5) -| (0.5,-1);
        \draw (3.5,-2) |- (2,-2.5) node[circ]{};
        %
        \draw (4.5,1) [open,v=$U$] to (4.5,-2);
    \end{tikzpicture}
}
\newcommand{\circuitlarge}[1][]{%
    \begin{tikzpicture}[#1]
        % Switch
        \draw (4,0) node[spdt, rotate=90,anchor=in] (sw) {};
        \draw (sw.out 2)  node[right] {(2)};
        \draw (sw.out 1)  node[left] {(1)};
        %Komponenen
        \draw (1,0)  to [V_=$U$] (1,-2);
        \draw (4,0) to [R,v=$U_R$] (4,-2) to [L,v=$U_L$] (4,-4);
        \draw (7,0) to [C,v=$U_C$] (7,-4);
        %Verkabelung
        \draw (1,0) to (1,3) -| (sw.out 1);
        \draw (7,0) to (7,3) -| (sw.out 2);
        \draw (4,-4) to (4,-5) -| (1,-2);
        \draw (7,-4) |- (4,-5) node[circ]{};
        %
        \draw (9,2) [open,v=$U$] to (9,-4);
    \end{tikzpicture}
}


\begin{document}
{%
    \ctikzset{resistors/scale=0.55}%
    \ctikzset{inductors/scale=0.55}%
    \ctikzset{capacitors/scale=0.6}%
    \ctikzset{sources/scale=.8}%
    \circuit
}
\quad
{
    \ctikzset{sources/scale=1.2}%
    \ctikzset{switches/scale=1.8}%
    \LARGE
    \circuitlarge[scale=0.55, transform shape]
    \ctikzset{voltage shift=1.5}
    \circuitlarge[scale=0.55, transform shape]
    
}

\end{document}

在此处输入图片描述

我在 GitHub 项目上打开了一个问题并尝试在未来解决它。实际上,电压的事情应该完全重写(首先,使用edges 作为箭头,这样它们就可以独立于电线进行样式设置,使用更可靠的锚点,等等)。


(*) 是的,是我的。不过已经很旧了。

相关内容