I'm working on a block diagram using TikZ. I'd like to create a symbol like below, which means I have to draw 5 lines inside a node and write a letter in the upper-right corner.
What's the best way to achieve what I need? Any hints appreciated.
I'm working on a block diagram using TikZ. I'd like to create a symbol like below, which means I have to draw 5 lines inside a node and write a letter in the upper-right corner.
What's the best way to achieve what I need? Any hints appreciated.
Here is a possible implementation (based on Automat within Record). Is this what you had in mind?
\documentclass{article}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\newcounter{image}
\setcounter{image}{0}
\pgfmathtruncatemacro{\recordwidth}{2}
\pgfmathtruncatemacro{\recordheight}{1}
\newcommand{\setrecordwidth}[1]{\pgfmathtruncatemacro{\recordwidth}{#1}}
\newcommand{\setrecordheight}[1]{\pgfmathtruncatemacro{\recordheight}{#1}}
\newcommand{\mylabel}{M}
\newcommand{\setlabel}[1]{\renewcommand{\mylabel}{#1}}
\newcommand{\labelfont}{\scriptsize}
\newcommand{\setlabelfont}[1]{\renewcommand{\labelfont}{#1}}
\tikzset{drawinside/.code args={#1}{%
\draw($(#1.west)!0.3!(#1.center)$)--($(#1.east)!0.3!(#1.center)$);
\draw($(#1.south)!0.3!(#1.center)$)--($(#1.north)!0.3!(#1.center)$);
\draw($(#1.south west)!0.4!(#1.west)!0.3!(#1.center)$)--($(#1.south west)!0.165!(#1.west)!0.5!(#1.center)$)--(#1.center);
\draw(#1.center)--($(#1.north east)!0.165!(#1.east)!0.65!(#1.center)$)--($(#1.north east)!0.45!(#1.east)!0.45!(#1.center)$) node[right,font=\labelfont]{$\mylabel$};
}
}
\tikzset{record/.style args={#1 and #2}{
rectangle,draw,minimum width=#1, minimum height=#2
}
}
\NewDocumentCommand{\drawrecord}{d()}{
\stepcounter{image}
\IfNoValueTF{#1}{%true
\node[record=\recordwidth cm and \recordheight cm,name=a\theimage]{};
}
{%false
\node[record=\recordwidth cm and \recordheight cm,name=a\theimage]at(#1){};
}
\node[drawinside={a\theimage}]{};
}
\begin{document}
\tikz{\drawrecord}
\tikz{\drawrecord}
\vspace*{2cm}
\begin{tikzpicture}
\drawrecord(0,0)
\setlabel{X}
\setlabelfont{\normalfont}
\setrecordwidth{6}
\setrecordheight{3}
\drawrecord(6,0) % that's the 4° picture, so it can be accessed by (a4)
\draw[-stealth]($(a4.west)+(-1,0)$)--(a4.west);
\draw[-stealth](a4.east)--($(a4.east)+(1,0)$);
\end{tikzpicture}
\end{document}
It allows you to customize the dimensions of the block and the labels. Moreover, as did for the last block, you can connect this with the rest of the picture by means of (anumber of the picture
).
Complementing Claudio's answer: You can also inherit the properties of a rectangle node shape and further add some drawings on top of it and use it as a genuine node shape.
\documentclass{standalone}
\usepackage{tikz}
\makeatletter
\pgfdeclareshape{satnode}{
\inheritsavedanchors[from={rectangle}]
\inheritbackgroundpath[from={rectangle}]
\inheritanchorborder[from={rectangle}]
\foreach \x in {center,north east,north west,north,south,south east,south west}{
\inheritanchor[from={rectangle}]{\x}
}
\foregroundpath{
\pgfpointdiff{\northeast}{\southwest}
\pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast
\pgfpathmoveto{\pgfpoint{0}{0.45\pgf@ya}}
\pgfpathlineto{\pgfpoint{0}{-0.45\pgf@ya}}
\pgfpathmoveto{\pgfpoint{0.45\pgf@xa}{0}}
\pgfpathlineto{\pgfpoint{-0.45\pgf@xa}{0}}
\pgfpathmoveto{\pgfpointadd{\southwest}{\pgfpoint{-0.2\pgf@xa}{-0.3\pgf@ya}}}
\pgfpathlineto{\pgfpointadd{\southwest}{\pgfpoint{-0.5\pgf@xa}{-0.3\pgf@ya}}}
\pgfpathlineto{\pgfpointadd{\northeast}{\pgfpoint{-0.5\pgf@xa}{-0.3\pgf@ya}}}
\pgfpathlineto{\pgfpointadd{\northeast}{\pgfpoint{-0.4\pgf@xa}{-0.3\pgf@ya}}}
{
\pgftransformshift{\pgfpointadd{\northeast}{\pgfpoint{-0.4\pgf@xa}{-0.3\pgf@ya}}}
\pgftransformscale{0.5}
\pgfsetcolor{black}
\pgftext[left]{$M$}
}
\pgfusepath{stroke}
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node[satnode,minimum size=1cm,fill=blue,draw] (a) {};
\node[satnode,draw,fill=red,minimum height=2cm,minimum width=1 cm] (a2) at (-2,0) {};
\node[satnode,thick,draw,minimum height=1cm,minimum width=1.5 cm,fill=yellow] (a1) at (2,0) {};
\draw[-latex] (a2) -- (a) -- (a1);
\end{tikzpicture}
\end{document}