7

I've built a beamer presentation in which a TikZ graph is built up sequentially using \pause. Example:

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
        \begin{frame}
                \begin{tikzpicture}[ scale=5 ]
                        \draw (0,0) -- (1,0) node[below] {$f_1$};
                        \pause
                        \draw (0,0) -- (0,1) node[left] {$f_2$};
                        \pause
                        \draw (0,0) -- (0.87,0.5) node[right] {$f_3$};
                \end{tikzpicture}
        \end{frame}
\end{document}

This results in three slides. I want these as three separate images in which each TikZ picture covers an entire "page" or "slide". That is, I want the output slide1.pdf, slide2.pdf and slide3.pdf, and in each of them, the TikZ picture should cover the entire slide.

I could accomplish this by creating three standalone .tex files with a lot of duplicate TikZ code, but I suppose there is a better way.

What is a good solution?

2
  • You could extract them from the beamer presentation using the pdfpages package. You could also use the plain option for the frame environment so that you won't have headers/footers etc.
    – mbork
    Mar 31, 2014 at 12:40
  • This is a tip with \only in use: tex.stackexchange.com/questions/119428/…
    – Malipivo
    Mar 31, 2014 at 13:02

2 Answers 2

18

I'm not sure about the question but I think you're looking for standalone

\documentclass[beamer]{standalone}
\usepackage{tikz}
\begin{document}
        \begin{standaloneframe}
                \begin{tikzpicture}[ scale=5 ]
                        \draw (0,0) -- (1,0) node[below] {$f_1$};
                        \pause
                        \draw (0,0) -- (0,1) node[left] {$f_2$};
                        \pause
                        \draw (0,0) -- (0.87,0.5) node[right] {$f_3$};
                \end{tikzpicture}
        \end{standaloneframe}
\end{document}

produces a three pages/frames pdf document.

enter image description here

You can include them as background in any beamer presentation with \includegraphics[page=x]{your-standalone-file.pdf} where x=1,2,3.

With standaloneframe you don't have to worry about different figure sizes because all of them are equal.

\documentclass{beamer}

\begin{document}
\setbeamertemplate{background}{\includegraphics[page=1]{168685}}
        \begin{frame}{First frame}
        \end{frame}
\setbeamertemplate{background}{\includegraphics[page=2]{168685}}
        \begin{frame}{Second frame}
        \end{frame}
\setbeamertemplate{background}{\includegraphics[page=3]{168685}}
        \begin{frame}{Third frame}
        \end{frame}
\end{document}

enter image description here

1

If you use \documentclass[tikz]{standalone}, then each tikzpicture environment in the document will create a different page.

Then, you can include each page separately in your document. I use a \foreach loop to generate multiple tikzpicture environments and set various toggles and values based on the slide number.

Here's an example of the standalone document.

% Using the 'tikz' option causes each tikz diagram to be displayed on a different page.
\documentclass[tikz]{standalone}
\usepackage{etoolbox}% Provides \newtoggle

\newtoggle{showLines}
\newtoggle{showRegions}

\begin{document}
\foreach \slideNumber in {
    0, % Slide that is never shown. Used to adjust the timing of overlays in Beamer slideshow. 
    0,  % Circle only
    10, % Lines
    20, % Regions (blue)
    30  % Regions (red)
    }{%
    
  \ifnum \slideNumber > 9
      \toggletrue{showLines}
  \fi

  \ifnum \slideNumber > 19
      \toggletrue{showRegions}
  \fi

  \ifnum \slideNumber > 29
      \def\fillColor{blue}
  \else
      \def\fillColor{red}
  \fi

  \tikzset{regions/.style={fill=\fillColor}}

  \begin{tikzpicture}[scale=1.2]

      \iftoggle{showRegions}{
          % Draw shaded regions
          \fill[regions] (0, 1) -- (1, 1) -- (1, 0) -- cycle;
          \fill[regions] (0, 1) -- (-1, 1) -- (-1, 0) -- cycle;
          \fill[regions] (0, -1) -- (1, -1) -- (1, 0) -- cycle;
          \fill[regions] (0, -1) -- (-1, -1) -- (-1, 0) -- cycle;
      }{}% END 'showRegions'

      \iftoggle{showLines}{%
          \draw (0.0, 0.0) -- (1, 1);
          \draw (0.0, 0.0) -- (-1, 1);
          \draw (0.0, 0.0) -- (1, -1);
          \draw (0.0, 0.0) -- (-1, -1);
      }{}% End 'showLines'

      \draw (0,0) circle[radius=1cm];
  \end{tikzpicture}
}

\end{document}

Output enter image description here Note that this PDF has five pages (arranged horizontally).

Here is an example Beamer slideshow that uses the resulting TikZ images:

\documentclass{beamer}

% Access the current Beamer overlay value,
% per https://tex.stackexchange.com/a/55066/153678
\makeatletter
\newcommand*{\overlaynumber}{\number\beamer@slideinframe}
\makeatother

\begin{document}

\begin{frame}

  \begin{columns}
    \begin{column}[T]{0.48\textwidth}
      Here is my first thing to say. There is nothing to see here yet.
      \pause
      \begin{itemize}[<+->]
        \item Now there is a circle.
        \item Crossed by lines.
        \item Add some red corners.
        \item Make them blue.
      \end{itemize}
    \end{column}
    \hfill
    \begin{column}[T]{0.48\textwidth}
      % Start showing the images on the second slide.
      % Set the page of the PDF displayed equal to 
      \includegraphics<2->[page=\overlaynumber]{path/to/tikzoutput.pdf}
    \end{column}
  \end{columns}

\end{frame}

\end{document}

Output enter image description here

3
  • 1
    You don't need \usepackage{graphicx} in the beamer example Dec 5, 2023 at 8:51
  • Thanks. I updated my answer. Is that because Beamer loads it?
    – Paul Wintz
    Dec 5, 2023 at 9:18
  • 1
    Yes, beamer already loads it (same is true for xcolor, amsmath etc.). In theory it does not hurt much to load it again, but users sometimes have the impedimental habit, that if they see such packages in their preambles, they will try to add package options there and then things explode. So best to not show them unnecessary packages. Dec 5, 2023 at 9:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .