4

I'm trying to scale the whole picture but it's not working.

\begin{tikzpicture} [scale=0.5, every node/.style={transform shape}]

\tikzstyle{startstop}   = [ellipse,   draw=orange, thick, fill=orange!20, text width=5em, minimum height=4em, text centered, dashed]
\tikzstyle{block}       = [rectangle, draw=blue,   thick, fill=blue!20,   text width=8em, minimum height=4em, shape aspect=2, text centered, rounded corners]

    % Define nodes in a matrix
    \matrix [column sep=10mm, row sep=7mm]
            {
                \node   [startstop]     (Signal)        {Trama de la señal};
                &\node  [block]         (DFT)           {Transformada Discreta de Fourier};
                &\node  [block]         (Module)        {Módulo};
                &\node  [block]         (MelFilt)       {Filtros Mel}; \\
                \node   [startstop]     (MFCC)          {MFCC};
                &\node  [block]         (Lifter)        {Lifter};
                &\node  [block]         (IDCT)          {Transformada Discreta Inversa de Coseno};
                &\node  [block]         (Log)           {Logaritmo}; \\
            };

    \node [draw, scale=1, rectangle, dashed, thick, fit=(DFT) (Module) (Log) (Lifter) (IDCT)] {};

    % connect all nodes DFT above
    \begin{scope} [every path/.style={line, line width=1.3pt}  ]

        %Down Lines 
        \path (Signal)  --  (DFT);
        \path (DFT)     --  (Module);
        \path (Module)  --  (MelFilt);
        \path (MelFilt.south)   --  (Log.north);
        \path (Log)     --  (IDCT);
        \path (IDCT)    --  (Lifter);
        \path (Lifter)  --  (MFCC);

    \end{scope}

\end{tikzpicture}

And when I replace transform shape for scale=0.5, the fitting fails.

3

I think the issue is the matrix. As soon as I switched to regular nodes, it started working better. I also don't think a matrix is the appropriate tool here since it works a bit differently. Alternatively, I'd suggest using the chains library which will also get rid of the extra line commands below. Finally, you can remove the fit library and use calc to draw a fitting rectangle around the nodes (you only needed two by the way for fitting them).

Of course, now it scales better!

Output

enter image description here

Code

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}

\usetikzlibrary{shapes.geometric, chains, calc}

\tikzset{
    startstop/.style={ellipse,   draw=orange, thick, fill=orange!20, text width=5em, minimum height=4em, text centered, dashed},
    block/.style={rectangle, draw=blue,   thick, fill=blue!20,   text width=8em, minimum height=4em, shape aspect=2, text centered, rounded corners},
    links/.style={line width=1.3pt}
}

\begin{document}
\begin{tikzpicture}[scale=.5,transform shape,
    start chain=going right, node distance=1cm, auto,
    every join={line width=1.3pt},
    every node/.style={on chain, join}
    ]

% Define nodes in a matrix
\node[startstop] (Signal)  {Trama de la señal};
\node[block]     (DFT)     {Transformada Discreta de Fourier};
\node[block]     (Module)  {Módulo};
\node[block]     (MelFilt) {Filtros Mel};
\node[continue chain=going below,block] (Log) {Logaritmo};
\node[continue chain=going left, block] (IDCT) {Transformada Discreta Inversa de Coseno};
\node[continue chain=going left, block]     (Lifter)  {Lifter};
\node[continue chain=going left, startstop] (MFCC)    {MFCC};

% connect all nodes DFT above
\draw[dashed, thick, rounded corners] ($(Lifter.south west)+(-.2,-.2)$) rectangle ($(MelFilt.north east)+(.2,.2)$);

\end{tikzpicture}
\end{document}
  • Thanks, it's working just fine. But how can I add end arrows to those lines? – user249067 Feb 19 '16 at 16:25
  • @user249067 if you need the same direction, then do: every node/.style={on chain, join=by {->}} – Alenanno Feb 19 '16 at 16:37
2

It is not really clear, if you want to scale the text as well. But there are many posts on this topic around here. For your example, transform canvas={scale=.5} should work. Is this, what you want?

Please note that I had to remove the style line from your scope, as I did not know where this comes from.

% arara: pdflatex

\documentclass{article}
\usepackage[spanish]{babel}
\usepackage{tikz}
\usetikzlibrary{shapes, fit}    

\begin{document}
\begin{tikzpicture}[%
    ,transform canvas={scale=.5}
    ,startstop/.style={%
        ,ellipse
        ,draw=orange
        ,thick
        ,fill=orange!20
        ,text width=5em
        ,minimum height=4em
        ,text centered
        ,dashed
        }
    ,block/.style={%
        ,rectangle
        ,draw=blue
        ,thick
        ,fill=blue!20
        ,text width=8em
        ,minimum height=4em
        ,shape aspect=2
        ,text centered
        ,rounded corners
        }
    ]
% Define nodes in a matrix
\matrix[column sep=10mm, row sep=7mm]
    {%
    \node   [startstop]     (Signal)        {Trama de la señal};
    &\node  [block]         (DFT)           {Transformada Discreta de Fourier};
    &\node  [block]         (Module)        {Módulo};
    &\node  [block]         (MelFilt)       {Filtros Mel}; \\
    \node   [startstop]     (MFCC)          {MFCC};
    &\node  [block]         (Lifter)        {Lifter};
    &\node  [block]         (IDCT)          {Transformada Discreta Inversa de Coseno};
    &\node  [block]         (Log)           {Logaritmo}; \\
    };
\node[draw, rectangle, dashed, thick, fit=(DFT) (Module) (Log) (Lifter) (IDCT)] {};
% connect all nodes DFT above
\begin{scope}[every path/.style={draw,line width=1.3pt}]
\path (Signal)  --  (DFT);
\path (DFT)     --  (Module);
\path (Module)  --  (MelFilt);
\path (MelFilt.south)   --  (Log.north);
\path (Log)     --  (IDCT);
\path (IDCT)    --  (Lifter);
\path (Lifter)  --  (MFCC);
\end{scope}
\end{tikzpicture}
\end{document}
1

From TikZ manual:

It is possible to transform nodes, but, by default, transformations do not apply to nodes. The reason is that you usually do not want your text to be scaled or rotated even if the main graphic is transformed. Scaling text is evil, rotating slightly less so. However, sometimes you do wish to transform a node, for example, it certainly sometimes makes sense to rotate a node by 90 degrees. There are two ways to achieve this:

  1. You can use the following option:

    /tikz/transform shape (no value)

Causes the current “external” transformation matrix to be applied to the shape. For example, if you said \tikz[scale=3] and then say node[transform shape] {X}, you will get a “huge” X in your graphic.

  1. You can give transformation options inside the option list of the node. These transformations always apply to the node.

So, if it possible, avoid scaling! If you still persist, than make it your MWe on the following way:

\documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{fit,matrix,shapes.geometric}

    \begin{document}
\begin{tikzpicture} [
 every node/.style = {scale=0.5, transform shape, % <-----
                      align=center, minimum height=4em},
  startstop/.style = {ellipse, draw=orange, thick, dashed, 
                      fill=orange!20, text width=5em},
      block/.style = {rectangle, draw=blue, thick, rounded corners, 
                      fill=blue!20, text width=8em}
                    ]
% Define nodes in a matrix
\matrix [column sep=10mm, row sep=7mm]
{
\node[startstop]    (Signal)   {Trama de la señal};
    &   \node  [block]         (DFT)           {Transformada Discreta de Fourier};
    &   \node  [block]         (Module)        {Módulo};
    &   \node  [block]         (MelFilt)       {Filtros Mel}; \\
\node  [startstop]  (MFCC)     {MFCC};
    &   \node  [block]         (Lifter)        {Lifter};
    &   \node  [block]         (IDCT)          {Transformada Discreta Inversa de Coseno};
    &   \node  [block]         (Log)           {Logaritmo}; \\
            };
\node[draw, dashed, thick, 
      scale=2, % <-----
      fit=(DFT) (Log)] {};
% connect all nodes DFT above
\draw[line width=1.3pt,->] 
    (Signal)  edge  (DFT)
    (DFT)     edge  (Module)
    (Module)  edge  (MelFilt)
    (MelFilt) edge  (Log)
    (Log)     edge  (IDCT)
    (IDCT)    edge  (Lifter)
    (Lifter)  edge  (MFCC);
\end{tikzpicture}
    \end{document}

The main changes in your code is indicated by <---. Other changes only slightly optimize your code and (according to my taste) improve appearance. Of course better appearance is obtained without scaling.

As you see, the node, which fir blue nodes, is re-scaled with inverse value of node scaling. This is necessary, since for fitting nodes it had not to be scaled.

Result is:

enter image description here

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.