tikz 键内的数字条件?

tikz 键内的数字条件?

我想设置一个演示文稿,其中显示同一张 tikz 图片的不同部分,具体取决于一个(可能更多)整数变量的值。我首先尝试使用固定图片,并根据幻灯片编号更改其不同路径元素的可见性,但这无法扩展。一帧中大约有 150 张幻灯片。

然后,我尝试了另一种方法,将整个图片定义为一个宏,每张幻灯片调用一次,根据全局条件显示不同的部分。但是,我未能在键中包含条件。

这是一个不太简单且肯定不起作用的示例,展示了我的失败。任何帮助都将不胜感激:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{链}

        \tikz设置{%
            invisible/.style={opacity=0},
        }

\newcounter{数量}


\newcommand\myPicture{
\开始{tikzpicture}
  \begin{范围}[开始链 = 向右]
      \node[绘制,圆圈,链上] {
      \ifnum \value{计数} > 1
      {Count 大于 s}
      \fi};
  \node[draw, circle, on chain,opacity=0] {B};
  \node[draw, circle, on chain, \ifnum \value{count} > 1\relax invisible\fi] {C};
    \node[绘制,圆圈,在链上] {D};
  \结束{范围}
\结束{tikzpicture}
}

\开始{文档}


\开始{框架}
\setcounter{计数}{2}
\ifnum \value{计数} > 1
{计数大于 1}
\fi
\ifnum \value{计数} > 2
{Count 大于 s}
\fi



\仅有的{
\setcounter{计数}{2}
\我的照片
}

\仅有的{
\setcounter{计数}{1}
\我的照片
}
\仅有的{
\setcounter{计数}{2}
\我的照片
}
\结束{框架}
\结束{文档}

这是一个最小的例子,给出了预期结果的概念,但当然没有实现它:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{链}
\newcounter{数量}
\newcommand\myPicture{
\开始{tikzpicture}
  \begin{范围}[开始链 = 继续以下]
      \node[draw, rectangle, on chain] {仅当计数器在 1 到 3 之间时显示};
  \node[draw, rectangle, on chain] {仅当计数器为负时显示}; %
  \node[draw, rectangle, on chain] {仅当计数器在 100 到 200 之间时显示};
  \node[draw, circle, on chain] {仅当计数器在 3 到 20 范围内时};
  \结束{范围}
\结束{tikzpicture}
}

\开始{文档}
\开始{框架}
\only{\setcounter{count}{-3}\myPicture}
\only{\setcounter{count}{105}\myPicture}
\only{\setcounter{count}{39}\myPicture}
\only{\setcounter{count}{2}\myPicture}
\结束{框架}
\结束{文档}

答案1

我对和都非常不熟悉beamertikz不太明白它们\only应该做什么)但也许这可以朝着你想要的方向发展:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains}
\newcounter{count}

% helper macro:
\long\def\GobToSemiColon #1;{}

\newcommand\myPicture{
\begin{tikzpicture}
  \begin{scope}[start chain = going below]
  \ifnum\value{count}<1 \expandafter\GobToSemiColon\fi
  \ifnum\value{count}>3 \expandafter\GobToSemiColon\fi
  \node[draw, rectangle, on chain] {display only when counter is between
    1 and 3};

  \ifnum\value{count}>-1 \expandafter\GobToSemiColon\fi
  \node[draw, rectangle, on chain] {display only when counter is
    negative}; 

  \ifnum\value{count}<100 \expandafter\GobToSemiColon\fi
  \ifnum\value{count}>200 \expandafter\GobToSemiColon\fi  
  \node[draw, rectangle, on chain] {display only if counter is between
    100 and 200};

  \ifnum\value{count}<3 \expandafter\GobToSemiColon\fi
  \ifnum\value{count}>20 \expandafter\GobToSemiColon\fi
  \node[draw, circle, on chain] {only when counter is in the range 3 to 20};
  \end{scope}
\end{tikzpicture}
}

\begin{document}
\begin{frame}
\only{\setcounter{count}{-3}\myPicture}
\only{\setcounter{count}{105}\myPicture}
\only{\setcounter{count}{39}\myPicture}
\only{\setcounter{count}{2}\myPicture}
\only{\setcounter{count}{5}\myPicture}
\end{frame}
\end{document}

投影机

答案2

我尝试通过引入tikzpicture依赖于整数值的变化来修改您的最小示例。为了使绘图稳定的在所有幻灯片上,我都加入了一个\clip动作。

在此处输入图片描述

我无法弄清楚您的问题是什么,我想您的问题和我给出的答案之间的时间间隔不会有所帮助。如果您仍在寻找其他内容,请告诉我。

\documentclass{beamer}

\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{chains}

\newcounter{count}
\newcommand{\myPicture}[1]{%
  \begin{tikzpicture}
    \clip (-5, -3.3) rectangle (5, 3.3);
    \begin{scope}[start chain = going below]
      \ifnum#1<4
      \node[draw, rectangle, on chain, fill=yellow]
      {display only when counter is between 1 and 3};
      \node[on chain, red!50!black, fill=blue!50!black!10,
      inner sep=2ex, rounded corners, scale=1.25, rotate={(#1-1)*10}]
      {counter=#1};
      \else
      \ifnum#1<6
      \node[draw, rectangle, on chain, rounded corners]
      {display only when counter is 4 or 5};
      \else
      \ifnum#1=6
      \node[draw, rectangle, on chain]
      {display only when counter is 6 or 7};
      \else
      \ifnum#1=7
      \node[draw, rectangle, on chain,
      label={[fill=orange]-35:not so identical}]
      {display only when counter is 6 or 7};      
      \else
      \node[draw, very thick, blue, circle, on chain]
      {only when counter is 8, or \ldots};
      \fi\fi\fi\fi
  \end{scope}
\end{tikzpicture}
}

\begin{document}

\begin{frame}{Introduction}
  Some information on the first frame and an example with multiple slides based on a TikZ picture on the second one.
\end{frame}


\begin{frame}{A changing image on this frame}
  The inspiring test: (on slide \thepage\ -- total counting)

  \bigskip
  
  \only<1> {\myPicture{1}}
  \only<2> {\myPicture{2}}
  \only<3> {\myPicture{3}}
  \only<4-5> {\myPicture{4}}
  \only<6> {\myPicture{6}}
  \only<7> {\myPicture{7}}
  \only<8> {\myPicture{8}}
\end{frame}
\end{document}  

相关内容