[Tex/LaTex] Alternative for tikz’s scope environment outside tikzpicture

scopingtikz-pgf

I have a lot of small tikz graphics that I all want to scale down, so I'd like to put them in a scope, like this:

\documentclass{article}
\usepackage{tikz}
\begin{document}
    \begin{scope}[scale=0.3]
        \begin{tikzpicture}
%               Draw stuff in a small scale
        \end{tikzpicture}
        \begin{tikzpicture}
%               Draw more stuff in a small scale
        \end{tikzpicture}
    \end{scope}
    \begin{tikzpicture}
%           Draw stuff in normal scale again
    \end{tikzpicture}
\end{document}

But this doesn't work because the scope environment is only defined inside a tikzpicture.

How can I achieve this effect? Do I have to use \tikzset and save the current scale before scaling down and restoring it again at the end or is there a "proper" way of doing this?

Best Answer

We can use \tikzset{every picture/.style={scale=0.3}} for this purpose. I enclose an example and a page preview of it where scaling is applied from 0.1 to 1.2 with a step of 0.1 to demonstrate its use.

%! *latex tikz-scaling-a.tex
\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage{tikz}
\parindent=0pt
\addtolength{\textheight}{1in}
\begin{document}
\def\malpicture{% Picture is changing, the font is not...
  \begin{tikzpicture}[x=1cm, y=1cm]
    \draw[line width=2pt, ](0,0)--(5,2);
    \node at (1,1) {Hello World!};
  \end{tikzpicture}
  }% End of \malpicture...
% A typical use... 
\malpicture\par
% And now with scaling...
\foreach\scaling in {0.1,0.2,...,1.2} {%
  \tikzset{every picture/.style={scale=\scaling}}% =0.3 etc.
  \fbox{\malpicture}\par
  }% End of \foreach\scaling...

\tikzset{every picture/.style={scale=0.3}}
\malpicture
\end{document}

mwe

I enclose one similar example where a TeX group (braces or \begingroup and \endgroup) is used to limit the \tikzset command. The first and the last pictures are without change, the second and the third one are affected by the \tikzset command.

%! *latex tikz-scaling-b.tex
\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage{tikz}
\parindent=0pt
\addtolength{\textheight}{1in}
\begin{document}

% A normal picture before a change is applied... 
\begin{tikzpicture}[x=1cm, y=1cm]
    \draw[line width=2pt, ](0,0)--(5,2);
    \node at (1,1) {Hello World!};
\end{tikzpicture}

% A group will limit the \tikzset command...
\begingroup % or we use opening brace "{"
\tikzset{every picture/.style={scale=0.3}} % a change in parameters
\begin{tikzpicture}[x=1cm, y=1cm]
    \draw[line width=2pt, ](0,0)--(5,2);
    \node at (1,1) {My first scaled picture!};
\end{tikzpicture}\par
\begin{tikzpicture}[x=1cm, y=1cm]
    \draw[line width=2pt, ](0,0)--(5,2);
    \node at (1,1) {My second scaled picture!};
\end{tikzpicture}%
\endgroup % or we use closing brace "}"

% A let's get back to normal scaling... 
\begin{tikzpicture}[x=1cm, y=1cm]
    \draw[line width=2pt, ](0,0)--(5,2);
    \node at (1,1) {My last picture!};
\end{tikzpicture}
\end{document}

mwe2