6

Following is the code that was posted for my question How to show path gains in block diagrams drawn in tikz environment?

It is giving me the desired output. But my problem is that I don't understand the set of statements in the preamble. I want to understand how each of them is used so that I can define my own tikzset for my future works. Can someone help me in understanding these. I will be grateful.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows, decorations.markings, positioning}
    \newcommand\ppbb{path picture bounding box}
\tikzset{
shorten <>/.style = {shorten >=#1, shorten <=#1},
  dot/.style = {circle, fill=black,
                inner sep=0mm, outer sep=0mm, minimum size=1mm,
                node contents={}},
 gain/.style = {decoration={markings, mark= at position 0.5
                           with {\arrow[ultra thick]{stealth};
                                 \node[above] {#1};}
                            },
                postaction={decorate}},
  sum/.style = {circle, draw=black, fill=white, minimum size=6mm,
               path picture={\draw[very thick,shorten <>=1mm,-]
               (\ppbb.north) edge (\ppbb.south)
               (\ppbb.west)   --  (\ppbb.east);
                },% end of node contents
                node contents={}},
delay/.style = {draw=black, fill=white, minimum size=12mm,
                node contents={D}},
        }

\begin{document}
\begin{frame} 
    \frametitle{MWE}
\begin{center}  
\begin{tikzpicture}[
    node distance = 1 cm and 2cm
                    ]
\node (b1) {$x[n]$}; 
\node (s1) [sum,right=of b1]; 
\node (s2) [dot,right=of s1];
\node (b3) [right=of s2] {$y[n]$}; 
\node (d1) [delay,below=of s2];
% lines
\draw [gain=$b$,->]   (b1)  --    (s1); 
\draw [->]          (s1) edge   (b3)
                    (s2)  --    (d1); 
\draw [->]  (d1.south)  -- ++ (0,-1) coordinate (c1) 
            (c1 -| s1) -- (s1);
\draw [gain=$\alpha$]  (c1) -- (c1 -| s1);
\end{tikzpicture} 
    \end{center} 
\end{frame}
\end{document}

This MWE gives:

enter image description here

For above picture I didn't bother with line thickness. This you can easy change.

1
  • 1
    If you just want an overview of what is going on - essentially a series of pointers - then this question is probably fine and Zarko's answer to it is a good one in that respect. However, you could also get that from looking at the manually or just experimenting - maybe not quite as easily, but certainly more effectively. If, on the other hand, you want detailed explanation, then the question is much too broad. In that case, you need to ask a specific question about the particular bit you don't understand and make clear what you do understand so that somebody can explain the 'next step'.
    – cfr
    Commented Jun 15, 2016 at 21:26

1 Answer 1

10

Basic explanation of meaning some commands/macros used in my answer I already add to the answer, so here I more or less repeat them.

In graph are used predefined shapes of nodes. For its definition is used `\tikzset{ ...}, but they also can be defined locally as

    \begin{tikzpicture}[
presets of used graph elements
                        ]
    < graph content >
    \end{tikzpicture}

To \tikzset also can be given name, for example `\tikzset{mygraphs/.style = {< styles definitions>}} and than use in particular TikZ picture:

\begin{tikzipicture}[mygraphs]
< graph content >
\end{tikzpicture}

By styles are predefined graph elements as dot, gain, summation and delay. Most of definition is straightforward, some of them are more complex. At all nodes, which have fixed content, this content is written already in node style definition. For this is exploited option node content={...}. Use of this nodes is:

\node[dot, right=of <node name>];

More complex is adding to the node shape some drawings. For this are for coordinates used bounding box anchors. They are defined as

(path picture bounding box.<which one>)

For shorter writing those coordinates is defined new command

\newcommand\ppbb{path picture bounding box}     

by which the coordinates is accessible as for example accessible by

\draw[very thick,shorten <>=1mm,-]
           (\ppbb.west)   --  (\ppbb.east);

Added drawings should be in path picture={...} as can be seen in the code.

Follows copy of explanations already given in my answer to your question before.

  • Macros shorten <= <length> and shorten >=length> are doing as their names suggest: make line shorter (if length is positive) or longer (if length is negative) on the start or on the end of line respectively.

  • The style shorten <> is defined for shorter/concise code in styles definitions. Of course, it can be also used in graph, where the lines had to be shorter for the same length on its start and end.

  • The \node (b1) {$x[n]$}; is the same as \node (b1) at (0,0) {$x[n]$};, i.e. it is positioned at coordinate (0,0). All other nodes in graph are positioned relatively to it using TikZ library positioning on predefined distances between nodes by node distance=<vertical length> and horizontal length>, e.g. in the MWE with node distance = 1 cm and 2cm.

Hopefully, some one will give better explanation. On the end, when I do not know how to solve some particular problem in drawing with (nice, powerful and complex) TikZ package, I read its manual agan and again ... . If this not help me, I ask here (TeX. SE) for help :-). Here around are a lot of TikZ gurus! On the web you also can find some short introductions to the TikZ.

From code you also can observe a way, how you can draw similar graph with prepared system of shapes.

Addendum: In cases, when function blocks have different text inside shape, than you have two possibilities to define their styles:

  • as standard node, which content is added in curly braces, for example:˛ \node[<style name>] at (coordinate) {<text in node shape>};

  • or define it with optional argument, for example for node delay:

    delay/.style = {draw=black, fill=white, minimum size=12mm, node contents={#1}}

    delay/.default = D

In this case, when the node content is "D", use this style as

\node (<name>) [delay];

and when content is different (not default) for example as:

\node (<name>) [delay=$D_1$];
3
  • How should I define delay/.style so that I can add any text inside it like D1, T4, etc. If I leave node content{} and then try to use it as \node (d1) [delay,below=of s2]{$D1$}; I get an error
    – NAASI
    Commented Jun 15, 2016 at 21:59
  • I changed my definition to delay/.style = {draw=black, fill=white, minimum size=12mm} and now \node (d1) [delay,below=of s2]{D1}; is giving the desired result.
    – NAASI
    Commented Jun 15, 2016 at 22:08
  • See addendum to my answer.
    – Zarko
    Commented Jun 15, 2016 at 22:14

You must log in to answer this question.

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