How can I create a new component and include it in CircuiTikZ? For example a 4 bit adder?
[Tex/LaTex] CircuiTikZ — create new component
circuitikz
Related Solutions
The three anchors you are looking are <name>.in
, <name>.out 1
, and <name>.out 2
. A little example showing a spdt
component alone with its main three anchors, and another one showing how to connect some of these components with others; sorry if the examples lack any "real" meaning (I know nothing about circuits):
\documentclass{article}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz} \draw
(1,0) node[spdt] (myspdt) {}
(0,0) -- (myspdt.in)
(myspdt.out 1) -- +(1,0)
(myspdt.out 2) -- +(1,0);
\end{circuitikz}
\vspace{1cm}
\begin{circuitikz} \draw
(2,2) node[spdt] (myspdt1) {}
(2,0) node[spdt] (myspdt2) {}
(0,1) node[spdt] (myspdt3) {}
(5,1) node[and port] (myand) {}
(myspdt3.out 1) -| (myspdt1.in)
(myspdt3.out 2) -| (myspdt2.in)
(myspdt1.out 1) -- (myand.in 1)
(myspdt2.out 2) -- (myand.in 2)
;\end{circuitikz}
\end{document}
The file circuitikz1.code.tex
holds all style definition for the Zener diode zD
and its variant zD*
and zDo
as well as the long forms Zener diode
, empty Zener diode
and full Zener diode
.
(The zD
and Zener diode
styles switch dynamically to empty or full diodes depending on the styles/options empty diodes
/emptydiodes
or full diodes
/fulldiodes
respectively.)
These styles are copied to make a new
Zener diode family.
As we want to use this shape on paths we also need to define a set of path
s. These are simply copied from the old Zener diode family and are adjusted to match the new shapes.
The actual shape re-definition happens with the \pgfcircledeclarebipole
macro.
Again, these definitions are copied from the pgfcircbipoles.sty
file: The names are changed (I added an n
).
The first path is the path of the triangle, the second path is the path of the line thing in front of it.
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.8\pgf@circ@res@left}{\pgf@circ@res@down}}
Notice the additional .8
in the \pgfpathmoveto
line?
That’s it!
Code
\documentclass[tikz]{standalone}
\usepackage{circuitikz}
\makeatletter
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/diode/height}}{emptynzdiode}{\ctikzvalof{bipoles/diode/height}}{\ctikzvalof{bipoles/diode/width}}{
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
\pgfscope
\pgftransformxshift{\pgf@circ@res@left}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
\pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
\pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
\pgfusepath{draw}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.8\pgf@circ@res@left}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@up}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-1.2\pgf@circ@res@left}{\pgf@circ@res@up}}
\pgfusepath{draw}
\endpgfscope
}
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/diode/height}}{fullnzdiode}{\ctikzvalof{bipoles/diode/height}}{\ctikzvalof{bipoles/diode/width}}{
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
\pgfscope
\pgftransformxshift{\pgf@circ@res@left}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
\pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
\pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
\pgfusepath{draw,fill}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.8\pgf@circ@res@left}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@up}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-1.2\pgf@circ@res@left}{\pgf@circ@res@up}}
\pgfusepath{draw}
\endpgfscope
}
\tikzset{
nzD/.style={new Zener diode},
nzD*/.style={full new Zener diode},
nzDo/.style={empty new Zener diode},
new Zener diode/.style={\ifpgf@circuit@fulldiode full \else empty \fi new Zener diode},
full new Zener diode/.style={\circuitikzbasekey, /tikz/to path=\pgf@circ@fullnzdiode@path},
empty new Zener diode/.style={\circuitikzbasekey, /tikz/to path=\pgf@circ@emptynzdiode@path},
}
\def\pgf@circ@fullnzdiode@path#1{\pgf@circ@bipole@path{fullnzdiode}{#1}}
\def\pgf@circ@emptynzdiode@path#1{\pgf@circ@bipole@path{emptynzdiode}{#1}}
\makeatother
\begin{document}
\begin{circuitikz}
\foreach \diode[count=\x from 0] in {zD,
zD*,
zDo,
nzD,
nzD*,
nzDo} {
\draw[yshift=-\x cm] (0,0) to[\diode] (1,0) node[right] {\diode};
}
\end{circuitikz}
\end{document}
Best Answer
There is an easy way. Use an existing component as a base, such as
to[generic,color=white,n=myname]
and draw anything you want in the space.I have improved on my technique since then, as explained in the following tutorials.
http://www.elfsoft2000.com/projects/speaker.pdf
http://www.elfsoft2000.com/projects/multipole.pdf
http://www.elfsoft2000.com/projects/bipole.pdf