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 have a working example here. I want to display tikzpicture and equation one at a time. I don't know how to use only overlay here.

\documentclass{beamer}


\usepackage{tikz}
\usetikzlibrary{shapes, shadows, arrows}

\tikzset{
  basic/.style  = {draw, text width=2cm, drop shadow, font=\sffamily, rectangle},
  root/.style   = {basic, rounded corners=2pt, thin, align=center,
                   fill=green!30},
  level 2/.style = {basic, rounded corners=6pt, thin,align=center, fill=green!60,
                   text width=8em},
  level 3/.style = {basic, thin, align=left, fill=pink!60, text width=6.5em}
}

\mode<presentation>

\begin{document}

\begin{frame}

    \begin{tikzpicture}
      level 1/.style={sibling distance=40mm},
      edge from parent/.style={->,draw},
      >=latex]

    % root of the the initial tree, level 1
    \node[root](start) {Mass Balance};
    \draw[->,very thick](0,0) (1.2,0)--(1.9,0);
    \draw[->,very thick](-1.8,0)--(-1.1,0);
    \draw[->,very thick](0,0.6)--(0,1.4);
    \draw[->,very thick](0,-1.4)--(0,-0.6);
    \node[right of =start,xshift=2.5cm](spatialpos){$q_c(t,x+\Delta x,\tau)$};
    \node[left of =start,xshift=-1.7cm](spatialneg){$q_c(t,x,\tau)$};
    \node[above of =start,yshift=0.8cm](agepos){$c(t,x,\tau+\Delta \tau)$};
    \node[below of =start,yshift=-0.8cm](ageneg){$c(t,x,\tau)$};
    \draw[->,very thick](-4,-3)--(-4,0);
    \draw[->,very thick](-4,-3)--(-0.5,-3);
    \node[below of = ageneg,yshift=0.2cm](spatial){Spatial dim};
    \node[left of = spatialneg,yshift=0.4cm](age){Age dim.};
    \end{tikzpicture}


        \begin{align*}
         \rho \Delta x \Delta y \Delta z \Delta \tau \partial_t c_i(t,x,\tau) \\
        &= \rho \Delta x \Delta y \Delta z \Delta \tau (p_i-d_i)  \\
        &- \rho \Delta y, \Delta z \Delta \tau [q_{i,x}(t,x+\Delta x/2, y, z, \tau)\\
        &\qquad - q_{i,x}(t,x - \Delta x/2, y, z, \tau)]\\
        &- \rho \Delta x, \Delta z \Delta  \tau [q_{i,y}(t,x,y+\Delta y/2, y, z, \tau)\\
        &\qquad - q_{i,y}(t,x,y - \Delta y/2, z, z, \tau)]\\
        &- \rho \Delta x \Delta y \Delta \tau[q_{i,z}(t,x,y,z+\Delta z/2, \tau) \\
        &\qquad - q_{i,z}(t,x,y,z-\Delta z/2, \tau)]\\
            &- \rho \Delta x \Delta y \Delta \tau[q_{i,z}(t,x,y,z+\Delta z/2, \tau) \\
        &\qquad - q_{i,z}(t,x,y,z-\Delta z/2, \tau)] \\
        \end{align*}

\end{frame}

\end{document}
share|improve this question

1 Answer 1

up vote 4 down vote accepted

The syntax for \only is

\only<overlay specification>{text} 

or

\only{text}<overlay specification>

and you can use virtually anything (in particular, a tikzpicture or a displayed equation) in the place os text.

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{shapes, shadows, arrows}

\tikzset{
  basic/.style  = {draw, text width=2cm, drop shadow, font=\sffamily, rectangle},
  root/.style   = {basic, rounded corners=2pt, thin, align=center,
                   fill=green!30},
  level 2/.style = {basic, rounded corners=6pt, thin,align=center, fill=green!60,
                   text width=8em},
  level 3/.style = {basic, thin, align=left, fill=pink!60, text width=6.5em}
}

\mode<presentation>

\begin{document}

\begin{frame}

    \only<1>{\begin{tikzpicture}
      level 1/.style={sibling distance=40mm},
      edge from parent/.style={->,draw},
      >=latex]

    % root of the the initial tree, level 1
    \node[root](start) {Mass Balance};
    \draw[->,very thick](0,0) (1.2,0)--(1.9,0);
    \draw[->,very thick](-1.8,0)--(-1.1,0);
    \draw[->,very thick](0,0.6)--(0,1.4);
    \draw[->,very thick](0,-1.4)--(0,-0.6);
    \node[right of =start,xshift=2.5cm](spatialpos){$q_c(t,x+\Delta x,\tau)$};
    \node[left of =start,xshift=-1.7cm](spatialneg){$q_c(t,x,\tau)$};
    \node[above of =start,yshift=0.8cm](agepos){$c(t,x,\tau+\Delta \tau)$};
    \node[below of =start,yshift=-0.8cm](ageneg){$c(t,x,\tau)$};
    \draw[->,very thick](-4,-3)--(-4,0);
    \draw[->,very thick](-4,-3)--(-0.5,-3);
    \node[below of = ageneg,yshift=0.2cm](spatial){Spatial dim};
    \node[left of = spatialneg,yshift=0.4cm](age){Age dim.};
    \end{tikzpicture}}


        \only<2>{\begin{align*}
         \rho \Delta x \Delta y \Delta z \Delta \tau \partial_t c_i(t,x,\tau) \\
        &= \rho \Delta x \Delta y \Delta z \Delta \tau (p_i-d_i)  \\
        &- \rho \Delta y, \Delta z \Delta \tau [q_{i,x}(t,x+\Delta x/2, y, z, \tau)\\
        &\qquad - q_{i,x}(t,x - \Delta x/2, y, z, \tau)]\\
        &- \rho \Delta x, \Delta z \Delta  \tau [q_{i,y}(t,x,y+\Delta y/2, y, z, \tau)\\
        &\qquad - q_{i,y}(t,x,y - \Delta y/2, z, z, \tau)]\\
        &- \rho \Delta x \Delta y \Delta \tau[q_{i,z}(t,x,y,z+\Delta z/2, \tau) \\
        &\qquad - q_{i,z}(t,x,y,z-\Delta z/2, \tau)]\\
            &- \rho \Delta x \Delta y \Delta \tau[q_{i,z}(t,x,y,z+\Delta z/2, \tau) \\
        &\qquad - q_{i,z}(t,x,y,z-\Delta z/2, \tau)] \\
        \end{align*}}

\end{frame}

\end{document}

enter image description here

share|improve this answer
    
Thank you so much for your prompt response. I didn't know we could put the whole section into curly braces where we want to apply the \only overlay. –  Jdbaba Jun 21 '13 at 0:26
1  
@Jdbaba yes, the syntax for \only is \only<overlay specification>{text} or also \only{text}<overlay specification>. –  Gonzalo Medina Jun 21 '13 at 0:28
1  
@Jdbaba I've added this remark to my answer. –  Gonzalo Medina Jun 21 '13 at 0:37
    
Can I ask you how did you create the animated (gif) image ? Thats very helpful to show how the code works. –  Jdbaba Jun 21 '13 at 2:23
    
@Jdbaba I first produce the PDF and then I use something like this convert -verbose -delay 120 -loop 0 -density 300 <file>.pdf <file>.gif (changing the value for delay, if necessary) in the command line (this requires ImageMagick installed). –  Gonzalo Medina Jun 21 '13 at 2:28

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.