Beamer:一张 tikzpicture 工作正常,两张则紧急停止

Beamer:一张 tikzpicture 工作正常,两张则紧急停止

分成两列的 beamer 框架必须在一列包含一个 tikz 图片(饼图),在第二列包含另外两张 tikz 图片。

第一张图片一切正常,但添加另外两张图片会导致编译器停止(紧急停止)。

我尝试复制所显示完全相同的 tikzpicture 代码,但它仍然不起作用。

以下是功能代码,其中在另外两个饼图的位置处添加了注释。

\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

您需要重新启动计数器\cyclecount,并对\ind每张图片使用它们:

\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}

在此处输入图片描述

相关内容