Graphics, Figures & Tablesanimate package: Problem with frame size

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
htson
Posts: 2
Joined: Sun Oct 10, 2010 7:16 pm

animate package: Problem with frame size

Post by htson »

I am using animate package for animation with the idea of separating the background of the animation from the particular moving element of the animation. The main motivation is that during the animation, I can change the background information.

The problem that I had is somehow the frame size of the animation changed hence the animation does not look so smooth. I manage to have the following example.

Code: Select all

\documentclass{beamer}

\usetheme{Singapore}
\usepackage{animate}
\usepackage{tikz}

\newcommand\background{}

\newcommand{\animationframe}{%
  \begin{tikzpicture}
    \background
    \draw (0, 0) rectangle +(4, 2);
 \end{tikzpicture}
}

\begin{document}

\begin{frame}
  \frametitle{Simple Animation}

  \begin{center}
    \begin{animateinline}[controls]{12}
      
      \animationframe
      \newframe
      \renewcommand\background{\draw (2,1) node{T};}
      \animationframe
  \end{animateinline}
  \end{center}
\end{frame}
\end{document}
I suppose to create two frames, the first one has only the bound box, and the second one has the bounding box with the T in the middle. The result is in animation-1.pdf, but one can see clearly that the bound box has been resized between the first and the second frame.

If I removed the \renewcommand{...} from the code then (of course) the frame are exactly the same and the bounding box is OK (but of course there is no T in the middle for the second frame anymore).

Strange enough, if I removed the \renewcommand{...} and put some brackets around the second \animationframe, i.e. {\animationframe} then the problem with the bounding box occurred again (see animation-2.pdf).

Any information regarding this matters will be very highly appreciated, in particular, if I misunderstood and misused the animate package for what I am trying to achieve.
Thank you very much.
Best regards
--
Thai Son Hoang
Attachments
animation-2.pdf
Bounding box resized again
(16.71 KiB) Downloaded 263 times
animation-1.pdf
Bounding box resized
(23.71 KiB) Downloaded 224 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

alex
Posts: 32
Joined: Mon May 19, 2008 10:53 am

animate package: Problem with frame size

Post by alex »

The definition of the second frame must be

Code: Select all

\renewcommand\background{\draw (2,1) node{T};}% <-- linebreak must be commented out
\animationframe
Uncommented line breaks are interpreted as space in TeX/LaTeX. This space is inserted left to \animationframe, moving it somewhat to the right. The whole contents of the second frame is then scaled to fit into the box of the first frame by animate, leading to the squeezing effect to be observed when playing the animation.

Alexander
htson
Posts: 2
Joined: Sun Oct 10, 2010 7:16 pm

Re: animate package: Problem with frame size

Post by htson »

Hi Alexander,
Thank you very much. Indeed this newline character is the problem. I am very happy with the result now. Everything works as expected.
Best regards,
Son
Post Reply