# TikZ Scaling: Cannot scale a tikzpicture

Please take a look at the picture below. scale pgfkey works for the inner tikzpicture but not for the outer one.

MWE:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node[draw](node2){Node 2};
\node[below=of node2](tikzpic){%
\begin{tikzpicture}[scale=2]
\draw [step=0.25cm,lightgray,very thin] (0,0) grid (2.5,1.5);
\end{tikzpicture}
};
\draw[->,ultra thick] (node2) -- (tikzpic);
\end{tikzpicture}
%
\begin{tikzpicture}[scale=2]
\node[rectangle,draw](node2){Node 2};
\node[below=of node2](tikzpic){%
\begin{tikzpicture}
\draw [step=0.25cm,lightgray,very thin] (0,0) grid (2.5,1.5);
\end{tikzpicture}
};
\draw[->,ultra thick] (node2) -- (tikzpic);
\end{tikzpicture}
\end{document}


-
Is it correct to insert tikzpicture environment inside another one? – Sigur Dec 12 '12 at 15:18
@Sigur No, it isn't. – Loop Space Dec 12 '12 at 15:25

Do this if you promise to wash your hands before and afterwards and to digest Andrew's answer. I'm not that sensitive about this issue however he tells you the proper (and prescribed) way.

The nested ones don't inherit the styles since it's not set for every picture style. But you can enforce it. Also you need to include transform shape key to let the nodes absorb the current transformation. But this would scale the nested ones 4 times. Since it's scaled twice first in the outer and then in the inner one.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\tikzset{for this and nested ones/.style={#1,every picture/.style={#1}}}

\begin{document}
\begin{tikzpicture}
\node[draw](node2){Node 2};
\node[below=of node2](tikzpic){%
\begin{tikzpicture}[scale=2]
\draw [step=0.25cm,lightgray,very thin] (0,0) grid (2.5,1.5);
\end{tikzpicture}
};
\draw[->,ultra thick] (node2) -- (tikzpic);
\end{tikzpicture}
%
\begin{tikzpicture}[for this and nested ones={scale=2,transform shape}]
\node[rectangle,draw](node2){Node 2};
\node[below=of node2](tikzpic){%
\begin{tikzpicture}
\draw [step=0.25cm,lightgray,very thin] (0,0) grid (2.5,1.5);
\end{tikzpicture}
};
\draw[->,ultra thick] (node2) -- (tikzpic);
\end{tikzpicture}
\end{document}


-

It does work for the outer one, but in the outer one you have nothing that is affected by it. Everything in your picture is defined in terms of nodes and nodes are generally exempt from non-translation transformations. So the scale=2 is not applied to either node2 or tikzpic, and then since the arrow is defined in terms of those nodes it isn't affected either.

To force a non-translation transformation to have an effect on a node you can use the transform shape key on that node. To force it on all, use every node/.append style={transform shape}:

\documentclass{article}
%\url{http://tex.stackexchange.com/q/86730/86}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node[draw](node2){Node 2};
\node[below=of node2](tikzpic){%
\begin{tikzpicture}[scale=2]
\draw [step=0.25cm,lightgray,very thin] (0,0) grid (2.5,1.5);
\end{tikzpicture}
};
\draw[->,ultra thick] (node2) -- (tikzpic);
\end{tikzpicture}
%
\begin{tikzpicture}[scale=2]
\node[rectangle,draw](node2){Node 2};
\node[transform shape,below=of node2](tikzpic){%
\begin{tikzpicture}
\draw [step=0.25cm,lightgray,very thin] (0,0) grid (2.5,1.5);
\end{tikzpicture}
};
\draw[->,ultra thick] (node2) -- (tikzpic);
\end{tikzpicture}
\end{document}
`

Produces:

Nesting pictures is generally a bad idea - TikZ is not set up with the expectation that tikzpictures are nested and so there is no particular control over "leakage" of settings from one picture to the other (inner to outer or outer to inner). It is better to form your picture as a single picture, using scopes to separate content and matrices to position content. In this particular situation it is very simple to recreate this as a single diagram - which leads me to suspect that it is an example crafted to show the problem you were encountering (which is a very good thing to do!). So while I'd be happy to try to recreate it as a single picture for you it may be that your real example is more complicated and doing this one wouldn't be all that illuminating. If you would like help on reformulating a nested picture as a single one (assuming I've convinced you!), feel free to ask a new question.

(There are quite a number of different posts here dealing with issues of nesting tikz pictures. It is possible so long as you are aware of what you are doing and know what can go wrong. An example of what can go wrong is at Problem with overlay when a tikzpicture is inside another tikzpicture, and there are plenty of linked questions to see other things.)

-
Thanks. I am trying to make multiple flowcharts (fairly complex) for my thesis. They would be reused for various publications after that. I do not want to spend more time with them and am experimenting with tikz to find a good workflow. Will this be acccepted as a question on this forum? As for nested tikz code, I will see work on it and may be ask a question if I am not able to do it. – devendra Dec 12 '12 at 16:23
@devendra Certainly asking for help with diagrams is fine, but it works best when you can pinpoint the issue. "Just draw it for me" questions aren't so good. What you did here was good in that you provided an example showing just what it was you were stuck with. With nesting pictures, pragmatism should hold sway: if it works, use it. Just be prepared that odd things can happen. – Loop Space Dec 12 '12 at 16:38