# Add additional anchor to existing TikZ shape and modify existing anchor

I have the following code, which should give me a NAND gate:

\tikzset{
block rect/.style =
{
draw = \linecolor,
fill = \blockcolor,
rectangle,
minimum height = 1.6\blocksize,
minimum width = \blocksize,
anchor = center,
inner sep = 0.05\blocksize,
font = \blockfontsize
},
nand gate/.style =
{
draw,
block rect,
yshift = -0.33\blocksize,
append after command =
{
\pgfextra
{%
\node [draw, circle, minimum size = 1mm, inner sep=0pt] at ([xshift=0.5mm]\tikzlastnode.east) {};
}
},
path picture =
{
\node at ([yshift=0.33\blocksize]path picture bounding box.center) {\small \&};
}
}}


it actually works and gives me a nice (european style :-) ) NAND gate:

however, when I would like to use the NAND gate's output with (node name.east), the actal east anchor is the east anchor of the rectangle, but I want to shift the east anchor to the right by the diameter of the small circle. Otherwise, any connections from the right side of the NAND go through that small circle, which is wrong and looks ugly.

Second, I would like to add two additional anchors 'in1' and 'in2' or 'a' and 'b' on the left side of the NAND for the two input ports, so that I could connect lines to the NAND's inputs. The two anchors should be at +/-0.33 the height of the rectangle. How can I define these two new anchors for my gate?

• Welcome to TeX.SE! Do you look into circuitikz package? Or circuit library of TikZ? There IEC NAND gate symbols are already defined (with two inputs only (unfortunately) May 18, 2016 at 20:09
• @Zarko With circuit you can use the logical gate inputs or the input key (the latter is a short-cut for the former) to define more than two inputs, even so far to define different inputs (normal ones and inverted ones). May 18, 2016 at 20:25
• @Qrrbrbirlbel, thank you for info. Good to know. Actualy I mostly use circuitikz, where I didn't saw this option. I will look in TikZ manual again :-) May 18, 2016 at 20:41

A little example with circuits TikZlibrary.

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{circuits.logic.IEC}

\begin{document}
\begin{tikzpicture}[circuit logic IEC, huge circuit symbols]
\matrix[column sep=10mm]
{
\node [nand gate] (nand) {}; &  & \\
& \node [nor gate, inputs=nni] (nor) {}; &
\node [or gate, inputs=nnn] (out) {}; \\
};

\node (c) at ([xshift=-10mm]nand.west|-nor.input 2) {C};
\draw (nor.input 2) -- (c);
\draw (nand.input 2) -- (nand.input 2-|c.east) node[left] (b) {B};
\draw (nand.input 1) -- (nand.input 1-|c.east) node[left] (a) {A};
\draw (nor.input 3) -- coordinate (Daux) (nor.input 3 -|c.east) node[left] (d) {D};

\draw (out.input 3) -| ([shift={(-5mm,-5mm)}]out.input 3) -| (Daux);
\draw (out.input 1) --++(180:5mm) |- (nand.output);
\draw (nor.input 1) --++(180:5mm) |- (nand.output);
\draw (nor.output) -- ++(right:5mm)   |- (out.input 2);
\draw (out.output) -- ++(right:10mm);
\end{tikzpicture}
\end{document}


• Thank you for your example. I did know the circuit library, the stuff with the NAND gate was just an example. I have made some other special symbols which are not availabe in the circuit library and for these I need to add some specialised anchors. That's why I cannot use circuit library. May 20, 2016 at 8:14