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}
Best Answer
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 atikzpicture
.The following doesn't produce any shifting:
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 theadjustbox
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.