Including TikZ image (with external inputs) inside adjustbox adds horisontal spacing, why?

I'm working on my masters thesis and so I have a bunch of tikz files that I want to include in the thesis. This I do by using adjustbox to limit the size to \textwidth as such \adjustbox{max width=\textwidth,bgcolor=blue}{\input{test.tikz}}.

Now my problem is that I have created external files containing common draw commands in order to creating multiple UML like diagrams and memory diagrams easier... this however, for some reason, adds padding to the including picture! Why, and what can I do to avoid it?

Example: The test file "test.ext" used in the example only contains 100x5 '%'s so nothing really should be included in the final image?

Code:

\adjustbox{max width=\textwidth,bgcolor=blue}{
\input{test.ext}                              <-- this causes the problem
\begin{tikzpicture}[]
\draw[fill=blue!20] (0,0) rectangle (3,1);
\end{tikzpicture}
}


Result:

.

-
I am guessing spurious spaces, add a % at the end of the lines doing the \input and starting the \adjustbox. –  Roelof Spijker Apr 4 '12 at 14:53
I'm the author of adjustbox. The issue are indeed spurious spaces as shown in Torbjørn T.s answer below. This use-case looks also like it could benefit from my other package (and class) standalone. With it you can compile the picture on its own and include it using \includestandalone[<options>]{<filename>}. –  Martin Scharrer Apr 4 '12 at 21:33

The linebreak after \input gives the extra space, which can be removed by adding a % at the end of that line. Similarly, you can add % after \adjustbox{ and \end{tikzpicture} to remove the remaining space.

\documentclass{article}
\begin{document}
\input{testinp}
\begin{tikzpicture}[]
\draw[fill=blue!20] (0,0) rectangle (3,1);
\end{tikzpicture}
}
\input{testinp}%
\begin{tikzpicture}[]
\draw[fill=blue!20] (0,0) rectangle (3,1);
\end{tikzpicture}%
}
\end{document}


As commented by Martin, the adjustbox environment ignores spaces at its beginning and end, so the following will give the same result as the second \adjustbox in the above example.

\begin{adjustbox}{max width=\textwidth,bgcolor=blue}
\input{testinp}%
\begin{tikzpicture}[]
\draw[fill=blue!20] (0,0) rectangle (3,1);
\end{tikzpicture}


For reference, a few questions related to end-of-line %s:

-
Thanks, I just saw this question and wanted to post the same answer ;-) Note that there is also the adjustbox environment which ignores spaces at the beginning and end of the content. However the % after \input{..} is still required then. –  Martin Scharrer Apr 4 '12 at 21:30
@MartinScharrer Thanks, I added that to the answer. –  Torbjørn T. Apr 4 '12 at 22:10