I'd like to draw a user defined a simple node shape in combination with the circuit library. The node has one input and one output. I'd like to put text inside the node shape near the input and output.
I couldn't find an example in the TikZ manual that describes how to put text inside the node shapes (except for the info label).
There are two problems.
The circuit library fills the node and this overwrites the text. I managed to turn that off with a style. I'm not sure if this is the best thing to do.
I can't figure out how to position the text. It always ends up in the centre of the node shape.
The following is what I've got:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{circuits.logic.CDH}
\tikzset{circuit logic CDH}
\usetikzlibrary{shapes.misc}
\makeatletter
\pgfdeclareshape{myshapeshape} {
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{north west}
\inheritanchor[from=rectangle]{north east}
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{east}
\inheritanchor[from=rectangle]{mid}
\inheritanchor[from=rectangle]{mid west}
\inheritanchor[from=rectangle]{mid east}
\inheritanchor[from=rectangle]{base}
\inheritanchor[from=rectangle]{base west}
\inheritanchor[from=rectangle]{base east}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{south west}
\inheritanchor[from=rectangle]{south east}
\inheritbackgroundpath[from=rectangle]
\anchor{1}{
\pgf@process{\northeast}%
\pgf@xa=\pgf@x%
\pgf@process{\southwest}%
\advance\pgf@x by \pgf@xa%
\pgf@x=0.5\pgf@x%
}
\anchor{2}{
\pgf@process{\southwest}%
\pgf@xa=\pgf@x%
\pgf@process{\northeast}%
\advance\pgf@x by \pgf@xa%
\pgf@x=0.5\pgf@x%
}
% attempt to put in text.
\beforebackgroundpath{%
\pgf@process{\northeast}%
\pgf@xa=\pgf@x%
\pgf@process{\southwest}%
\advance\pgf@x by \pgf@xa%
\pgf@x=0.5\pgf@x%
\pgftext{\textsc{1}}
}%
}
\tikzset{circuit declare symbol=myshapeg,
set myshapeg graphic={draw,
fill=none,
shape=myshapeshape,%
minimum width=10mm,
minimum height=20mm}}
\tikzset{myshape/.style={myshapeg,info=center:{#1}},
myshape/.default={null}}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw (0,0) node(inout)[myshape=text] {}
(inout.1) -- + (0,-1)
(inout.2) -- + (0,1)
;
\end{tikzpicture}
\end{document}
Any help much appreciated.
IEC
sub-library?) and add the text withappend after command
(i.e. labels on the inside). (This surely can also done on a lower level with PGF.) Why are using arectangle
definition? Thecircuits
library stuff already offers anchors like.input
and.output
…\pgftext[bottom,at={\pgfpoint{\pgf@x}{\pgf@y}}]{\textsc{1}}