12

I am trying to draw a flow diagram and I am having some trouble getting the details right. For now, my code looks like this:

% Define block styles
\tikzstyle{block} = [rectangle, draw, fill=red!40, 
    text width=6em, text centered, rounded corners, minimum height=3em]
\tikzstyle{arrow} = [draw, -latex']

\begin{figure}[!h]
\centering
\begin{tikzpicture}[node distance = 5cm, auto]
    % Place nodes
    \draw ++(0,0) node [block] (signal) {Señal temporal};
    \draw ++(4,0) node [block] (FFT)  {Transformada rápida de Fourier};
    \draw ++(9,0) node [block] (MSF)  {Mapeo a escala de Mel};
    \draw ++(13.5,-1.5) node [block] (Log)  {Logaritmo de la potencia};
    \draw ++(9,-3) node [block] (DCT) {Transformada Coseno Discreta};
    \draw ++(4,-3) node [block] (MFCC) {Descriptores MFCC};

    % Draw edges
    \path [arrow] (signal) -- (FFT);
    \path [arrow] (FFT) -- node {espectro} (MSF) ;
    \draw[arrow] (MSF.east) -- node [above] {espectro} node [below] {de Mel} ++(1.5,0)   -|  (Log.north);    
    \draw[arrow] (Log.south) --  ++(0,-0.86)   --  (DCT.east);    
    \path [arrow] (DCT) -- (MFCC) ;
    
   
\end{tikzpicture}
\caption[MFCC]{Diagrama en bloques del cálculo de las MFCC para un frame.}
\label{MFCC}
\end{figure}

Which outputs this:

How my tikz picture looks like

In the first line, all the way up to the right there is a text above and under the arrow "espectro de Mel" I would like this to be centered to the right like this:

What I would like to accomplish

Of course, I can accomplish this easily with an image editor but I think this can by done with code.

Thank you for your answers, and I will gladly receive any suggestions regarding the rest of the image as well.

2
  • [above,midway] comes to mind ;-)
    – daleif
    Sep 30 '15 at 13:16
  • That seems so simple it should work but it doesn´t. I also don´t get any warnings or errors, just the exact same output :/ Sep 30 '15 at 13:19
14

Some comments:

  • tikzset{stylename/.style={}} is recommended over \tikzstyle.
  • Nodes are positioned relative to each other, using the syntax of the positioning library.
  • The right-down line is drawn with (node1) -| (node2), and in this case pos=0.25 will be halfway between the first node and the corner.

    In your original code you have (MSF.east) -- <nodes are here> ++(1.5,0) -| (Log.north), so the nodes are placed halfway between the right edge of MSF and a point 1.5 units right of MSF. Then the line continues horizontally until it reaches the x-coordinate of Log.north, where it turns and goes down to Log.

  • While it still works, the arrows library is deprecated in favour of arrows.meta. Making that switch requires a small change in the specification of the arrow tip.

enter image description here

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\tikzset{
     block/.style={rectangle, draw, fill=red!40, text width=6em,
                   text centered, rounded corners, minimum height=3em},
     arrow/.style={-{Stealth[]}}
     }
\usetikzlibrary{positioning,arrows.meta}
\begin{document}
\begin{tikzpicture}
    \node [block] (signal) {Señal temporal};
    \node [block,right=of signal] (FFT)  {Transformada rápida de Fourier};
    \node [block,right=2cm of FFT] (MSF)  {Mapeo a escala de Mel};
    \node [block,below right=0.2cm and 1cm of MSF] (Log)  {Logaritmo de la potencia};
    \node [block,below left=0.2cm and 1cm of Log] (DCT) {Transformada Coseno Discreta};
    \node [block,left=2cm of DCT] (MFCC) {Descriptores MFCC};


    % Draw edges
    \draw [arrow] (signal) -- (FFT);
    \draw [arrow] (FFT) -- node [above] {espectro} (MSF);
    \draw[arrow] (MSF)  -|  (Log) node [above,pos=0.25] {espectro} node [below,pos=0.25] {de Mel}   ;  
    \draw[arrow] (Log.south) |-  (DCT.east);  
    \draw [arrow] (DCT) -- (MFCC) ;
\end{tikzpicture}
\end{document} 
5
  • Thank you very much for your input! I didn´t really understood how to draw the lines but I think I am starting to. I appreciate that you didn´t just answered my question, but helped me better understand where they were coming from. Sep 30 '15 at 13:38
  • @TorbjørnT, in the third item of your comments I first time see described this features! I discover it accidentally in drawing one of my TikZ images, Is this features documented somewhere? If it is in TikZ manual, in spite to often reading it, I didn't see it.
    – Zarko
    Sep 30 '15 at 20:23
  • @Zarko Yes, find the description of the pos key, it is mentioned there. (Section 17.8, bottom of page 235 in the version of the manual I have.) Sep 30 '15 at 20:28
  • @TorbjørnT. thank you for info! Just now I download recent version of manual (3.0.1a) and found this description (at bottom of page 235). I'm pretty sure, that in older one doesn't has this information. Maybe I'm wrong.
    – Zarko
    Sep 30 '15 at 21:16
  • Thanks @TorbjørnT. for the answer!
    – Sufyan
    May 7 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.