在 tikz 电路中对齐梯形

在 tikz 电路中对齐梯形

以下是我正在尝试执行的代码:

\documentclass[tikz]{standalone}
\usepackage{tikz}%to draw
\usetikzlibrary{arrows,shapes.gates.logic.US,shapes.gates.logic.IEC,calc,decorations.pathmorphing,backgrounds,fit,petri}
\usepackage{circuitikz}%para dibujos con pouertas logicas etc
\usepackage{pgfplots}%graficas en tikz
\usetikzlibrary{circuits.logic.US}

\usetikzlibrary{calc}
\usetikzlibrary{shapes.geometric}
\usepackage{rotating}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{positioning}
\pgfmathtruncatemacro\patitas{2}%distance for patitas de las puertas lógicas etc
\begin{document}

\begin{tikzpicture}[circuit logic US,
                tiny circuit symbols,
                every circuit symbol/.style={fill=white,draw, logic gate input sep=1mm},
node distance = 1cm,
]


\tikzset{font=\scriptsize}
%logic gate nodes

\node[and gate, draw, logic gate inputs=nn] at ($(1,0.5)$) (andpriman) {}; 
\node[and gate, draw, logic gate inputs=nn] [above of =andpriman] (andprima1) {};
\node[and gate, draw, logic gate inputs=nn] [node distance=1cm,above of =andprima1] (andn) {};
\node[and gate, draw, logic gate inputs=nn] [above of =andn] (and1) {}; 

\path ([yshift=-1mm]and1.south) -- (andn.north) node [black, font=\Large, midway, sloped] (vdots1) {$\dots$};    
\path ([yshift=-1mm]andprima1.south) -- (andpriman.north) node [black, font=\Large, midway, sloped] (vdots2) {$\dots$}; 

\node[or gate, draw, logic gate inputs=nn] [right of =vdots1] (orexcitatorias) {}; 
\node[nor gate, draw, logic gate inputs=nn] [right of =vdots2] (norinhibitorias) {}; 
\node at ($ (orexcitatorias) !.5! (norinhibitorias) $) (aux1) {}; 
\node[and gate, draw, logic gate inputs=nn] [right of =aux1]  (andgatherer) {};  

    \draw (andpriman.input 1) -- ++(left:\patitas mm) node[yshift=1mm, left=0mm] (xpriman) {$x'_{n'}$};
\draw (andpriman.input 2) -- ++(left:\patitas mm) node[yshift=-1mm, left=0mm] (wprimajn) {$i_{n'}$};
\draw (andprima1.input 1) -- ++(left:\patitas mm) node[yshift=1mm, left=0mm] (xpriman) {$x'_1$};
\draw (andprima1.input 2) -- ++(left:\patitas mm) node[yshift=-1mm, left=0mm] (wprimajn) {$i_1$};
\draw (andn.input 1) -- ++(left:\patitas mm) node[yshift=1mm, left=0mm] (xpriman) {$x_n$};
\draw (andn.input 2) -- ++(left:\patitas mm) node[yshift=-1mm, left=0mm] (wprimajn) {$e_n$};                \draw (and1.input 1) -- ++(left:\patitas mm) node[yshift=1mm, left=0mm] (xpriman) {$x_1$};
\draw (and1.input 2) -- ++(left:\patitas mm) node[yshift=-1mm, left=0mm] (wprimajn) {$e_1$};

\draw (and1.output) -- ++(right:\patitas mm) node [midway, right, blue] {$x_1 \cap e_1$} |- (orexcitatorias.input 1);
\draw (andn.output) -- ++(right:\patitas mm) node [midway, right, blue] {$x_n \cap e_n$} |- (orexcitatorias.input 2);
\draw (andprima1.output) -- ++(right:\patitas mm) node [midway, right, blue] {$x'_1 \cap i_1$} |- (norinhibitorias.input 1);
\draw (andpriman.output) -- ++(right:\patitas mm) node [midway, right, blue] {$x'_{n'} \cap i_{n'}$} |- (norinhibitorias.input 2);
\draw (orexcitatorias.output) -- ++(right:\patitas mm) node [midway, right, blue] {$\cup \left(x_i \cap e_i\right)$} |- (andgatherer.input 1);
\draw (norinhibitorias.output) -- ++(right:\patitas mm) node [midway, right, blue] {$\cup \left(x'_i \cap i_i\right)$} |- (andgatherer.input 2);



\node at ($ (orexcitatorias) !.5! (andgatherer)$) (aux2) {}; 
\node [trapezium, draw,minimum width=0.5cm,
trapezium left angle=65, trapezium right angle=65, rotate=270] [node distance=2cm,above of =aux2]  (addernode) {\small Adder}; 


\draw (andgatherer.output) -- ++(right:\patitas mm) node [midway,right,blue] {$E_n$} |- (addernode.south east);


\end{tikzpicture}

\end{document}

生成结果:

以下是该代码的输出

我想要的是将加法器梯形放置在使得连接与门的输出和加法器的线始终垂直的位置。

谢谢你!

答案1

你必须使用命令

\draw (andgatherer.output)
   -- ++(right:\patitas mm) node [midway,right,blue,below] {$E_n$}
   -- (andgatherer-|addernode.south);

addernode.south基线梯形的。由于梯形是旋转的,所以该点标志着梯形旋转后的左边界。(andgatherer-|addernode.south)表示从 开始的水平线andgatherer与从 开始的垂直线相交的点addernode.south。这正是从 开始的直线andgatherer应该结束的点。

这里有一个建议,如何使用来简化您的代码ciruitikz

在此处输入图片描述

\documentclass[border=2mm]{standalone}
\usepackage{circuitikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{circuitikz}
 \draw
    (0,6) node[and port] (and1) {}
    (0,4) node[and port] (and2) {}
    (0,2) node[and port] (and3) {}
    (0,0) node[and port] (and4) {}
    (3,5) node[or  port] (or1)  {}
    (3,1) node[nor port] (nor1) {}
    (5,3) node[and port] (and5) {}
    (6,3.5) node [trapezium, draw,minimum width=0.5cm,
                  trapezium left angle=65,trapezium right angle=65,
                  rotate=270,thick] (adder) {\small adder}
    (and1.out) node[right]{$x_1\cap e_1$}              |- (or1.in 1)
    (and2.out) node[right]{$x_n\cap e_n$}              |- (or1.in 2)
    (and3.out) node[right]{$x'_1\cap i_1$}             |- (nor1.in 1)
    (and4.out) node[right]{$x'_{n'}\cap i_{n'}$}       |- (nor1.in 2)
    (or1.out)  node[right]{$\bigcup_i (x_i\cap e_i)$}  |- (and5.in 1)
    (nor1.out) node[right]{$\bigcup_i (x'_i\cap i_i)$} |- (and5.in 2)
    (and5.out) node[below]{$E_n$}                      -- (and5.out-|adder.south)
    (adder.north) to [short,-o] +(0.5,0)
    \foreach \p/\l in
      {and1.in 1/{x_1},and1.in 2/e_1,
       and2.in 1/x_n,and2.in 2/e_n,
       and3.in 1/x'_1,and3.in 2/i_1,
       and4.in 1/x'_{n'},and4.in 2/i_{n'}%
      } 
      {([xshift=-0.5cm]\p) node[left]{$\l$} to [short,o-]  (\p)}
    ;
  \draw[loosely dotted,very thick]
    (-0.5,4.6) -- (-0.5,5.4)
    (-0.5,0.6) -- (-0.5,1.4)
    ;
\end{circuitikz}
\end{document}

相关内容