CircuiTikZ 中的 DIP 芯片对齐

CircuiTikZ 中的 DIP 芯片对齐

我想使用它circuitikz来制作面包板布局。
序言:


\tikzset{
  open socket/.style = {
    circle,
    fill = lightgray,
    inner sep = 1pt
  },
  filled socket/.style = {
    circle,
    fill = black,
    inner sep = 1pt
  }
}
\usetikzlibrary{calc, arrows.meta, backgrounds}

到目前为止,我已经获得了网格:

%% draw breadboard sections
  \foreach \y [evaluate = \y as \line using int(abs(\y))] in {0, ..., -13}{

    % draw line numbers off to the left
    \node [text=gray] at (-9, \y) {\line};
    \node [text=gray] at (9, \y) {\line};

    % draw bus and breadboard grid sockets
    \foreach \lab/\x in {l-/-8, lg/-7, A/-5, B/-4, C/-3, D/-2, E/-1, F/1, G/2, H/3, I/4, J/5, rg/7, r+/8} {
      \coordinate [open socket] (\lab\line) at (\x, \y);
    }

    % draw row connectivity for board proper
    \draw [lightgray, opacity = 0.2, very thick]
      (-5, \y) -- (-1, \y)
      (1, \y)  -- (5, \y);

  }

  % label breadboard columns

  \foreach \lab/\x in {A/-5, B/-4, C/-3, D/-2, E/-1, F/1, G/2, H/3, I/4, J/5} {
    \node [above of = \lab0] {\lab};
  }

  % label buses

  \node [above of=l-0] {V$_{-}$};
  \node [above of=lg0] {GND$_{}$};
  \node [above of=rg0] {GND$_{}$};
  \node [above of=r+0] {V$_{+}$};

  % draw bus connection lines
  \begin{scope} [
      on background layer  % these paths should not interfere with anything else
    ]
    \draw [very thick, red,  opacity = 0.2] (l-0) -- (l-13);
    \draw [very thick, blue, opacity = 0.2] (lg0) -- (lg13);

    \draw [very thick, blue, opacity = 0.2] (rg0) -- (rg13);
    \draw [very thick, red,  opacity = 0.2] (r+0) -- (r+13);
  \end{scope}

裸面包板 现在,我想将一个 DIP 芯片放置在面包板的中间,到目前为止我得到的结果如下:

\node at (E1) (081) [
                        dipchip,
                        fill = cyan!20!white,
                        circuitikz/multipoles/dipchip/pin spacing = 0.711,
                        circuitikz/multipoles/dipchip/width = 1.03,
                        anchor = pin 1,
                        num pins = 8,
                        hide numbers
                    ] {TL081};

  % and fill its pins with tiny descriptions:

  \node [right, font=\tiny] at (081.bpin 1) {ON1};
  \node [right, font=\tiny] at (081.bpin 2) {IN-};
  \node [right, font=\tiny] at (081.bpin 3) {IN+};
  \node [right, font=\tiny] at (081.bpin 4) {$V_-$};

  \node [left,  font=\tiny] at (081.bpin 5) {ON2};
  \node [left,  font=\tiny] at (081.bpin 6) {OUT};
  \node [left,  font=\tiny] at (081.bpin 7) {$V_+$};
  \node [left,  font=\tiny] at (081.bpin 8) {NC};

  \foreach \i in {1, 2, ..., 8} {
    \node at (081.pin \i) [filled socket] {};
  }

芯片面包板 得出的结果是: 结果本身没问题;但是,它要求我手动对齐芯片,这不是很灵活。有没有更好的方法可以进行这种对齐?或者,有没有一种间距方法可以用于面包板,使芯片间距与之相对应?

答案1

circuititz你可以利用所有长度都与(默认 1.4 厘米)成比例的事实来玩bipoles/length;例如:

\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\ctikzset{bipoles/length=1cm}
\ctikzset{multipoles/dipchip/pin spacing=1}
\ctikzset{multipoles/external pins width=0.5}
\ctikzset{multipoles/dipchip/width=3}
\begin{document}
\begin{circuitikz}[x=1cm, y=1cm,
    ]
    \draw [cyan, dashed](-4,-4) grid (4,4);
    \draw (-3,3) to[R, *-*] ++(1,0);
    \path (-2,3) node[dipchip, anchor=pin 1, num pins=12]{DIP};
\end{circuitikz}
\end{document}

给出:

图像

或者你可以使用双极子长度的当前值来改变 x,y 坐标,如下所示:

\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
% \ctikzset{bipoles/length=1cm}
\makeatletter\newlength{\Rlen}\setlength{\Rlen}{\pgf@circ@Rlen}\makeatother
\ctikzset{multipoles/dipchip/pin spacing=1}
\ctikzset{multipoles/external pins width=0.5}
\ctikzset{multipoles/dipchip/width=3}
\begin{document}
\begin{circuitikz}[
    x=\Rlen, y=\Rlen,
    ]
    \draw [cyan, dashed](-4,-4) grid[step=\Rlen] (4,4);
    \draw (-3,3) to[R, *-*] ++(1,0);
    \path (-2,3) node[dipchip, anchor=pin 1, num pins=12]{DIP};
\end{circuitikz}
\end{document}

其结果大致相同。

答案2

为了发出警告,我对您的代码进行了相当大的修改。不过,我认为现在它的用途更广泛了。

我改变了以下几个方面:

  • 行数现在是一个参数
  • 中间间隙的大小现在是一个参数
  • 文本大小现在是一个参数
  • 添加了有关缩放的解释

我创建了这个新的面包板命令。它仍然与您的有些相似。不要被许多 #2 吓到,这只是中间的差距。我还结合了一些您的绘图逻辑,以避免不必要的迭代。您也可以将其视为黑匣子,但请注意,我稍微改变了面包板的外观,您可能想将其改回来。

\newcommand{\breadboard}[3]{%
    \foreach \y in {1, ..., #1}{

            % Draw line numbers
            \node [text=gray] at (-2, -\y) {#3\y};
            \node [text=gray] at (12+#2, -\y) {#3\y};

            % Draw the pins
            \foreach \x in {-1, ..., 5, 5+#2, 6+#2, 7+#2, 8+#2, 9+#2, 10+#2, 11+#2}{
                    \fill[lightgray, radius=3pt] (\x,-\y) circle;
                }

            % Draw horizontal lines
            \draw [lightgray, opacity = 0.2, very thick] (1,-\y) -- (5, -\y);
            \draw [lightgray, opacity = 0.2, very thick] (5+#2,-\y) -- (9+#2, -\y);

        }

    % Draw labels
    \foreach \label/\x in {\color{red}+/-1, \color{blue}-/0, A/1, B/2, C/3, D/4, E/5, F/5+#2, G/6+#2, H/7+#2, I/8+#2, J/9+#2, \color{red}+/10+#2, \color{blue}-/11+#2}{
            \node at (\x, 0) {#3\label};
        }

    % draw bus connection lines
    \draw [very thick, red,  opacity = 0.2] (-1,-1) -- (-1,-#1);
    \draw [very thick, blue, opacity = 0.2] (0,-1) -- (0,-#1);
    \draw [very thick, red, opacity = 0.2] (10+#2,-1) -- (10+#2,-#1);
    \draw [very thick, blue,  opacity = 0.2] (11+#2,-1) -- (11+#2,-#1);

    % Optional border
    \draw [black, very thick] (-2.5,1) -- (-2.5,-#1-0.5) -- (12.5+#2,-#1-0.5) -- (12.5+#2,1) -- cycle;
}

让我们定义其他优秀答案提供的一些常量

\ctikzset{bipoles/length=1cm}
\ctikzset{multipoles/dipchip/pin spacing=1}
\ctikzset{multipoles/external pins width=0.5}
\ctikzset{multipoles/dipchip/width=1}

现在,我们可以调用我们的面包板命令,其中第一个参数是列数,第二个参数是中间间隙的宽度(以整个引脚距离为单位),第三个参数只是放在任何文本前面的东西。您可以使用它来更改字体、字体大小、颜色等

\begin{circuitikz}[
    ]
    \breadboard{10}{2}{\huge}

    \node [
        dipchip,
        anchor=pin 1,
        fill = cyan!20!white,
        num pins = 8,
        hide numbers
    ] at (5,-2) {TL081};


\end{circuitikz}
\vspace{20pt}

显示渲染的面包板的图像

这样不太好看,对吧?但是,如果我们把电路板做得更长,并改变字体大小,它看起来会很棒。至少在我看来是这样。但要使面包板更大,我们需要缩小图像。请注意,我们不仅要缩放 tikzpicture,还需要单独缩放芯片。缩小时,我们注意到字体大小保持很大。这很糟糕,但幸运的是,第三个参数让我们可以轻松处理这个问题。请注意我们如何将字体大小设置为 \small 而不是之前的 \huge

\begin{circuitikz}[
        scale=0.5
    ]
    \breadboard{30}{2}{\small}

    \node [
        dipchip,
        circuitikz/chips/scale=0.5,
        anchor=pin 1,
        fill = cyan!20!white,
        num pins = 8,
        hide numbers
    ] at (5,-2) {TL081};


\end{circuitikz}
\vspace{20pt}

显示渲染的面包板的图像

但我们甚至可以做得更好!!!有时你的芯片会变得很大,你想写下每个引脚的描述,但空间太少了。使用第一个参数,我们可以改变中间的间隙,这样我们的芯片就可以很宽,包含大量有用的文本。注意我们如何覆盖芯片宽度!

\begin{circuitikz}[
        scale=0.5
    ]
    \breadboard{30}{6}{\small}

    \node [
        dipchip,
        circuitikz/chips/scale=0.5,
        circuitikz/multipoles/dipchip/width=5,
        anchor=pin 1,
        fill = cyan!20!white,
        num pins = 8,
        hide numbers
    ] at (5,-2) {TL081};


\end{circuitikz}
\vspace{20pt}

显示渲染的面包板的图像

相关内容