Использование библиотеки схем TikZ и CircuiTikZ в одном документе

Использование библиотеки схем TikZ и CircuiTikZ в одном документе

Покопавшись немного, я нашел кое-чторешениеиспользовать tikzбиблиотеки в том же документе, что и circuitkzпакет. Или думал, что я это сделал.

Мне нравится визуальный ряд tikz logic (и возможность использования многовходовых логических вентилей) и транзисторов в circuitikz.

Я попробовал вышеупомянутое решение, и оно работает, если сделать следующее:

 \documentclass{article}

 \usepackage{circuitikz}
 \usepackage{tikz}

 \begin{document}

 \begin{figure}[htbp]
      \centering
      \begingroup
      \usetikzlibrary{circuits.logic.US}
      \usetikzlibrary{circuits.ee.IEC}
      \begin{tikzpicture}[circuit logic US, circuit ee IEC, huge circuit symbols, set resistor graphic = var resistor IEC graphic]
           \matrix[column sep=10mm, row sep=10mm,anchor=center]
           {
                \node [not gate] (not1) {}; \\
                \node [not gate] (not2) {}; \\
           };

           \node (a) at ([xshift=-25mm]not1.input) {$V_{in}^+$};
           \node [contact] (a1) at ([xshift=-10mm]not1.input) {};

           \node (b) at ([xshift=-25mm]not2.input) {$V_{in}^-$};
           \node [contact] (b1) at ([xshift=-10mm]not2.input) {};

           \node (x) at ([xshift=25mm]not1.output) {$V_{out}^-$};
           \node [contact] (x1) at ([xshift=10mm]not1.output) {};

           \node (z) at ([xshift=25mm]not2.output) {$V_{out}^+$};
           \node [contact] (z1) at ([xshift=10mm]not2.output) {};

           \node (en) at ([xshift=-30mm]$(not1.south)!0.5!(not2.north)$) {$EN$};
           \node [contact] (en1) at ($(not1.south)!0.5!(not2.north)$) {};

           \draw (en1.center) -- (not1.south) node[below right] (ennot1) {$E$};
           \draw (en1.center) -- (not2.north) node[above right] (ennot2) {$E$};

           \node [resistor={info'={$R$}}] (res1) at ([xshift=2mm, yshift=10mm]not1.north){};
           \node [resistor={info={$R$}}] (res2) at ([xshift=2mm, yshift=-10mm]not2.south){};

           \draw (a.east) -- (a1.center);
           \draw (a1.center) |- (res1.input);
           \draw (a1.center) -- (not1.input);

           \draw (b.east) -- (b1.center);
           \draw (b1.center) |- (res2.input);
           \draw (b1.center) -- (not2.input);

           \draw (en.east) -- (en1.center);

           \draw (not1.output) -- (x1.center);
           \draw (x1.center) |- (res1.output);
           \draw (x1.center) |- (x.west);

           \draw (not2.output) -- (z1.center);
           \draw (z1.center) |- (res2.output);
           \draw (z1.center) |- (z.west);

      \end{tikzpicture}
      \endgroup
      \caption{Some NOT gates with enable and resistors.}
 \end{figure}

 \begin{figure}[htbp]
      \begin{center}
           \begin{circuitikz}[scale=0.7, transform shape]
                \draw[thick,->] (0,0.5) --(1,0.5) node[anchor=south east] {$i(x,t)$};
                \node[] at (0,-1) {$v(x,t)$};
                \draw
                (0,0) node[anchor=east] {+}
                     to[short, o-] (1,0)
                     to[R=$Rx$] (3,0)
                     to[L=$Lx$] (5,0)
                (5,-2) to[R=$Gx$, *-*] (5,0)
                (5,0) to[short] (7,0)
                (7,-2) to[C=$Cx$, *-*] (7,0)
                (5,-2) to[short] (7,-2)
                (0,-2) node[anchor=east]{-}
                     to[short, o-] (5,-2)
                (9,0) node[anchor=west]{+}
                     to[short, o-] (7,0)
                (9,-2) node[anchor=west]{-}
                     to[short, o-] (7,-2)
                ;
                \draw[thick,->] (7,0.5) --(9,0.5) node[anchor=south east] {$i(x+ x,t)$};
                \node[] at (9,-1) {$v(x+ x,t)$};
           \end{circuitikz}
           \caption{Infinitesimal section of a transmission line.}
           \label{fig:transmission_line_section}
      \end{center}
 \end{figure}

 \end{document}

Но если я попытаюсь добавить еще одну цифру с помощью tikzpicture, то он выйдет с ошибками. Например:

 \documentclass{article}

 \usepackage{circuitikz}
 \usepackage{tikz}

 \begin{document}

 \begin{figure}[htbp]
      \centering
      \begingroup
      \usetikzlibrary{circuits.logic.US}
      \usetikzlibrary{circuits.ee.IEC}
      \begin{tikzpicture}[circuit logic US, circuit ee IEC, huge circuit symbols, set resistor graphic = var resistor IEC graphic]
           \matrix[column sep=10mm, row sep=10mm,anchor=center]
           {
                \node [not gate] (not1) {}; \\
                \node [not gate] (not2) {}; \\
           };

           \node (a) at ([xshift=-25mm]not1.input) {$V_{in}^+$};
           \node [contact] (a1) at ([xshift=-10mm]not1.input) {};

           \node (b) at ([xshift=-25mm]not2.input) {$V_{in}^-$};
           \node [contact] (b1) at ([xshift=-10mm]not2.input) {};

           \node (x) at ([xshift=25mm]not1.output) {$V_{out}^-$};
           \node [contact] (x1) at ([xshift=10mm]not1.output) {};

           \node (z) at ([xshift=25mm]not2.output) {$V_{out}^+$};
           \node [contact] (z1) at ([xshift=10mm]not2.output) {};

           \node (en) at ([xshift=-30mm]$(not1.south)!0.5!(not2.north)$) {$EN$};
           \node [contact] (en1) at ($(not1.south)!0.5!(not2.north)$) {};

           \draw (en1.center) -- (not1.south) node[below right] (ennot1) {$E$};
           \draw (en1.center) -- (not2.north) node[above right] (ennot2) {$E$};

           \node [resistor={info'={$R$}}] (res1) at ([xshift=2mm, yshift=10mm]not1.north){};
           \node [resistor={info={$R$}}] (res2) at ([xshift=2mm, yshift=-10mm]not2.south){};

           \draw (a.east) -- (a1.center);
           \draw (a1.center) |- (res1.input);
           \draw (a1.center) -- (not1.input);

           \draw (b.east) -- (b1.center);
           \draw (b1.center) |- (res2.input);
           \draw (b1.center) -- (not2.input);

           \draw (en.east) -- (en1.center);

           \draw (not1.output) -- (x1.center);
           \draw (x1.center) |- (res1.output);
           \draw (x1.center) |- (x.west);

           \draw (not2.output) -- (z1.center);
           \draw (z1.center) |- (res2.output);
           \draw (z1.center) |- (z.west);

      \end{tikzpicture}
      \endgroup
      \caption{Some NOT gates with enable and resistors.}
 \end{figure}

 \begin{figure}[htbp]
      \centering
      \begingroup
      \usetikzlibrary{circuits.logic.US}
      \usetikzlibrary{circuits.ee.IEC}
      \begin{tikzpicture}[circuit logic US, circuit ee IEC, huge circuit symbols, set resistor graphic = var resistor IEC graphic]
           \matrix[column sep=10mm, row sep=10mm,anchor=center]
           {
                \node [not gate] (not1) {}; \\
                \node [not gate] (not2) {}; \\
           };

           \node (a) at ([xshift=-25mm]not1.input) {$V_{in}^+$};
           \node [contact] (a1) at ([xshift=-10mm]not1.input) {};

           \node (b) at ([xshift=-25mm]not2.input) {$V_{in}^-$};
           \node [contact] (b1) at ([xshift=-10mm]not2.input) {};

           \node (x) at ([xshift=25mm]not1.output) {$V_{out}^-$};
           \node [contact] (x1) at ([xshift=10mm]not1.output) {};

           \node (z) at ([xshift=25mm]not2.output) {$V_{out}^+$};
           \node [contact] (z1) at ([xshift=10mm]not2.output) {};

           \node (en) at ([xshift=-30mm]$(not1.south)!0.5!(not2.north)$) {$EN$};
           \node [contact] (en1) at ($(not1.south)!0.5!(not2.north)$) {};

           \draw (en1.center) -- (not1.south) node[below right] (ennot1) {$E$};
           \draw (en1.center) -- (not2.north) node[above right] (ennot2) {$E$};

           \node [resistor={info'={$R$}}] (res1) at ([xshift=2mm, yshift=10mm]not1.north){};
           \node [resistor={info={$R$}}] (res2) at ([xshift=2mm, yshift=-10mm]not2.south){};

           \draw (a.east) -- (a1.center);
           \draw (a1.center) |- (res1.input);
           \draw (a1.center) -- (not1.input);

           \draw (b.east) -- (b1.center);
           \draw (b1.center) |- (res2.input);
           \draw (b1.center) -- (not2.input);

           \draw (en.east) -- (en1.center);

           \draw (not1.output) -- (x1.center);
           \draw (x1.center) |- (res1.output);
           \draw (x1.center) |- (x.west);

           \draw (not2.output) -- (z1.center);
           \draw (z1.center) |- (res2.output);
           \draw (z1.center) |- (z.west);

      \end{tikzpicture}
      \endgroup
      \caption{Some NOT gates with enable and resistors.}
 \end{figure}

 \begin{figure}[htbp]
      \begin{center}
           \begin{circuitikz}[scale=0.7, transform shape]
                \draw[thick,->] (0,0.5) --(1,0.5) node[anchor=south east] {$i(x,t)$};
                \node[] at (0,-1) {$v(x,t)$};
                \draw
                (0,0) node[anchor=east] {+}
                     to[short, o-] (1,0)
                     to[R=$Rx$] (3,0)
                     to[L=$Lx$] (5,0)
                (5,-2) to[R=$Gx$, *-*] (5,0)
                (5,0) to[short] (7,0)
                (7,-2) to[C=$Cx$, *-*] (7,0)
                (5,-2) to[short] (7,-2)
                (0,-2) node[anchor=east]{-}
                     to[short, o-] (5,-2)
                (9,0) node[anchor=west]{+}
                     to[short, o-] (7,0)
                (9,-2) node[anchor=west]{-}
                     to[short, o-] (7,-2)
                ;
                \draw[thick,->] (7,0.5) --(9,0.5) node[anchor=south east] {$i(x+ x,t)$};
                \node[] at (9,-1) {$v(x+ x,t)$};
           \end{circuitikz}
           \caption{Infinitesimal section of a transmission line.}
           \label{fig:transmission_line_section}
      \end{center}
 \end{figure}

 \end{document}

Я что-то делаю не так? Если библиотеки объявлены только в группе, разве они не могут быть объявлены в другой группе? Есть ли лучшее решение для ограничения области действия объявленных библиотек?

решение1

После внимательного прочтения CircuiTikZруководство, правильным решением будет использовать compatilibityопцию пакета и оставить библиотеки TikZ глобально загруженными. Единственный недостаток в том, что при использовании определений CircuiTikZ *перед ним следует использовать .

Например, это:

\begin{figure}[htbp]
  \begin{center}
       \begin{circuitikz}[scale=0.7, transform shape]
            \draw[thick,->] (0,0.5) --(1,0.5) node[anchor=south east] {$i(x,t)$};
            \node[] at (0,-1) {$v(x,t)$};
            \draw
            (0,0) node[anchor=east] {+}
                 to[short, o-] (1,0)
                 to[R=$Rx$] (3,0)
                 to[L=$Lx$] (5,0)
            (5,-2) to[R=$Gx$, *-*] (5,0)
            (5,0) to[short] (7,0)
            (7,-2) to[C=$Cx$, *-*] (7,0)
            (5,-2) to[short] (7,-2)
            (0,-2) node[anchor=east]{-}
                 to[short, o-] (5,-2)
            (9,0) node[anchor=west]{+}
                 to[short, o-] (7,0)
            (9,-2) node[anchor=west]{-}
                 to[short, o-] (7,-2)
            ;
            \draw[thick,->] (7,0.5) --(9,0.5) node[anchor=south east] {$i(x+ x,t)$};
            \node[] at (9,-1) {$v(x+ x,t)$};
       \end{circuitikz}
       \caption{Infinitesimal section of a transmission line.}
       \label{fig:transmission_line_section}
  \end{center}
\end{figure}

При использовании опции происходит следующее compatibility:

\begin{figure}[htbp]
  \begin{center}
       \begin{circuitikz}[scale=0.7, transform shape]
            \draw[thick,->] (0,0.5) --(1,0.5) node[anchor=south east] {$i(x,t)$};
            \node[] at (0,-1) {$v(x,t)$};
            \draw
            (0,0) node[anchor=east] {+}
                 to[*short, o-] (1,0)
                 to[*R=$Rx$] (3,0)
                 to[*L=$Lx$] (5,0)
            (5,-2) to[*R=$Gx$, *-*] (5,0)
            (5,0) to[*short] (7,0)
            (7,-2) to[*C=$Cx$, *-*] (7,0)
            (5,-2) to[*short] (7,-2)
            (0,-2) node[anchor=east]{-}
                 to[*short, o-] (5,-2)
            (9,0) node[anchor=west]{+}
                 to[*short, o-] (7,0)
            (9,-2) node[anchor=west]{-}
                 to[*short, o-] (7,-2)
            ;
            \draw[thick,->] (7,0.5) --(9,0.5) node[anchor=south east] {$i(x+ x,t)$};
            \node[] at (9,-1) {$v(x+ x,t)$};
       \end{circuitikz}
       \caption{Infinitesimal section of a transmission line.}
       \label{fig:transmission_line_section}
  \end{center}
\end{figure}

решение2

Это можно сделать, но это все равно пустая трата времени.

Очевидно, загрузка библиотек вносит некоторые глобальные изменения, которые не удаляются в конце группы. Однако вы можете создать все ваши смешанные схемы одновременно и сохранить их (глобально) в saveboxes.

Вы можете попробовать использовать externalize или просто создать изображения с помощью standalone. Лучшим решением будет скопировать исходный код для желаемых компонентов TikZ и переименовать их для использования в circuitikz.

 \documentclass{article}

 \usepackage{circuitikz}
 \usepackage{tikz}

\newsavebox{\figA}
\newsavebox{\figB}

\begin{document}

\begingroup
      \usetikzlibrary{circuits.logic.US}
      \usetikzlibrary{circuits.ee.IEC}
      \global\setbox\figA=\hbox{%
      \begin{tikzpicture}[circuit logic US, circuit ee IEC, huge circuit symbols, set resistor graphic = var resistor IEC graphic]
           \matrix[column sep=10mm, row sep=10mm,anchor=center]
           {
                \node [not gate] (not1) {}; \\
                \node [not gate] (not2) {}; \\
           };

           \node (a) at ([xshift=-25mm]not1.input) {$V_{in}^+$};
           \node [contact] (a1) at ([xshift=-10mm]not1.input) {};

           \node (b) at ([xshift=-25mm]not2.input) {$V_{in}^-$};
           \node [contact] (b1) at ([xshift=-10mm]not2.input) {};

           \node (x) at ([xshift=25mm]not1.output) {$V_{out}^-$};
           \node [contact] (x1) at ([xshift=10mm]not1.output) {};

           \node (z) at ([xshift=25mm]not2.output) {$V_{out}^+$};
           \node [contact] (z1) at ([xshift=10mm]not2.output) {};

           \node (en) at ([xshift=-30mm]$(not1.south)!0.5!(not2.north)$) {$EN$};
           \node [contact] (en1) at ($(not1.south)!0.5!(not2.north)$) {};

           \draw (en1.center) -- (not1.south) node[below right] (ennot1) {$E$};
           \draw (en1.center) -- (not2.north) node[above right] (ennot2) {$E$};

           \node [resistor={info'={$R$}}] (res1) at ([xshift=2mm, yshift=10mm]not1.north){};
           \node [resistor={info={$R$}}] (res2) at ([xshift=2mm, yshift=-10mm]not2.south){};

           \draw (a.east) -- (a1.center);
           \draw (a1.center) |- (res1.input);
           \draw (a1.center) -- (not1.input);

           \draw (b.east) -- (b1.center);
           \draw (b1.center) |- (res2.input);
           \draw (b1.center) -- (not2.input);

           \draw (en.east) -- (en1.center);

           \draw (not1.output) -- (x1.center);
           \draw (x1.center) |- (res1.output);
           \draw (x1.center) |- (x.west);

           \draw (not2.output) -- (z1.center);
           \draw (z1.center) |- (res2.output);
           \draw (z1.center) |- (z.west);

      \end{tikzpicture}}%
      \global\setbox\figB=\hbox{%
      \begin{tikzpicture}[circuit logic US, circuit ee IEC, huge circuit symbols, set resistor graphic = var resistor IEC graphic]
           \matrix[column sep=10mm, row sep=10mm,anchor=center]
           {
                \node [not gate] (not1) {}; \\
                \node [not gate] (not2) {}; \\
           };

           \node (a) at ([xshift=-25mm]not1.input) {$V_{in}^+$};
           \node [contact] (a1) at ([xshift=-10mm]not1.input) {};

           \node (b) at ([xshift=-25mm]not2.input) {$V_{in}^-$};
           \node [contact] (b1) at ([xshift=-10mm]not2.input) {};

           \node (x) at ([xshift=25mm]not1.output) {$V_{out}^-$};
           \node [contact] (x1) at ([xshift=10mm]not1.output) {};

           \node (z) at ([xshift=25mm]not2.output) {$V_{out}^+$};
           \node [contact] (z1) at ([xshift=10mm]not2.output) {};

           \node (en) at ([xshift=-30mm]$(not1.south)!0.5!(not2.north)$) {$EN$};
           \node [contact] (en1) at ($(not1.south)!0.5!(not2.north)$) {};

           \draw (en1.center) -- (not1.south) node[below right] (ennot1) {$E$};
           \draw (en1.center) -- (not2.north) node[above right] (ennot2) {$E$};

           \node [resistor={info'={$R$}}] (res1) at ([xshift=2mm, yshift=10mm]not1.north){};
           \node [resistor={info={$R$}}] (res2) at ([xshift=2mm, yshift=-10mm]not2.south){};

           \draw (a.east) -- (a1.center);
           \draw (a1.center) |- (res1.input);
           \draw (a1.center) -- (not1.input);

           \draw (b.east) -- (b1.center);
           \draw (b1.center) |- (res2.input);
           \draw (b1.center) -- (not2.input);

           \draw (en.east) -- (en1.center);

           \draw (not1.output) -- (x1.center);
           \draw (x1.center) |- (res1.output);
           \draw (x1.center) |- (x.west);

           \draw (not2.output) -- (z1.center);
           \draw (z1.center) |- (res2.output);
           \draw (z1.center) |- (z.west);

      \end{tikzpicture}}
 \endgroup

 \begin{figure}[htbp]
      \centering
      \usebox{\figA}      
      \caption{Some NOT gates with enable and resistors.}
 \end{figure}

 \begin{figure}[htbp]
      \centering
      \usebox{\figB}
      \caption{Some NOT gates with enable and resistors.}
 \end{figure}

 \begin{figure}[htbp]
      \begin{center}
           \begin{circuitikz}[scale=0.7, transform shape]
                \draw[thick,->] (0,0.5) --(1,0.5) node[anchor=south east] {$i(x,t)$};
                \node[] at (0,-1) {$v(x,t)$};
                \draw
                (0,0) node[anchor=east] {+}
                     to[short, o-] (1,0)
                     to[R=$Rx$] (3,0)
                     to[L=$Lx$] (5,0)
                (5,-2) to[R=$Gx$, *-*] (5,0)
                (5,0) to[short] (7,0)
                (7,-2) to[C=$Cx$, *-*] (7,0)
                (5,-2) to[short] (7,-2)
                (0,-2) node[anchor=east]{-}
                     to[short, o-] (5,-2)
                (9,0) node[anchor=west]{+}
                     to[short, o-] (7,0)
                (9,-2) node[anchor=west]{-}
                     to[short, o-] (7,-2)
                ;
                \draw[thick,->] (7,0.5) --(9,0.5) node[anchor=south east] {$i(x+ x,t)$};
                \node[] at (9,-1) {$v(x+ x,t)$};
           \end{circuitikz}
           \caption{Infinitesimal section of a transmission line.}
           \label{fig:transmission_line_section}
      \end{center}
 \end{figure}

 \end{document}

Связанный контент