我有一个 circuitikz,在 Ubuntu 20.04 上是正确的,但在 22.04 上却显示为乱码

我有一个 circuitikz,在 Ubuntu 20.04 上是正确的,但在 22.04 上却显示为乱码

我有以下circuitikz代码

\begin{figure}[h]
\resizebox{250pt}{100pt}{
\begin{circuitikz}[american]
        \draw (0,0) [vsource,l=$0V$,xshift=10pt] to [short] (6.5,0);
 \draw (1,0) to [sV, o-o, l=$Vin$] (1,3) % White noise source 
        to [short] +(0,1)
        to [short] +(1,0)
    to [european resistor,l=$R_1$] +(0,-2)
    to [european potentiometer,l=$R_{SPI2}$] +(0,-1)
    to [short] +(0,-1)
    ;
    % wiper R_{SPI2}
    \draw (2.6,2.3) to [short,-o] (2.6,1.5);
       \draw (3.5,4) to [C,l=$C$] (3.5,2.3)
    to [short] (3.5,3)
    ;

    \draw (5,4) to [short] +(0,-0.3)
     to [european potentiometer,l=$R_{SPI1}$] +(0,-1);
    \draw (5,2.6) to [short] (5,2.3);
    %wiper R_{SPI1}
    \draw (5.5,4) to [short,-o] (5.5,3.22);
    \draw (2,4) to [short] (3.5,4);

  \node[draw,circle,blue] (A) at (9,2.3) {$FFT2$};
   \draw [short,o-,blue] (8,2.3) to [short,-o] (2.0,2.3);
   \node[draw,circle,blue] (A) at (9,4) {$FFT1$};
   \draw [short,o-,blue] (8,4) to [short] (3.0,4.0)
    %to [short,-o] (15.0,3.0);
   ;

 \end{circuitikz}
 } % resize box
 \caption{
Blah blah blah impedance.
}
\label{fig:tds_wl_detector}
\end{figure}

在 Ubuntu 22.04 安装中,它提供

在此处输入图片描述

在较旧的 20.04 Ubuntu 上,它(似乎正确)给出

在此处输入图片描述

我是不是在使用时做了一些未定义的事情circuitikz?它们渲染的方式不同,这看起来很奇怪。

答案1

让我们从第一行开始:

 \draw (0,0) [vsource,l=$0V$,xshift=10pt] to [short] (6.5,0);

语法不正确,并且从未得到支持,因此行为未定义。必须指定 path-style 元素里面命令,因此语法为:

\draw (coordinate 1) to[...whatever...] (coordinate 2);

...实际上,你没有vsource在任何地方标注 $0V$。我不知道你的意图是什么,所以我只能猜测一下。

然后,我认为你搞错了相对+()样式坐标。它们指定了一个相对坐标,是的,但它们不会移动当前点...我想你指的是语法++()

最后,您不能像现在这样猜测距离;您必须学会使用正交和命名坐标。例如,要连接到雨刮器,您需要给电位计命名,然后才能使用锚点...name.wiper。例如:

\draw (2.6,2.3) to [short,-o] (2.6, 2.3 |- rspi2.wiper) -- (rspi2.wiper);

意思是:从 出发(2.6,2.3);然后带着一个元素走到垂直位置为、水平坐标为short的点,添加一个极点;然后继续(2.6,2.3)(rspi2.wiper)(rspi2.wiper)确切地雨刮器位置。

此外,一般来说,使用默认尺寸,电阻器无法在 1cm 内容纳;我不想改变坐标,因此我将双极子的尺寸缩小了约 40% \ctikzset{bipoles/length=1cm}

这是使你的电路正确编译的最小更改,但它仍然写得相当差。我稍后会尝试添加更好的版本。

\documentclass[border=10pt]{standalone}
\usepackage[siunitx]{circuitikz}
\begin{document}
\begin{tikzpicture}[american]
    \ctikzset{bipoles/length=1cm}
    \draw (0,0) to[vsource,l=$0V$] (6.5,0);
    \draw (1,0) to [sV, o-o, l=$Vin$] (1,4) % White noise source 
        to [short] ++(1,0)
        to [european resistor,l=$R_1$] ++(0,-2)
        to [european potentiometer,l_=$R_{SPI2}$, name=rspi2] ++(0,-1)
        to [short] ++(0,-1)
        ;
    % wiper R_{SPI2}
    \draw (2.6,2.3) to [short,-o] (2.6, 2.3 |- rspi2.wiper) -- (rspi2.wiper);
    \draw (3.5,4) to [C,l=$C$] (3.5,2.3) 
        to [short] (3.5,3)
        ;

    \draw (5,4) to [short] ++(0,-0.3)
        to [european potentiometer,l=$R_{SPI1}$, name=rspi1] ++(0,-1.3);
    \draw (5,2.6) to [short] (5,2.3);
    %wiper R_{SPI1}
    \draw (5.5,4) to [short,-o] (5.5, 4 |- rspi1.wiper) -- (rspi1.wiper);
    \draw (2,4) to [short] (3.5,4);

    \node[draw,circle,blue] (A) at (9,2.3) {$FFT2$};
    % the following is wrong too
    \draw [short,o-,blue] (8,2.3) to [short,-o] (2.0,2.3);
    \node[draw,circle,blue] (A) at (9,4) {$FFT1$};
    % and this
    \draw [short,o-,blue] (8,4) to [short] (3.0,4.0)
        %to [short,-o] (15.0,3.0);
        ;
\end{tikzpicture}
\end{document}

在此处输入图片描述

最后...如果您需要重新调整电路的比例,请不要使用不同的 x 和 y 比例...这样会变得非常丑陋。如果您想缩小所有内容,保持比例,请使用scale=0.8, transform shape图片选项。

我绘制电路的方式如下,例如:

\documentclass[border=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage[siunitx]{circuitikz}
\begin{document}
\begin{tikzpicture}[american]
    \draw (0,0) -- ++(2,0) to[vsource,l=\SI{0}{V}] ++(7,0);
    % you could use the noise-style generators too, but let's just fill it
    \draw (1,0) to [sV, l=$V_{\mathit{in}}$, fill=gray] ++(0,4)
        to [short] ++(2,0) coordinate(top r1) % this will name the position as (top r1)
        to [european resistor,l=$R_1$] ++(0,-2) coordinate(bot r1)
        to [european potentiometer,l_=$R_{\mathit{SPI}2}$, name=rspi2] ++(0,-2)
        -- (0,0 -| top r1) % orthogonal coordinate, no guessing!
        ;
    \draw [blue] (bot r1) to[short, -o] ++(6,0) coordinate(fft2);
    \draw [blue] (top r1) to[short, -o] ++(6,0) coordinate(fft1);

    \draw (bot r1) ++(1,0) |- (rspi2.wiper);
    \draw (top r1) ++(2,0) coordinate(tmp) to [C,l_=$C$] (tmp|-bot r1);

    \draw (top r1) ++(4,0) coordinate(tmp)
        to [european potentiometer,l_=$R_{\mathit{SPI}1}$, name=rspi1] (tmp|-bot r1);
    \draw (top r1) ++(5,0) |- (rspi1.wiper);

    \node[draw,circle,blue, right=0.5cm] at(fft2) {\textit{FFT2}};
    \node[draw,circle,blue, right=0.5cm] at(fft1) {\textit{FFT1}};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容