3

A beamer frame split in two columns must contain one tikz picture (a pie chart) in one column, and two other in the second column.

With the first picture all works fine, but adding the other two causes the compiler to stop (Emergency stop).

I have tried duplicating the exact same tikzpicture code of the one showing, but it still doesn't work.

Here is the functioning code with a comment in place of where the additional two pie charts should be.

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{tikz}
\begin{document}
\begin{frame}

\def\angle{0}
\def\radius{3}
\def\cyclelist{{"blue","red","green"}}
\newcount\cyclecount \cyclecount=-1
\newcount\ind \ind=-1

\begin{columns}
   \column{.5\textwidth}

\begin{figure}
   \tiny
   \centering
\begin{tikzpicture}[scale=.3]
  \foreach \percent/\name in {
      66.7/Soci,
      30/Villani,
      3.3/Pareggio
    } {
      \ifx\percent\empty\else               % If \percent is empty, do nothing
        \global\advance\cyclecount by 1     % Advance cyclecount
        \global\advance\ind by 1            % Advance list index
        \ifnum3<\cyclecount                 % If cyclecount is larger than list
          \global\cyclecount=0              %   reset cyclecount and
          \global\ind=0                     %   reset list index
        \fi
        \pgfmathparse{\cyclelist[\the\ind]} % Get color from cycle list
        \edef\color{\pgfmathresult}         %   and store as \color
        % Draw angle and set labels
        \draw[fill={\color!50},draw={\color}] (0,0) -- (\angle:\radius)
          arc (\angle:\angle+\percent*3.6:\radius) -- cycle;
        \node at (\angle+0.5*\percent*3.6:0.7*\radius) {\percent\,\%};
        \node[pin=\angle+0.5*\percent*3.6:\name]
          at (\angle+0.5*\percent*3.6:\radius) {};
        \pgfmathparse{\angle+\percent*3.6}  % Advance angle
        \xdef\angle{\pgfmathresult}         %   and store in \angle
      \fi
    };
\end{tikzpicture}
\caption{Random vs Random}
\end{figure}

\column{.5\textwidth}


%%% HERE GOES THE ADDITIONAL PICTURE(S)


\end{columns}
\end{frame}
\end{document}
1

You need to restart the counters \cyclecount and \ind for each picture that will use them:

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{tikz}
\begin{document}
\begin{frame}

\def\angle{0}
\def\radius{3}
\def\cyclelist{{"blue","red","green"}}
\newcount\cyclecount 
\cyclecount=-1
\newcount\ind 
\ind=-1

\begin{columns}
   \column{.5\textwidth}

\begin{figure}
   \tiny
   \centering
\begin{tikzpicture}[scale=.3]
  \foreach \percent/\name in {
      66.7/Soci,
      30/Villani,
      3.3/Pareggio%
    } {
      \ifx\percent\empty\else               % If \percent is empty, do nothing
        \global\advance\cyclecount by 1     % Advance cyclecount
        \global\advance\ind by 1            % Advance list index
        \ifnum3<\cyclecount                 % If cyclecount is larger than list
          \global\cyclecount=0              %   reset cyclecount and
          \global\ind=0                     %   reset list index
        \fi
        \pgfmathparse{\cyclelist[\the\ind]} % Get color from cycle list
        \edef\color{\pgfmathresult}         %   and store as \color
        % Draw angle and set labels
        \draw[fill={\color!50},draw={\color}] (0,0) -- (\angle:\radius)
          arc (\angle:\angle+\percent*3.6:\radius) -- cycle;
        \node at (\angle+0.5*\percent*3.6:0.7*\radius) {\percent\,\%};
        \node[pin=\angle+0.5*\percent*3.6:\name]
          at (\angle+0.5*\percent*3.6:\radius) {};
        \pgfmathparse{\angle+\percent*3.6}  % Advance angle
        \xdef\angle{\pgfmathresult}         %   and store in \angle
      \fi
    };
\end{tikzpicture}
\caption{Random vs Random}
\end{figure}

\column{.5\textwidth}
\cyclecount=-1
\ind=-1
\begin{figure}
   \tiny
   \centering
\begin{tikzpicture}[scale=.3]
  \foreach \percent/\name in {
      66.7/Soci,
      30/Villani,
      3.3/Pareggio%
    } {
      \ifx\percent\empty\else               % If \percent is empty, do nothing
        \global\advance\cyclecount by 1     % Advance cyclecount
        \global\advance\ind by 1            % Advance list index
        \ifnum3<\cyclecount                 % If cyclecount is larger than list
          \global\cyclecount=0              %   reset cyclecount and
          \global\ind=0                     %   reset list index
        \fi
        \pgfmathparse{\cyclelist[\the\ind]} % Get color from cycle list
        \edef\color{\pgfmathresult}         %   and store as \color
        % Draw angle and set labels
        \draw[fill={\color!50},draw={\color}] (0,0) -- (\angle:\radius)
          arc (\angle:\angle+\percent*3.6:\radius) -- cycle;
        \node at (\angle+0.5*\percent*3.6:0.7*\radius) {\percent\,\%};
        \node[pin=\angle+0.5*\percent*3.6:\name]
          at (\angle+0.5*\percent*3.6:\radius) {};
        \pgfmathparse{\angle+\percent*3.6}  % Advance angle
        \xdef\angle{\pgfmathresult}         %   and store in \angle
      \fi
    };
\end{tikzpicture}
\caption{Random vs Random}
\end{figure}\par\bigskip

\cyclecount=-1
\ind=-1
\begin{figure}
   \tiny
   \centering
\begin{tikzpicture}[scale=.3]
  \foreach \percent/\name in {
      66.7/Soci,
      30/Villani,
      3.3/Pareggio%
    } {
      \ifx\percent\empty\else               % If \percent is empty, do nothing
        \global\advance\cyclecount by 1     % Advance cyclecount
        \global\advance\ind by 1            % Advance list index
        \ifnum3<\cyclecount                 % If cyclecount is larger than list
          \global\cyclecount=0              %   reset cyclecount and
          \global\ind=0                     %   reset list index
        \fi
        \pgfmathparse{\cyclelist[\the\ind]} % Get color from cycle list
        \edef\color{\pgfmathresult}         %   and store as \color
        % Draw angle and set labels
        \draw[fill={\color!50},draw={\color}] (0,0) -- (\angle:\radius)
          arc (\angle:\angle+\percent*3.6:\radius) -- cycle;
        \node at (\angle+0.5*\percent*3.6:0.7*\radius) {\percent\,\%};
        \node[pin=\angle+0.5*\percent*3.6:\name]
          at (\angle+0.5*\percent*3.6:\radius) {};
        \pgfmathparse{\angle+\percent*3.6}  % Advance angle
        \xdef\angle{\pgfmathresult}         %   and store in \angle
      \fi
    };
\end{tikzpicture}
\caption{Random vs Random}
\end{figure}

\end{columns}
\end{frame}
\end{document}

enter image description here

  • Thank you. Strange that this is not needed when the same code is applied to a Latex thesis instead of a beamer presentation. – sowdust Jul 11 '15 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.