# Best way to include a standalone tikz file and scale it without scaling the nodes

Consider something like this:

\documentclass{article}
\usepackage{standalone}
\begin{document}
\includestandalone[scale=2]{myfile}
\includestandalone[scale=1.5]{myfile}
\end{document}


where myfile is a standalone file containing a tikz picture:

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (1,0) node[right]{$X$};
\end{tikzpicture}
\end{document}


My problem is, that the scale option scales the whole picture including nodes and the characters like $X$ in my example. What is the best way to change this such that I can scale the picture without scaling the nodes? I.e. the equivalent to the scale option of the tikzpicture environment without the transform shape option?

• Can you just put the draw commands in the file? Then you could use \begin{tikzpicture}[scale=2]\input{tikzfile.tex}\end{tikzpicture} – Tom Bombadil Oct 27 '15 at 14:26

Why not something like this?

\newcommand*\MyScale{1}
\tikzset{%
every picture/.style={%
scale=\MyScale,
}
}


This defines a command \Scale which takes a single optional argument. By default, it just sets the scaling to 1. With an argument, it sets it to that value. This is then used at the start of each tikzpicture to scale the picture without, of course, scaling the text and labels.

So you can then say

  \includestandalone{\jobname-tikz}
\Scale[2]
\includestandalone{\jobname-tikz}
\Scale[1.5]
\includestandalone{\jobname-tikz}
\Scale[3]
\includestandalone{\jobname-tikz}
\Scale
\includestandalone{\jobname-tikz}


to produce

I would like this to reset the default scaling each time. However, I can't figure out a straightforward way to do that right now and the feature doesn't seem to be worth the additional hassle involved in using a non-straightforward strategy.

Complete code:

\begin{filecontents}{\jobname-tikz.tex}
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (1,0) node[right]{$X$};
\end{tikzpicture}
\end{document}
\end{filecontents}
\documentclass{article}
\usepackage{standalone,tikz}
\newcommand*\MyScale{1}
\tikzset{every picture/.style={scale=\MyScale}}
\begin{document}
\includestandalone{\jobname-tikz}
\Scale[2]
\includestandalone{\jobname-tikz}
\Scale[1.5]
\includestandalone{\jobname-tikz}
\Scale[3]
\includestandalone{\jobname-tikz}
\Scale
\includestandalone{\jobname-tikz}
\end{document}


I would do something like this:

\documentclass[tikz]{standalone}

\def\Scale{3}
\pgfmathparse{1/\Scale}\edef\InvScale{\pgfmathresult}

\begin{document}
\begin{tikzpicture}[scale=\Scale]
\draw (0,0) -- (1,0) node[right]{\scalebox{\InvScale}{$X$}};
\draw (0,-0.25) -- (1,-0.25) node[right,scale=\InvScale]{$X$};
\draw (0,-0.5) -- (1,-0.5) node[right]{$X$};
\end{tikzpicture}
\end{document}


But I am not sure if it works with \includestandalone command.

• I don't understand this. Why the use of \scalebox? Why not just scale=\Scale passed to the tikzpicture? Though it would be much better to use \newcommand*\Scale{3}. Especially since \Scale seems just the kind of thing a package might define. – cfr Oct 27 '15 at 21:42
• scalebox is just an example that may be used. Nevertheless, I would use the second approach. \newcommand*\Scale{3} if of course a better choice, \def was used just as a shortcut. – cacamailg Oct 27 '15 at 23:14
• But wasn't the original problem that the nodes were scaled? If you put stuff which uses \Scale inside the nodes, you don't avoid their being affected by the scaling factor.... – cfr Oct 27 '15 at 23:23
• Well... The nodes are scaled and also the draw with \begin{tikzpicture}[scale=\Scale] ... \end{tikzpicture}. That is why then I scale each node individually with scale=\InvScale. So only the \draw` will effectively been scaled. – cacamailg Oct 27 '15 at 23:31