# Saturation block

I have an issue with the answer given in this question.

As suggested in the comments to its answer, I modified the solution as follows:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{calc,positioning}

\newcounter{image}
\setcounter{image}{0}

\tikzstyle{square} = [draw, rectangle, draw=black, minimum width=1cm, minimum height=1cm, text centered]

\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)$);
}
}

\tikzset{record/.style args={#1 and #2}{
rectangle,draw,minimum width=#1, minimum height=#2
}
}

\newcommand{\drawrecord}[1]
{
\stepcounter{image}
{
\node [record=1 cm and 1 cm, name=a\theimage] at {#1};
}
\node[drawinside={a\theimage}]{};
}

\begin{document}
\begin{tikzpicture}

\drawrecord{0,0};

\node (sq) [square] {};
\drawrecord{sq};

\end{tikzpicture}
\end{document}


but I keep receiving a ! Package tikz Error: Cannot parse this coordinate. error when I call \drawrecord

. how may I solve this issue?

. Is there a way to define \drawrecord as a \tikzstyle instead of a new command?

EDIT:

for the second question, I have been suggested to look into "append after command", but I cannot find documentation about it, anyone has a link?

EDIT2: actually, the second question is kind of redundant, I can simply call

\node [record=1 cm and 1 cm, name=newnode, right of=oldnode];
\node[drawinside={newnode}]{};


in my document. And

\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.5!(#1.center)$)--($(#1.north east)!0.4!(#1.east)!0.3!(#1.center)$);
}
}


is symmetrical (the previous one is slightly off)

If your intention is to define a newshape, instead of using Claudio's answer, use Percusse's one.

Next code slightly modifies satnode shape defined by Percusse. I've changed its name to record and some dimensions to look more like your example.

You can use

\node[record,minimum size=1cm,fill=blue!30,draw] (a) {};


to place a record where you want, fix it's size, color, ... and also use its anchors for later use.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}

\usetikzlibrary{positioning}

\makeatletter

\pgfdeclareshape{record}{
\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.33\pgf@ya}}
\pgfpathlineto{\pgfpoint{0}{-0.33\pgf@ya}}
\pgfpathmoveto{\pgfpoint{0.33\pgf@xa}{0}}
\pgfpathlineto{\pgfpoint{-0.33\pgf@xa}{0}}
}
}
\makeatother

\begin{document}
\begin{tikzpicture}

\node[record,minimum size=1cm,fill=blue!30,draw] (a) {};
\node[record,draw,fill=red!30,minimum height=12mm, minimum width=6mm] (a2) at (-1,1.5) {};
\node[record,thick,draw=purple!30,minimum height=1cm,minimum width=1.5 cm,fill=yellow!10, above right=.5cm and .4cm of a] (a1){};
\draw[-latex] (a2) -| (a);
\draw[-latex] (a) -| (a1);
\end{tikzpicture}
\end{document}


Another way of doing things, this time with the path picture:

\documentclass[tikz,border=5]{standalone}
\tikzset{%
saturation block/.style={%
draw,
path picture={
% Get the width and height of the path picture node
\pgfpointdiff{\pgfpointanchor{path picture bounding box}{north east}}%
{\pgfpointanchor{path picture bounding box}{south west}}
\pgfgetlastxy\x\y
% Scale the x and y vectors so that the range
% -1 to 1 is slightly shorter than the size of the node
\tikzset{x=\x*.4, y=\y*.4}
%
% Draw annotation
\draw (-1,0) -- (1,0) (0,-1) -- (0,1);
\draw (-1,-.7) -- (-.7,-.7) -- (.7,.7) -- (1,.7);
}
}
}

\begin{document}
\begin{tikzpicture}
\node [saturation block, minimum size=0.5cm] at (0,0) {};
\node [saturation block, minimum size=1cm] at (0,1) {};
\node [saturation block, minimum width=2cm, minimum height=1cm] at (0,2.25) {};
\end{tikzpicture}
\end{document}


• That's a great answer, is it possible to set a default minimum size in the macro? – Marko Buršič May 23 '16 at 10:00
• You can add the properties minimum width = x mm, minimum height = x mm, inside saturation block/.style={ ... } – Taekwondavide Mar 26 '19 at 15:01

You have a syntax problem here:

\node [record=1 cm and 1 cm, name=a\theimage] at {#1};


at expects a coordinate, so you need

\node [record=1 cm and 1 cm, name=a\theimage] at (#1) {};


The code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{calc,positioning}

\newcounter{image}
\setcounter{image}{0}

\tikzset{
square/.style={
rectangle,
draw=black,
minimum width=1cm,
minimum height=1cm,
text centered
},
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)$);
},
record/.style args={#1 and #2}{
rectangle,draw,minimum width=#1, minimum height=#2
}
}

\newcommand{\drawrecord}[1]{%
\stepcounter{image}%
\node [record=1 cm and 1 cm, name=a\theimage] at (#1) {};
\node[drawinside={a\theimage}]{};%
}

\begin{document}

\begin{tikzpicture}
\drawrecord{0,0};
\node (sq) [square] {};
\drawrecord{sq}
\end{tikzpicture}

\end{document}


• thank you! :) any idea about the second part of the question? – Federico Feb 18 '14 at 14:40
• @Federico I am not sure about your second question. What should the style do? – Gonzalo Medina Feb 18 '14 at 14:45
• the same as drawrecord, but as a style and not a command, so to be able to write \node[drawrecord, left of =oldnode]{} instead of \node(new)[left of=oldnode]{};\drawrecord{new}; The arrows from/to the block would also look better. – Federico Feb 18 '14 at 14:49
• @Federico If I understand correctly, I am afraid what you are after is a new shape, not just a style. This, of course, can be done, but it is rather a long process. Perhaps someone else will help you with that. – Gonzalo Medina Feb 18 '14 at 14:54