我想使用该ocgx
包创建一个带有按钮的 pdf,单击该按钮时其颜色会从红色变为绿色,再变为不可见,再变为红色(依此类推)。我尝试了以下操作:
\documentclass{beamer}
\usepackage{xcolor}
\usepackage{ocgx}
\begin{document}
\begin{frame}
\begin{ocg}{Bul01r}{ocg01r}{1}\actionsocg{ocg01g ocg01r}{}{}{\textcolor{red}{\textbullet}}\end{ocg} \hspace{-0.32cm}
\begin{ocg}{Bul01g}{ocg01g}{0}\actionsocg{ocg01g}{}{}{\textcolor{green}{\textbullet}}\end{ocg}
\end{frame}
\end{document}
但这只能实现从红色变为绿色再变回红色。如何才能得到具有三种状态的按钮?
答案1
这可以通过ocgx2
提供的包单选按钮组(ocg
环境选项radiobtngrp=<name>
)。在属于同一单选按钮组的所有 OCG(PDF 层)中,一次只能启用一个,自动隐藏先前启用的 OCG。这允许构建具有任意循环长度的循环依赖性的可点击按钮。
以下示例链接了红色、绿色、蓝色、无色状态。
\documentclass{beamer}
\usepackage{xcolor}
\usepackage{ocgx2}
\begin{document}
\begin{frame}
\makebox[0pt][l]{%
\begin{ocg}[radiobtngrp=myBullets]{Bul01r}{ocg01r}{1}\showocg{ocg01g}{\textcolor{red}{\textbullet}}\end{ocg}%
}%
\makebox[0pt][l]{%
\begin{ocg}[radiobtngrp=myBullets]{Bul01g}{ocg01g}{0}\showocg{ocg01b}{\textcolor{green}{\textbullet}}\end{ocg}%
}%
\makebox[0pt][l]{%
\begin{ocg}[radiobtngrp=myBullets]{Bul01b}{ocg01b}{0}\showocg{ocg01x}{\textcolor{blue}{\textbullet}}\end{ocg}%
}%
\begin{ocg}[radiobtngrp=myBullets]{Bul01x}{ocg01x}{0}\showocg{ocg01r}{$\circ$}\end{ocg}%
\end{frame}
\end{document}
*.aux
(如果ocgx
之前使用过该包,则可能需要删除第一个。)
不使用单选按钮组也可以实现相同的效果,使用命令\actionsocg{}{}{}{}
而不是\showocg{}{}
原始帖子中更简单的命令。但同样,这需要ocgx2
包,它确保根据与它们关联的 OCG 的可见性正确启用/禁用位于不同层上的切换链接:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% version without radio button group, using \actionsocg
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass{beamer}
\usepackage{xcolor}
\usepackage{ocgx2}
\begin{document}
\begin{frame}
\makebox[0pt][l]{%
\begin{ocg}{Bul01r}{ocg01r}{1}\actionsocg{}{ocg01g}{ocg01r}{\color{red}\textbullet}\end{ocg}%
}%
\makebox[0pt][l]{%
\begin{ocg}{Bul01g}{ocg01g}{0}\actionsocg{}{ocg01b}{ocg01g}{\color{green}\textbullet}\end{ocg}%
}%
\makebox[0pt][l]{%
\begin{ocg}{Bul01b}{ocg01b}{0}\actionsocg{}{ocg01x}{ocg01b}{\color{blue}\textbullet}\end{ocg}%
}%
\begin{ocg}{Bul01x}{ocg01x}{0}\actionsocg{}{ocg01r}{ocg01x}{$\circ$}\end{ocg}%
\end{frame}
\end{document}