Scale TikZ figure to linewidth when relative positioning used

This question is a follow-up to How to scale a tikzpicture to \textwidth. Unfortunately I haven't been a member long enough to post comments in that thread to ask for clarification.

I have some figures that I've drawn with relative positioning commands like "right of" and "below of". It seems like when you use these, most of the typical scaling approaches don't work anymore. For an example, there's the simple flow chart from http://texample.net. I've included the code below in case the example changes in the future.

So, suppose I want to scale the figure from the example below. If I use

\begin{tikzpicture}[node distance = 2cm, auto, scale=0.5]


nothing happens. I've also tried the first method at the above link that scales a tikz figure to \linewidth. It did not work for me. Can someone tell me how to make this type of figure

1. scale to some constant amount like I've shown, and

2. scale to \linewidth?

Example simple flow chart (modified) from
http://www.texample.net/tikz/examples/simple-flow-chart/

\documentclass[12pt,oneside, ]{report}

\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

\begin{document}
%\pagestyle{empty}

% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=blue!20,
text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20,
text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
minimum height=2em]

\begin{tikzpicture}[node distance = 2cm, auto]
% Place nodes
\node [block] (init) {initialize model};
\node [cloud, left of=init] (expert) {expert};
\node [cloud, right of=init] (system) {system};
\node [block, below of=init] (identify) {identify candidate models};
\node [block, below of=identify] (evaluate) {evaluate candidate models};
\node [block, left of=evaluate, node distance=3cm] (update) {update model};
\node [decision, below of=evaluate] (decide) {is best candidate better?};
\node [block, below of=decide, node distance=3cm] (stop) {stop};
% Draw edges
\path [line] (init) -- (identify);
\path [line] (identify) -- (evaluate);
\path [line] (evaluate) -- (decide);
\path [line] (decide) -| node [near start] {yes} (update);
\path [line] (update) |- (identify);
\path [line] (decide) -- node {no}(stop);
\path [line,dashed] (expert) -- (init);
\path [line,dashed] (system) -- (init);
\path [line,dashed] (system) |- (evaluate);
\end{tikzpicture}

\end{document}

-
I assume you don't want the line width and/or the node text to be scaled as well, do you? I'm personally very happy with \resizebox{\linewidth}{!}{<tikz picture>}. – Martin Scharrer May 3 '11 at 20:12
Not sure I understand the question. Generally, I want the entire contents of the Tikz figure scaled. I just tried your suggestion and it actually did scale the node text. Is that not what you usually expect? I'd also like an option that would scale everything but the text as that may be desirable in some cases. – SSilk May 3 '11 at 21:03
@SSilk: \resizebox scales everything, so I expected scaled text. Scaling everything but the text is much more difficult so I was asking if you need that. – Martin Scharrer May 3 '11 at 21:14
Actually, on closer inspection, I see one small quirk with your method. The picture ends up indented like a new paragraph. I can fix this by putting a \noindent right before your \resizebox. Does that sound correct? Thanks. – SSilk May 3 '11 at 21:15
@SSilk: That's normal and depends on the exact way/position you use the code. If you start a new paragraph it gets indented. – Martin Scharrer May 3 '11 at 21:18

You can use \resizebox{\linewidth}{!}{<tikz picture>} from the graphics package which is already loaded by tikz anyway. It scales its content to the given width and height (! for the height means that it scales with the width). One drawback of this approach is that everything is scaled including the line width and node texts which might not be what some people want.

Note that \resizebox reads the whole picture as a macro argument, which isn't very efficient and does not allow verbatim or other special content. Alternatives are \Resizebox (same syntax) from my realboxes package or the {adjustbox}{width=\linewidth} environment from my adjustbox package.

-

You can actually just use the scale option from Tikz. Normally that does not scale nodes, and therefore in your example nothing happens. We can tell it to scale nodes as well though, by adding the transform shape option. This is not generally recommended because it will scale everything, including text, which might make for bad looking results. However, as far as I know, all of the suggestions here will do exactly the same. Your best option is to create the graphics in the scale you want to use them in, if that isn't an option then \begin{tikzpicture}[node distance = 2cm, auto, scale=0.5, transform shape] should do exactly what you want.

-

Two solutions ( I don't like left of= etc. because it's impossible to scale the picture and I don't like \resizebox because everything is scaled !)

1) You keep left of= etc. but you use something like: \def\myscale{2}and then for each node distance you write for example node distance=3*\myscale cm and now you can add \begin{tikzpicture}[scale=\myscale ...

2) You replace left of=init by something like : \node [cloud](expert) at ([xshift=-3cm]init) {expert}; etc.

-