对齐节点中的符号 Circuitikz

对齐节点中的符号 Circuitikz

我有一个小问题,无法用 Circuitikz 解决。我想更改所有节点的布局。我希望它们看起来像这样:

circuitikz 标签

过了一会儿,我设法用 ctikzset 改变了点和门的比例。我的代码如下:

\documentclass[tikz,border=2mm]{standalone}
\usepackage[european]{circuitikz}
\ctikzset{tripoles/european not symbol=ieee circle,
tripoles/european nand port/height=1.1}

\begin{document}
    \begin{circuitikz} 
                \draw node[nand port,align=left](){};
    \end{circuitikz}
\end{document}

此代码为我提供了以下门:

我的代码 nand

现在我的两个问题是:

  1. 我怎样才能将“&”符号移动到大门旁边?
  2. 是否有选项可以同时更改所有端口的高度?(此刻我输入:
    tripoles/european and port/height=1.1,
    tripoles/european nand port/height=1.1,
    tripoles/european or port/height=1.1,
    tripoles/european nor port/height=1.1,
    tripoles/european not port/height=1.1,
    

先感谢您!

答案1

您可以用不同的文本定义修补端口的定义european,然后重新发布声明。您需要重新声明所有的高度,是的 --- 这是 circuitikz 的历史遗留问题,我想改变它(使用默认的每个类和可能的覆盖),但这是一个相当长的事情,而且容易出错...

要改变一切,你可以这样做:

\documentclass[border=2mm]{standalone}
\usepackage[european, RPvoltages]{circuitikz}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\pgfcircdeclareeurologicport}%
{%
\pgftext{#2}
}{%
\pgftext[y=\pgf@circ@res@up-4pt, top]{#2}
}{\typeout{Patching OK}}{\typeout{Patching failed}}
% fast change-all macro
\ctikzset{european ports height/.style={%
    % height change
    tripoles/european and port/height=#1,
    tripoles/european or port/height=#1,
    tripoles/european xor port/height=#1,
    tripoles/european not port/height=#1,
    tripoles/european buffer port/height=#1,
    tripoles/european nand port/height=#1,
    tripoles/european xor port/height=#1,
    tripoles/european xnor port/height=#1
}}
% redefine the ports
\pgfcircdeclareeurologicport{and}{\&}{\pgf@circ@res@count}{}
\pgfcircdeclareeurologicport{or}{$\ge 1$}{\pgf@circ@res@count}{}
\pgfcircdeclareeurologicport{xor}{$=1$}{\pgf@circ@res@count}{}
\pgfcircdeclareeurologicport{not}{$1$}{1}{not}
\pgfcircdeclareeurologicport{buffer}{$1$}{1}{}
\pgfcircdeclareeurologicport{nand}{\&}{\pgf@circ@res@count}{not}
\pgfcircdeclareeurologicport{nor}{$\ge 1$}{\pgf@circ@res@count}{not}
\pgfcircdeclareeurologicport{xnor}{$=1$}{\pgf@circ@res@count}{not}
\makeatother
\ctikzset{%
    logic ports origin=center,
    european ports height=1.1,
    tripoles/european not symbol=ieee circle,
}
\begin{document}
    \begin{circuitikz}
        \draw (0,0) node[nand port,align=left](){};
        \draw (2,0) node[nand port,align=left, rotate=90](){};
    \end{circuitikz}
\end{document}

在此处输入图片描述

但请注意,欧洲种类不被认为是垂直使用的,因为符号才不是旋转。如果需要,也可以调整;如果您将 patch 命令更改为:

\patchcmd{\pgfcircdeclareeurologicport}%
{%
\pgftext{#2}
}{%
\pgfgettransformentries\a\b\temp\temp\temp\temp
\pgfmathsetmacro{\rot}{-atan2(\b,\a)}
\pgftext[y=\pgf@circ@res@up-8pt, rotate=\rot]{#2}
}{\typeout{Patching OK}}{\typeout{Patching failed}}

并要求身体:

 \draw (0,0) node[nand port,align=left](){};
 \draw (2,0) node[nand port,align=left, rotate=90](){};
 \draw (4,0) node[nand port,align=left, rotate=-90](){};
 \draw (6,0) node[nand port,align=left, rotate=45](){};

你将拥有:

在此处输入图片描述

这不是最佳的,因为您必须8pt根据字体大小手动调整,但它有效......

答案2

这是一个可能的答案。(免责声明:这是猜测。)如果你增加2.5em“&”符号,它将会升高得更多。

\documentclass[border=2mm]{standalone}
\usepackage[european]{circuitikz}
\ctikzset{tripoles/european not symbol=ieee circle,
tripoles/european nand port/height=1.1}
\makeatletter
\ctikzset{tripoles/port height/.code={\ctikzset{tripoles/european and port/height=#1,
tripoles/european nand port/height=#1,
tripoles/european or port/height=#1,
tripoles/european nor port/height=#1,
tripoles/european not port/height=#1}}}
\pgfcircdeclareeurologicport{nand}{\raisebox{2.5em}{\&}}{\pgf@circ@res@count}{not}
\makeatother
\begin{document}
    \begin{circuitikz}[circuitikz/tripoles/port height=0.9] 
                \draw node[nand port,align=left](){};
    \end{circuitikz}
\end{document}

在此处输入图片描述

另一个不需要猜测参数的选​​择\raisebox是使用append after command密钥并让 TiZ 放置“&”符号。

\documentclass[border=2mm]{standalone}
\usepackage[european]{circuitikz}
\ctikzset{tripoles/european not symbol=ieee circle,
tripoles/european nand port/height=1.1}
\makeatletter
\ctikzset{tripoles/port height/.code={\ctikzset{tripoles/european and port/height=#1,
tripoles/european nand port/height=#1,
tripoles/european or port/height=#1,
tripoles/european nor port/height=#1,
tripoles/european not port/height=#1}}}
\tikzset{nand port/.append style={append after command={
(\tikzlastnode.north) node[below]{\&}}}}
\pgfcircdeclareeurologicport{nand}{}{\pgf@circ@res@count}{not}
\makeatother
\begin{document}
    \begin{circuitikz}[circuitikz/tripoles/port height=0.9] 
                \draw node[nand port,align=left](){};
    \end{circuitikz}
\end{document}

答案3

只是为了好玩:

\documentclass[tikz,border=2mm]{standalone}
\usepackage[european]{circuitikz}
\ctikzset{tripoles/european not symbol=ieee circle,
tripoles/european nand port/height=1.1}

\makeatletter
\pgfcircdeclareeurologicport{nand}{}{\pgf@circ@res@count}{not}% remove & symbol at \pgfpointorigin
\makeatother

\begin{document}
    \begin{circuitikz} 
      \draw node[nand port,align=left](nand1){}
        (nand1.north) node[below] {\&};% add & symbol
    \end{circuitikz}
\end{document}

相关内容