2

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?

  • If you want to make it smaller outside a \tikzpicture can use \resizebox command. – Ignasi Mar 27 '14 at 16:48
1

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

  • Instead I could just do \tikzset{scale=\scaling} before every picture, right? My problem is that at the end of your loop, the scaling is still set at 1.2. – Turion Mar 27 '14 at 16:38
  • No need for it, use \tikzset{every picture/.style={scale=0.3}} when you need it (before the first picture and only once) and use \tikzset{every picture/.style={scale=1.0}} whenever you need a common scaling (after the last picture you wish to have scaled, again use it only once). You can alternatively put that first command within a TeX group ({ }), then only pictures within that group would be affected. – Malipivo Mar 27 '14 at 16:44
  • Yes, but if the scale before wasn't 1.0, this won't work. What is a group? – Turion Mar 27 '14 at 16:45
  • 1
    This command is a switcher, it is switching parameters until another change. If we want to limit a switcher, we put it in a group (scope is a term used by TikZ), e.g. common scaling, starting a group: { \tikzset{every picture/.style={scale=0.3}} tikz pictures to be scaled } here is the end of group and common scaling again with another TikZ pictures. – Malipivo Mar 27 '14 at 16:55
  • Of course, where were my braces? ;) Great, that works and is exactly what I meant! Do you want to post a new answer or modify your answer with that? – Turion Mar 27 '14 at 17:13

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.