Scaling a TikZ figure from an external file

You can set the every picture locally in a group around the input file to set any option which should be used for the tikzpicture in that file.

\begingroup
\tikzset{every picture/.style={scale=0.3}}%
\input{sometikzpic}%
\endgroup

However, if you have other tikzpictures inside nodes of the main picture they will also be affected (twice I mean). In this case, \tikzset{every picture/.style={scale=0.3,every picture/.style={}}} might work better.


Note that scale scales only coordinates. Text is not affected. You might want to scale the whole picture all together. For this use \scalebox{<factor>}{\input{<file>}} or
\resizebox{<width>}{!}{\input{<file>}}. This both macros come from graphics which is loaded already by tikz.

Also have a look at the standalone class, especially the new \includestandalone[<options>]{<file>} from v1.0beta which will include subfiles and scales them if requested, like \includegraphics does for images.


I know this has been answered, so here's a little trick to use these answers.

-1- Put this after your \usepackages and before your \begin{document}:

\newcommand{\inputTikZ}[2]{%  
     \scalebox{#1}{\input{#2}}  
}

-2- Use it like this to create a figure:

\begin{figure}  
\begin{centering}  
    \inputTikZ{0.5}{mytikzfile.tkz}  
\end{centering}  
\label{fig:myFig}  
\caption{some caption for the figure}  
\end{figure}  

In this way, the syntax is similar to \includegraphics[scale=...]{filename}


If inside foo.tex you set the scale to \tkzscl or some other user macro, you can then set it like so:

\def\tkzscl{0.3}
\input{foo}

This way, you can set the scale of the picture in the main file.

foo.tex should then look like this:

\begin{tikzpicture}[scale=\tkzscl]
\draw (0,0) -- (1,0);
\end{tikzpicture}

Or whatever…