4

The following figure stands for a saturation block in a block diagram:

enter image description here

The idea is to use this figure as a node at different positions in drawings and place it relatively to other nodes. Consider the following mwe:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,circuits.ee.IEC,positioning,shapes.arrows}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tikzpicture}[%
,auto
,>=latex'
,block/.style={text height=1.5ex,text depth=.25ex, align=center, draw,
               fill=black!10, rectangle, minimum height=10mm, minimum width=10mm}
,input/.style={coordinate}
,output/.style={coordinate}
]
    \def\saturationBlock#1#2{\node [block] (#1) [#2] {};
        \begin{scope}[scale=0.4,shift={(3.75,0)}]
            \draw[thick]    (  -1,   0) -- (   1,   0);
            \draw[thick]    (   0,  -1) -- (   0,   1);
            \draw[thick]    (  -1,-0.9) -- (-0.5,-0.9)  -- ( 0.5, 0.9) -- (   1, 0.9);
        \end{scope}
    }
    \draw node [input]          (input)                                 {};
    \saturationBlock{saturation}{right = of input};
    \draw node [output]         (output)    [right = of saturation]     {};
    \path
    (input)                     edge[->]    (saturation)
    (saturation)                edge[->]    (output)
    ;
\end{tikzpicture}
\end{document}

leading to the result:

enter image description here

If the shift command (shift={(3.75,0)}) is omitted, the figure looks like this:

enter image description here

Obviously the drawing of the saturation sign is not referred to the location of the node (\saturationBlock). What is the proper proceeding to place the drawing at the origin of the corresponding node?

1

2 Answers 2

4

Although I think that percusse's satnode is a better solution, here you have an alternative saturation style which already draws the whole block with a path picture command. Something similar could be done with a pic but node placement is easier.

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

\begin{document}
\begin{tikzpicture}[
    shorten <>/.style={shorten >=1mm, shorten <=1mm},
    saturation/.style={
        minimum size=10mm, 
        draw,
        fill=black!10,
        path picture={
            \draw[thick,shorten <>] (path picture bounding box.west)
                                  --(path picture bounding box.east);
            \draw[thick,shorten <>] (path picture bounding box.south)
                                  --(path picture bounding box.north);
            \draw[thick] ([shift=(45:2mm)]path picture bounding box.south west) 
                           --++(0:2mm)--(path picture bounding box.center);
            \draw[thick] ([shift=(225:2mm)]path picture bounding box.north east) 
                           --++(180:2mm)--(path picture bounding box.center);
        },
    }]

    \node[saturation] (a) {};
    \draw[<-] (a.west)--++(180:1cm);
    \draw[->] (a.east)--++(0:1cm);
\end{tikzpicture}
\end{document}

enter image description here

1
  • another really nice solution indeed. even more elegant for the type of drawings i fulfill. Mar 18, 2016 at 7:10
3

It seems that you have problem with defining coordinates for your saturationBlock. Lines inside it should be tied with it, not have absolute coordinate. See, if the following solution work for you:

\documentclass[tikz,
               border=3mm,
               preview]{standalone}
\usetikzlibrary{calc,circuits.ee.IEC,positioning,shapes.arrows}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \begin{document}
\begin{tikzpicture}[%
,auto
,>=latex'
,shorten <>/.style = {shorten >=1mm,shorten <=1mm}% <--- new
,block/.style={text height=1.5ex,text depth=.25ex, align=center, draw,
               fill=black!10, rectangle, minimum height=10mm, minimum width=10mm}
,input/.style={coordinate}
,output/.style={coordinate}
                    ]
\def\saturationBlock#1#2{\node[block] (#1) [#2] {};
    \draw[thick,shorten <>]    (#1.west)  -- (#1.east) ;% <--- modified 
    \draw[thick,shorten <>]    (#1.north) -- (#1.south);% <--- modified
    \coordinate[above right=2mm of #1.south west] (#1sw);% <--- new
    \coordinate[below left =2mm of #1.north east] (#1ne);% <--- new
    \draw[thick]    (#1sw) -- + (+0.2,0)  -- (#1.center) % <--- modified
                    (#1ne) -- + (-0.2,0)  -- (#1.center);% <--- modified
                        }
\draw node [input]          (input)                                 {};
\saturationBlock{saturation}{right = of input};
\draw node [output]         (output)    [right = of saturation]     {};
\path[->]   (input) edge (saturation)
            (saturation) edge (output);
\end{tikzpicture}
\end{document}

Probably more elegant solution you obtain with small pictures \pic, which is designed for similar small figures.

enter image description here

1
  • exactly, what I was looking for! Mar 17, 2016 at 14:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .