10

I'm preparing a beamer presentation to show some basic TikZ stuff. I would like to have a two columns slide, where on the left I have the TikZ figure, and on the right the generating code. BUT, I also want the code to be uncovered set by step, that is, whenever a feature of the figure is uncovered, I want the corresponding piece of code to be uncovered.

Something like:

\begin{frame}[fragile]
  \begin{minipage}{0.10\linewidth}
    \begin{center}
      \begin{tikzpicture}
        \draw<1-> (-1.5,0) -- (1.5,0); 
        \draw<2-> (0,-1.5) -- (0,1.5); 
      \end{tikzpicture}
    \end{center}
  \end{minipage}
  \begin{minipage}{0.85\linewidth}
\begin{verbatim}
      \begin{tikzpicture}
        \draw (-1.5,0) -- (1.5,0); 
        \draw (0,-1.5) -- (0,1.5); 
      \end{tikzpicture}
\end{verbatim}
 \end{minipage}
\end{frame}

The problem is that I couldn't neither manage to use the uncover inside the verbatim nor use the verbatim inside an uncover...

What is the right practice?

Caramdir
  • 89,023
  • 26
  • 255
  • 291
Dror
  • 22,613

2 Answers2

3

Herbert's answer was helpful! However, for the sake of completeness, here's the correction of the second part of my code from the question:

\begin{minipage}{0.85\linewidth}
   \begin{semiverbatim}\small
       \uncover<1->{\\begin\{tikzpicture\} }
       \uncover<1->{  \alert<1>{\\draw [step=.2cm,gray!50,thin] (-1.5,-1.5) 
                      grid (1.5,1.5);}}
       \uncover<2->{  \alert<2>{\\draw (-1.5,0) -- (1.5,0);} }
       \uncover<3->{  \alert<3>{\\draw (0,-1.5) -- (0,1.5);}}
       \uncover<4->{  \alert<4>{\\draw[red,line width=2pt] (0,0) circle (.8cm);}}
       \uncover<5->{  \alert<5>{\\draw[green,line width=2pt] (-1,-1) 
                      rectangle (1,1);}}
       \uncover<6->{  \alert<6>{\\draw[blue,line width=2pt] (-.5,-.5) 
                      parabola (1,1);}}
       \uncover<1->{\\end\{tikzpicture\}}
   \end{semiverbatim}
\end{minipage}

Thanks you all!

Dror
  • 22,613
0

I had the same problem. I did one of the following in my presentation, each solution was used for a different problem (I'm sorry, I don't remember exactly what is used for what)

  • I wrapped the tikz figure with \uncover. Note that this is the only case that I did what I think you tried to do.
  • I used the \only command which is not recommended.
  • I think that I also placed everything inside a single tikz figure but I'm not sure.

Hope this is of any help.

Yotam
  • 7,109