# Tikz figure in Beamer shifting way to the right of the frame

I'm trying to include a tikz drawing into a Beamer slide. When I do it like this:

\begin{frame}
\frametitle{Overview}
\input{smartservice-diagram.tex}
\end{frame}


the image is way too big. I tried this:

\begin{frame}
\frametitle{Overview}
\resizebox{6in}{!}{\input{smartservice-diagram.tex}}
\end{frame}


and the image gets shrunk down but it gets shifted way over to the right of the slide. It's so far over that part of the image goes off the right of the slide. If I make the resize box a little bigger the image actually slides all the way off the right side. If I make it small the shrunken image moves back over to the left.

I tried to create a standalone document with the smartservice-diagram.tex and using the \resizebox and it works just fine (no extra white space on the left of the diagram). So it looks like something with Beamer that I'm missing.

Any idea what I have wrong?

EDIT: This is not only beamer exclusive, it happens simply using resizebox or also scalebox. I put it inside a figure, but outside a figure also fails. I attach a MWE:

\begin{figure}[htbp]
\resizebox{\linewidth}{!}{
\tikzstyle{scheme} = [draw = black, fill = black!10, thin, rectangle, minimum width = 15pt, minimum height = 10pt]
\begin{tikzpicture}
\node (n1) [scheme] {};
\node (n2) [scheme, at = (n1.east), right = 12pt] {};
\node (n3) [scheme, at = (n2.east), right = 12pt] {};
\node (n4) [scheme, at = (n3.east), right = 12pt] {};
\end{tikzpicture}
}
\caption{Test}
\end{figure}

-
For questions like this, it's a really good idea to provide a minimal working example (MWE), that is a small, complete document that demonstrates the behaviour you describe. Such a MWE makes it a lot easier for other to help, as it saves them the trouble of coming up with a document that reproduces the issue. –  Jake Aug 19 '11 at 2:41
Thanks. Good suggestion. I tried to do that last night and have so far been unable to come up with anything any simpler than the whole diagram that I've created. That would be too big to post here and I'd have to make labels and things more generic. I'll play around with it a little more to try to come up with a small example that has the same behavior that I'm observing. –  Dave Kincaid Aug 19 '11 at 18:58
@Dave: is it solved, or do you have an MWE? –  Stefan Kottwitz Sep 4 '11 at 15:19
No. Never got it solved and couldn't produce an MWE. My MWE is the full diagram which is too big (and proprietary) to post here. I ended up creating the drawing in its own document, exporting it to an image and importing the image into my Beamer slide. At least I could position it and resize it. I wish I could figure out the problem, but can't spend the time on it now. –  Dave Kincaid Sep 4 '11 at 15:27
@juanmah, @DaveKincaid: This is most likely just caused by added spaces. You need to add a % if a line ends with { and sometimes also with } to avoid that the line break is taken as a space. There might be some leading and trailing spaces in the input file as well. Try to add \ignorespaces before and \unskip afterwards. –  Martin Scharrer Sep 23 '11 at 15:11

This is most likely just caused by added spaces. You need to add a % if a line ends with { and sometimes also with } to avoid that the line break is taken as a space. Note that \tikzstyle is deprecated and also requires a % after the ] if it is used outside a tikzpicture.

The following doesn't produce any shifting:

\begin{figure}
\resizebox{\linewidth}{!}{%
\begin{tikzpicture}[scheme/.style={draw = black, fill = black!10, thin, rectangle, minimum width = 15pt, minimum height = 10pt}]
\node (n1) [scheme] {};
\node (n2) [scheme, at = (n1.east), right = 12pt] {};
\node (n3) [scheme, at = (n2.east), right = 12pt] {};
\node (n4) [scheme, at = (n3.east), right = 12pt] {};
\end{tikzpicture}%
}%
\caption{Test}
\end{figure}


There might be some leading and trailing spaces in the input file as well. Try to add \ignorespaces before and \unskip afterwards.

A further cause might be a paragraph indent which can be removed by placing \noindent before the content. You can also use \begin{adjustbox}{width=\linewidth} .. \end{adjustbox} from the adjustbox package for the scaling. It is more efficient than \resizebox and also allows special content like verbatim. It adds the \noindent by itself to play it save.

-

I don't get any unexpected behavior in the figure environment with the article class. This is because the figure environment sets the indent to zero.

Outside the figure environment the indent is added to the left, so the \linewidth wide object will go beyond the right margin; indeed I get the message

Overfull \hbox (15.0pt too wide) in paragraph at lines 7--19


which is precisely the indent amount.

Other possible sources for spurious spaces are pointed out by Martin.

-