Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TikZ, resizing and fitting

I want to take a PGF picture, scale it down (scaling the text as well, so \resizebox would be perfect) to obtain a certain height, then put a rotated text on the left of the picture and create a node containing everything.

Something like this:

Algorithm example

But I want to be able to set the height for the chart without scaling down the rotated "title".

Here is the LaTeX code for this example:

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

\begin{document}
\begin{tikzpicture}[%
  inner sep=2mm,
    delimiter/.style={ellipse, very thick, fill=red!30, draw=red!50},
    action/.style={trapezium, trapezium left angle=120, trapezium right angle=60, thick, fill=blue!30, draw=blue!50, align=center},
    loop/.style={ellipse, thick, fill=yellow!30, draw=yellow!50, align=center},
  title/.style={font=\LARGE\scshape,node distance=16pt, text=black!40, inner sep=1mm},
  background/.style={rectangle, rounded corners, fill=black!5, draw=black!15, inner sep=4mm}
]

  \node[delimiter] (begin) {Begin};
  \node[action] (cluster residues) [below=of begin] {Cluster residues};
  \node[action] (set clusters) [below=of cluster residues] {Set properties\\for every cluster};
  \node[action] (find pockets) [below=of set clusters] {Find clusters with\\$normalized\ SAS < 1$};
  \node[action] (sort pockets) [below=of find pockets] {Sort pockets found};
  \node[delimiter] (end) [below=of sort pockets] {End};

  \draw[->] (begin.south) -- (cluster residues);
  \draw[->] (cluster residues) -- (set clusters);
  \draw[->] (set clusters) -- (find pockets);
  \draw[->] (find pockets) -- (sort pockets);
  \draw[->] (sort pockets) -- (end);

  \node[fit=(begin)(cluster residues)(set clusters)(find pockets)(sort pockets)(end)] (chart) {};
  \node[title] (title) [left=of chart] {\rotatebox{90}{General algorithm}};

  \begin{scope}[on background layer]
    \node[background,fit=(chart)(title)] {};
  \end{scope}
\end{tikzpicture}
\end{document}

Any ideas on how to use \resizebox, \adjustbox or anything else to resize only the chart (not the "General algorithm" label)?

like image 207
dodomorandi Avatar asked Aug 20 '15 11:08

dodomorandi


1 Answers

You can put the chart into a scope and use the scale option to resize it. Notice the transform shape option. See the pgfmanual (17.7 Transformations) for details.

enter image description here

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,shapes.geometric,backgrounds}

\begin{document}
\begin{tikzpicture}[%
  inner sep=2mm,
    delimiter/.style={ellipse, very thick, fill=red!30, draw=red!50},
    action/.style={trapezium, trapezium left angle=120, trapezium right angle=60, thick, fill=blue!30, draw=blue!50, align=center},
    loop/.style={ellipse, thick, fill=yellow!30, draw=yellow!50, align=center},
  title/.style={font=\LARGE\scshape,node distance=16pt, text=black!40, inner sep=1mm},
  background/.style={rectangle, rounded corners, fill=black!5, draw=black!15, inner sep=4mm}
]

  \begin{scope}[scale=0.5, transform shape]
      \node[delimiter] (begin) {Begin};
      \node[action] (cluster residues) [below=of begin] {Cluster residues};
      \node[action] (set clusters) [below=of cluster residues] {Set properties\\for every cluster};
      \node[action] (find pockets) [below=of set clusters] {Find clusters with\\$normalized\ SAS < 1$};
      \node[action] (sort pockets) [below=of find pockets] {Sort pockets found};
      \node[delimiter] (end) [below=of sort pockets] {End};

      \draw[->] (begin.south) -- (cluster residues);
      \draw[->] (cluster residues) -- (set clusters);
      \draw[->] (set clusters) -- (find pockets);
      \draw[->] (find pockets) -- (sort pockets);
      \draw[->] (sort pockets) -- (end);
  \end{scope}

  \node[fit=(begin)(cluster residues)(set clusters)(find pockets)(sort pockets)(end)] (chart) {};
  \node[title] (title) [left=of chart] {\rotatebox{90}{General algorithm}};

  \begin{scope}[on background layer]
    \node[background,fit=(chart)(title)] {};
  \end{scope}
\end{tikzpicture}
\end{document}
like image 122
sergej Avatar answered Nov 06 '22 03:11

sergej