3

Is it possible to draw custom logic gates like the following one using circuitikz?

this

Alternatively, is it possible to draw them easily with the circuits.logic library in tikz?

3
  • 1
    Is it a one-off or do you plan to use it a lot? For a one-off, you could just draw it using tikz (circuitikz is built on top of tikz). Jun 2, 2015 at 13:05
  • @JohnKormylo I might not use this particular one often, but I need to use other designs, like flip flops, quite often.
    – Aakash Jog
    Jun 2, 2015 at 14:05
  • You can find a flip-flop shape in TeXample.net
    – Ignasi
    Jun 2, 2015 at 14:38

2 Answers 2

5

Here you have a possible solution. It uses a trapezium shape as reference to draw the ALU.

\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, positioning, calc}

\begin{document}
\begin{tikzpicture}[%
    alu/.style={trapezium,
            trapezium angle=30,
            shape border rotate=180,
            minimum width=4cm,
            minimum height=3cm,
            trapezium stretches=true,
            append after command={%
                    \pgfextra
                        \draw (\tikzlastnode.top left corner) --
                           (\tikzlastnode.top right corner) -- 
                           (\tikzlastnode.bottom right corner) -- 
                           ($(\tikzlastnode.bottom right corner)!.666!(\tikzlastnode.bottom side)$)--
                           ([yshift=-8mm]\tikzlastnode.bottom side)--
                           ($(\tikzlastnode.bottom side)!.334!(\tikzlastnode.bottom left corner)$)--
                           (\tikzlastnode.bottom left corner)--
                           (\tikzlastnode.top left corner);
                    \endpgfextra}},
            ]

\node[alu] (alu) {ADDER($n$)};
\draw (alu.south) -- ++(-90:5mm) node [below] (out) {$S[n-1:0]$};
\draw (alu.20) -- ++(0:5mm) node [right] {$C[0]$};
\draw (alu.50) -- ++(90:5mm) node [above] {$B[n-1:0]$};
\draw (alu.130) -- ++(90:5mm) node [above] {$A[n-1:0]$};
\draw (alu.130) -- ++(90:5mm) node [above] {$A[n-1:0]$};
\node[left=8mm of out] (carry) {$C[n]$};
\draw (carry) |- (alu.200);
\end{tikzpicture}
\end{document}

enter image description here

1

Here is a shorter solution written in circuitikz using new features that weren't available in 2015:

\begin{circuitikz}
\node [muxdemux,
  muxdemux def={NL=2, NR=1, NB=1, w=2,
    inset w=1, inset Lh=2, inset Rh=0,
    square pins=1, Lh=6, Rh=3}, rotate=-90](A) at (0,0) 
    {\rotatebox{90}{\small \ttfamily Adder(N)}};
\node[left] at (A.bpin 1) {$C[n]$};
\node[above] at (A.lpin 1) {$B[n - 1: 0]$};
\node[above] at (A.lpin 2) {$A[n - 1: 0]$};
\node[below] at (A.rpin 1) {$S[n - 1: 0]$};
\end{circuitikz}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .