2

I want to draw block diagram of following nature in tikz environment . I have defined arrows, adder and blocks so putting them together is not an issue.

However, I don't know how to add extra arrows along with labels to show "path-gains"....highlighted in green in following picture.

enter image description here

MWE: I have included all the libraries and packages that I am using in my actual document. My code is not very well presented here. Sorry for the inconvenience

\documentclass{beamer} 
\usetheme{default}
\usecolortheme{default} 
\usefonttheme{professional fonts}
\let\familydefault\rmdefault

\setbeamertemplate{navigation symbols}{} 
\setbeamertemplate{caption}[numbered] 
\setbeamertemplate{frametitle}[default][center]



\usepackage[english]{babel} 
\usepackage{csquotes} 
\usepackage{verbatim} 
\usepackage{tikz} 
\usepackage{textcomp} 
\usepackage{amsmath, amscd, amsthm, amssymb, mathrsfs,amsfonts}          \usepackage{graphicx} \usepackage{enumitem} \usepackage{mathtools,mathdots,bm,fixltx2e} 

\usepackage{pstool} %\usepackage{auto-pst-pdf}

\usetikzlibrary{arrows, calc, fit, positioning, shapes.geometric}    \usetikzlibrary{positioning} \usetikzlibrary{decorations.markings}

\usepackage{mathpazo} \usepackage{pgfplots,pgfplotstable} \usepackage{marvosym,xcolor} \usepackage{lmodern} \usepackage{varwidth} \usepackage{framed,color} \definecolor{shadecolor}{rgb}{1,0.8,0.3}

\usepackage[style=verbose,backend=bibtex]{biblatex} \bibliography{precoderreferences} \AtEveryCitekey{\clearfield{doi}} \AtEveryCitekey{\clearfield{ssn}} \renewcommand*{\bibfont}{\scriptsize} \renewcommand{\footnotesize}{\tiny} \newcommand*\MyPastitem{\item[\color{shadecolor}\scalebox{0.9}{\textbullet}]} \newcommand*\MyCurrentitem{\item[\color{blue}\scalebox{0.9}{\textbullet}]} \newcommand*\MyNextitem{\item[\color{white}\scalebox{0.9}{\textbullet}]}

\begin{document}

%------------------------------------------------ \tikzset{ A/.style = {decoration={markings, mark= at position 0.5
                        arrow[ultra thick]{stealth};
                        above] {##1};}
                            },
                            },
            decorate}},
         }

% Definition of blocks: \tikzstyle{block} = [rectangle, minimum width=1cm, minimum height=1cm, text centered, text width=1.1cm, draw=black, fill=white] \tikzstyle{text.block} = [rectangle, minimum width=2em, minimum height=2em, text centered, text width=2em, draw=white, fill=white] %------------------------------------------------ \tikzstyle{FIX} = [circle,minimum size=1em,text centered, draw=red] \tikzstyle{adder} = [circle,minimum size=1em,text centered, draw=black] %------------------------------------------------ \tikzstyle{arrow} = [thick,->,>=stealth] \tikzstyle{rarrow} = [thick,<-,>=stealth]

\begin{frame} \frametitle{MWE}

\begin{center}  \begin{tikzpicture}[node distance=2 cm][thick,scale=0.6, every node/.style={scale=0.6}]

%\draw [step=0.2cm,gray!30,very thin](0,0) grid (9.8,7.0); \node(Rp1) at (0,7.0) [FIX,draw=white]{};

\node(b1) [text.block,right of=Rp1] {$\mathbf{u}$}; \node(s1) [adder,right of=b1]{+}; \node(b2) [text.block,right of=s1, xshift=4cm]{$y[n]$}; \node(b3) [block, below right of=s1,xshift=1cm]{$D$};

\draw [arrow]  (b1)    --   (s1); \draw [arrow]  (s1)    --   (b2); \draw [arrow]  (s1)    -|   (b3); \draw [arrow]  (b3) |- ++(0,-1.5) -| node[pos=0.225,above] {$\alpha$}  (s1);


\end{tikzpicture} \end{center} \end{frame}

\end{document}
1

1 Answer 1

4

Try the following TikZ preset:

\tikzset{
A/.style = {decoration={markings, mark= at position 0.5
                        arrow[ultra thick]{stealth};
                        above] {#1};}
                        },
            postaction={decorate}},
         }

And than use it as:

\begin{tikzpicture}
\draw[A=$b$] (0,0) -- + (3,0);
\end{tikzpicture}

For this you need to load TikZ library decorations.markings.

Edit: By accident I erase important part of code when I try to format it ... Now this is corrected, and also is added an example of use the proposed solution:

\documentclass[tikz, border=3mm, preview]{standalone}
\usetikzlibrary{arrows,decorations.markings}

\tikzset{
A/.style = {decoration={markings, mark= at position 0.5
                        with {\arrow[ultra thick]{stealth};
                              \node[above] {#1};}
                            },
                postaction={decorate}},
        }         
\begin{document}
\begin{tikzpicture}
\draw[A=$b$] (0,0) -- + (3,0);
\end{tikzpicture}
\end{document}         

enter image description here

Adendum: From "forest" in your added MWE was very difficult to find important "trees" ... I omit all packages and your definition which are not relevant to desired picture. I also use corrected definition for arrows presenting gain (which you can see above) and rename it to gain which seems to be more meaningful. Also I use some my TikZ presets for similar diagrams and use corect syntax for positioning of nodes:

\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.

Some explanations: In code in the addendum are used some of the TikZ features:

  • 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.
  • 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 defining styles used in graph, where the lines had to be shorter for the same length on it start and end. Beside in styles, it can be used anywhere in a graph, where this can be handy.
  • In nodes with predefined content is used option node contents={...}. By this at the use of such node the {<content>} is surplus (i.e. the code is shorter) and cause warning for wrong use of node.
  • The command \ppbb is defined as \newcommand\ppbb{path picture bounding box} and used for shorter writing paths in path picture={...} in defining of particular node style (for example in definition of the sum, where is on this way drawn sign + centered in the shape).
9
  • I have included the required library but I am getting an error "Too many }'s" when I add \tikzset.
    – NAASI
    Commented Jun 14, 2016 at 22:26
  • By accident I erase part of code when I formatting it ... it is now corrected.
    – Zarko
    Commented Jun 14, 2016 at 22:44
  • @NAASI, I added full example of your image. See, if it is useful for your needs.
    – Zarko
    Commented Jun 15, 2016 at 14:00
  • @ Zarko, Thank you for your effort. Can you explain \newcommand\ppbb. How does this work?
    – NAASI
    Commented Jun 15, 2016 at 15:48
  • 1
    @NAASI, I add further explanation to my answer. Since we reach the limit number of comments, we need to finish this discussion. If you have new questions about answer, please ask new question. And: dont afraid to read TikZ manual. Beside, that it is huge, it is well structured ...
    – Zarko
    Commented Jun 15, 2016 at 17:49

You must log in to answer this question.

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