使用 ocgx 切换颜色-多个按钮

使用 ocgx 切换颜色-多个按钮

编辑:问题的第一次描述不够好,请注意最后的编辑。

这里我询问了如何使用 ocgx 切换颜色。解决方案如下:

\documentclass{beamer}
\usepackage{xcolor}
\usepackage{ocgx2}

\begin{document}
\begin{frame}
  \makebox[0pt][l]{%
    \begin{ocg}{Bul01r}{ocg01r}{1}\actionsocg{ocg01r ocg01g}{}{}{\textcolor{red}{\textbullet}}\end{ocg}%
  }%
  \makebox[0pt][l]{%
    \begin{ocg}{Bul01g}{ocg01g}{0}\actionsocg{ocg01g ocg01b}{}{}{\textcolor{green}{\textbullet}}\end{ocg}%
  }%
  \makebox[0pt][l]{%
    \begin{ocg}{Bul01b}{ocg01b}{0}\actionsocg{ocg01b ocg01x}{}{}{\textcolor{blue}{\textbullet}}\end{ocg}%
  }%
  \begin{ocg}{Bul01x}{ocg01x}{0}\actionsocg{ocg01x ocg01r}{}{}{$\circ$}\end{ocg}%
\end{frame}
\end{document}

现在我想让两个(或更多)按钮互相影响(即,如果按钮 1 是红色,按钮 2 是绿色,单击其中一个按钮时,按钮 1 变为绿色,按钮 2 变为蓝色;其他组合也是如此)。我不知道如何做到这一点,因为当我单击按钮 1 时,按钮 1 并“不知道”按钮 2 是什么颜色。

编辑:我似乎没有充分描述我的问题。我想要的是(例如)四个按钮排列成 2 行 2 列,这样每个按钮都会影响自身以及同一行和同一列中的两个按钮(即一个按钮不会影响所有其他按钮)。主要目标是对排列在矩形中的任意数量的按钮执行此操作。

答案1

看起来像是让每个按钮循环显示所有四种颜色(红色、绿色、蓝色、无色),但每个按钮的颜色都相对于其左边的邻居偏移一位。

可以点击任意按钮来推进循环(打开分享LaTeX):

\documentclass{beamer}
\usepackage{xcolor}
\usepackage{ocgx2}
\usepackage{multido}

\begin{document}

\begin{frame}
  \multido{}{8}{
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % 1st button
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \makebox[0pt][l]{%
      \begin{ocg}[radiobtngrp=myBullets]{state 1}{state1}{1}\showocg{state2}{\textcolor{red}{\textbullet}}\end{ocg}%
    }%
    \makebox[0pt][l]{%
      \begin{ocg}[radiobtngrp=myBullets]{state 2}{state2}{0}\showocg{state3}{\textcolor{green}{\textbullet}}\end{ocg}%
    }%
    \makebox[0pt][l]{%
      \begin{ocg}[radiobtngrp=myBullets]{state 3}{state3}{0}\showocg{state4}{\textcolor{blue}{\textbullet}}\end{ocg}%
    }%
    \begin{ocg}[radiobtngrp=myBullets]{state 4}{state4}{0}\showocg{state1}{$\circ$}\end{ocg}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % 2nd button
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \makebox[0pt][l]{%
      \begin{ocg}[radiobtngrp=myBullets]{state 4}{state4}{0}\showocg{state1}{\textcolor{red}{\textbullet}}\end{ocg}%
    }%
    \makebox[0pt][l]{%
      \begin{ocg}[radiobtngrp=myBullets]{state 1}{state1}{1}\showocg{state2}{\textcolor{green}{\textbullet}}\end{ocg}%
    }%
    \makebox[0pt][l]{%
      \begin{ocg}[radiobtngrp=myBullets]{state 2}{state2}{0}\showocg{state3}{\textcolor{blue}{\textbullet}}\end{ocg}%
    }%
    \begin{ocg}[radiobtngrp=myBullets]{state 3}{state3}{0}\showocg{state4}{$\circ$}\end{ocg}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % 3rd button
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \makebox[0pt][l]{%
      \begin{ocg}[radiobtngrp=myBullets]{state 3}{state3}{0}\showocg{state4}{\textcolor{red}{\textbullet}}\end{ocg}%
    }%
    \makebox[0pt][l]{%
      \begin{ocg}[radiobtngrp=myBullets]{state 4}{state4}{0}\showocg{state1}{\textcolor{green}{\textbullet}}\end{ocg}%
    }%
    \makebox[0pt][l]{%
      \begin{ocg}[radiobtngrp=myBullets]{state 1}{state1}{1}\showocg{state2}{\textcolor{blue}{\textbullet}}\end{ocg}%
    }%
    \begin{ocg}[radiobtngrp=myBullets]{state 2}{state2}{0}\showocg{state3}{$\circ$}\end{ocg}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % 4th button
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \makebox[0pt][l]{%
      \begin{ocg}[radiobtngrp=myBullets]{state 2}{state2}{0}\showocg{state3}{\textcolor{red}{\textbullet}}\end{ocg}%
    }%
    \makebox[0pt][l]{%
      \begin{ocg}[radiobtngrp=myBullets]{state 3}{state3}{0}\showocg{state4}{\textcolor{green}{\textbullet}}\end{ocg}%
    }%
    \makebox[0pt][l]{%
      \begin{ocg}[radiobtngrp=myBullets]{state 4}{state4}{0}\showocg{state1}{\textcolor{blue}{\textbullet}}\end{ocg}%
    }%
    \begin{ocg}[radiobtngrp=myBullets]{state 1}{state1}{1}\showocg{state2}{$\circ$}\end{ocg}
  }
\end{frame}
\end{document}

相关内容