如何在 tikz 中将 XOR 门符号绘制为节点?

如何在 tikz 中将 XOR 门符号绘制为节点?

我想要绘制如下的图:在此处输入图片描述

这是我的 tikz 代码

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,fit,calc,positioning,automata}

\begin{document}


\tikzstyle{int}=[draw, minimum size=4em]
\tikzstyle{init} = [pin edge={to-,thin,black}]

\begin{tikzpicture}[node distance=5cm,auto,>=latex', scale = 0.75, transform shape]
    \tikzstyle{line} = [draw, -latex']
    \node [int] (a) { $x^2$ };
   \node [int] (b) [right of=a] { $x^1$ };
    \node [int] (c) [right of=b] { $x^0$ };
    % \coordinate[right=1.75cm of a] (a1)  {};

    \path[->] (b) edge node { } (a);

\end{tikzpicture}

\end{document}

输出为:

在此处输入图片描述

我如何在 tikz 中制作那些 XOR 符号?

答案1

代码

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,fit,calc,positioning,automata}
\begin{document}

\tikzstyle{int}     = [draw, minimum size=4em]
\tikzstyle{init}    = [pin edge={to-,thin,black}]
\tikzstyle{XORgate} = [draw,circle]
\tikzstyle{line}    = [draw, -latex']

%\pgfkeyssetvalue{/tikz/node distance}{4cm}           % needs next line to work
%\pgfkeysgetvalue{/tikz/node distance}{\nodedistance} % but than I can just say \def…
\newcommand*\nodedistance{4cm}
\begin{tikzpicture}[node distance=\nodedistance,auto,>=latex', scale = 0.75, transform shape]
    \tikzstyle{line}=[draw, -latex']
    \node [int] (a) { $x^2$ };
    \node [int,right of=a] (b) { $x^1$ };
    \node [int,right of=b] (c) { $x^0$ };
    \node [XORgate] at ($(b)!.5!(c)$) (XOR-b-c) {\large +};
    \node [XORgate] at ($(b)!1.5!(a)$) (XOR-aa) {\large +};
    \coordinate [below of=XOR-aa,node distance=.5*\nodedistance] (below-XOR-aa);
    \node [above of=XOR-aa,node distance=1.5cm,text width=1.5cm,anchor=south,align=center] (input) {Message\\Input};
    \path[line] (c) edge (XOR-b-c)
                (XOR-b-c) edge (b)
                (b) edge (a)
                (a) edge (XOR-aa)
                (XOR-aa) -- (below-XOR-aa) -| ($(c) + (.5*\nodedistance,0pt)$) -- (c)
                (input) edge (XOR-aa)
                ($(XOR-b-c)+(0,-.5*\nodedistance)$) -- (XOR-b-c);
\end{tikzpicture}
\end{document}

输出

输出

相关内容