# Use pgfplots and a custom length to define global width when inputing the plot

I'm trying to set the width for all my plots, that are defined in other files and imported into the main document, using a custom width, \sz. I'm trying to set this length because I want to change it for one or two columns. Like in this example, main.tex:

\documentclass{minimal}

\usepackage{standalone}
\usepackage{tikz}
\usepackage{pgfplots}

\newlength{\sz}
\setlength{\sz}{0.5\linewidth}

\begin{document}
\input{test}
\end{document}


test.tex:

\documentclass{standalone}

\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
x tick label style={
/pgf/number format/1000 sep=},
ylabel=Population,
enlargelimits=0.05,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ybar interval=0.7,
cycle list name=color list
]
coordinates {(1930,50e6) (1940,33e6)
(1950,40e6) (1960,50e6) (1970,70e6)};
coordinates {(1930,38e6) (1940,42e6)
(1950,43e6) (1960,45e6) (1970,65e6)};
coordinates {(1930,15e6) (1940,12e6)
(1950,13e6) (1960,25e6) (1970,35e6)};
coordinates {(1930,15e6) (1940,12e6)
(1950,13e6) (1960,25e6) (1970,35e6)};

\legend{Far,Near,Here,There}
\end{axis}
\end{tikzpicture}
\end{document}


However, when I'm compiling it, the length of \sz is reset to zero. And I get the error: Error: Plot width '0.0pt' is too small. Is there any way of setting the length so that the figure in the other file is able to 'see' it?

-

This happens because you use the minimal documentclass, which doesn't define \linewidth. If you use a proper class, like article, your setup works.