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 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:

here.

share|improve this question
    
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
add comment

1 Answer 1

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.

enter image description here

\documentclass{article}
\usepackage{tikz,adjustbox}
\begin{document}
\adjustbox{max width=\textwidth,bgcolor=blue}{
   \input{testinp}
  \begin{tikzpicture}[]
    \draw[fill=blue!20] (0,0) rectangle (3,1);
  \end{tikzpicture}
}
\adjustbox{max width=\textwidth,bgcolor=blue}{%
   \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}
\end{adjustbox}

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

share|improve this answer
    
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
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.