我有一个“3D 按钮”数组(该数组将包含 100 多个按钮)。单击某个按钮时,我想显示“按钮的 OCG”并隐藏其他 OCG。我该怎么做?
下面是我想要的一个例子,但是我不知道如何隐藏其他值。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{ocgx}
\tikzstyle{button}=[minimum width=15mm, rounded corners, draw=white!50!black!100, bottom color=white]
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tikzpicture}
\node[button, show ocg=0] (0) {$\mathbf{0}$};
\foreach \x [evaluate={\xi=int(\x-1);}] [evaluate={\i=int(\x);}] in {1,2,...,7} {\node[button, show ocg=\i] [right of=\xi, xshift=20pt] (\x) {$\mathbf{\x}$};}
\foreach \x [evaluate={\xi=int(\x-8);}] [evaluate={\i=int(\x);}] in {8,9,...,11} {\node[button, show ocg=\i] [below of=\xi] (\x) {$\mathbf{\x}$};}
\end{tikzpicture}
\begin{center}
\begin{tikzpicture}
\begin{ocg}{OCG 0}{0}{1}\node {$0,0,0,0$};\end{ocg}
\foreach \x in {1,2,...,11} {\begin{ocg}{OCG \x}{\x}{0}\node {$\x,\x,\x,\x$};\end{ocg}};
\end{tikzpicture}
\end{center}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
答案1
更换包ocgx2
实现单选按钮组:
从texdoc ocgx2
:
可以使用新选项将图层添加到一个或多个单选按钮组
radiobtngrp
。单选按钮组内的所有图层中一次只能启用一个。启用图层(例如在 PDF 查看器的“图层”选项卡中)会自动隐藏先前可见的图层。
只需将数组中的所有 OCG 添加到相同的单选按钮组,例如:
\begin{ocg}[radiobtngrp=myRadioButtons]{OCG 0}{0}{1}...\end{ocg}
完整示例(修改自OP):
(如果ocgx
之前使用过,*.aux
必须先删除。)
打开分享LaTeX
\documentclass{article}
%\usepackage{tikz}
%\usetikzlibrary{ocgx}
\usepackage[tikz]{ocgx2}
\tikzstyle{button}=[minimum width=15mm, rounded corners, draw=white!50!black!100, bottom color=white]
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tikzpicture}
\node[button, show ocg=0] (0) {$\mathbf{0}$};
\foreach \x [evaluate={\xi=int(\x-1);}] [evaluate={\i=int(\x);}] in {1,2,...,7} {\node[button, show ocg=\i] [right of=\xi, xshift=20pt] (\x) {$\mathbf{\x}$};}
\foreach \x [evaluate={\xi=int(\x-8);}] [evaluate={\i=int(\x);}] in {8,9,...,11} {\node[button, show ocg=\i] [below of=\xi] (\x) {$\mathbf{\x}$};}
\end{tikzpicture}
\begin{center}
\begin{tikzpicture}
\begin{ocg}[radiobtngrp=myRadioButtons]{OCG 0}{0}{1}\node {$0,0,0,0$};\end{ocg}
\foreach \x in {1,2,...,11} {\begin{ocg}[radiobtngrp=myRadioButtons]{OCG \x}{\x}{0}\node {$\x,\x,\x,\x$};\end{ocg}};
\end{tikzpicture}
\end{center}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}