使用 ocgx 切換顏色

使用 ocgx 切換顏色

我想使用該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}

相關內容