Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
\pgfplotsset{width=\sz,compat=newest}

\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
]
\addplot
coordinates {(1930,50e6) (1940,33e6)
(1950,40e6) (1960,50e6) (1970,70e6)};
\addplot
coordinates {(1930,38e6) (1940,42e6)
(1950,43e6) (1960,45e6) (1970,65e6)};
\addplot
coordinates {(1930,15e6) (1940,12e6)
(1950,13e6) (1960,25e6) (1970,35e6)};
\addplot
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?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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

share|improve this answer
    
Thanks, my bad. Actually, I was using a different class; but for the example I decided to use a minimal to reproduce the error. However, your answer give me the hint to why it wasn't working. :) –  adn Nov 24 '11 at 13:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.