
마우스와 대화형 그래프를 만들고 싶습니다. 예를 들어 마우스를 텍스트 레이블 위로 가져간 다음 관련 영역을 강조 표시합니다. 아래는 예시 그래프입니다:
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[yscale=-1,>=latex]
\foreach \a/\b/\c/\d/\desc [count=\j] in {
0/0/5/8/box1,
0/0/5/8/box2,
1/1/4/7/box3,
0/0/3/6/box4
}{
\path (-2,0) ++(0,\j) coordinate (A);
\draw (\a,\b) rectangle (\c,\d);
\draw[<-,red] (\a,\b) -- (A) node[anchor=east,pos=1] {\desc};
}
\end{tikzpicture}
\end{document}
상자 1에 마우스를 올리면 (0,0) - (5,8) 영역이 강조 표시되어야 합니다. 애니메이션 지원을 알고 있지만 대화형이 아닙니다(마우스 위치로 제어).
답변1
다음은 ocgx2 패키지를 사용하는 예입니다. 파일은 두 번 컴파일되어야 하며 PDF 리더인 Acrobat Reader, Foxit Reader 또는 evince가 필요합니다. 영역을 활성화하려면 상자 이름을 클릭해야 합니다.
ocgx2
옵션을 사용하여 한 레이어를 활성화하면 다른 레이어를 비활성화하는 방법을 설명에 명시한 패키지 관리자인 @AlexG에게 감사드립니다 opts={radiobtngrp=myBoxes}}
.
\documentclass[border=2mm]{standalone}
\usepackage[tikz]{ocgx2}
\begin{document}
\begin{tikzpicture}[yscale=-1,>=latex]
\foreach \a/\b/\c/\d/\desc [count=\j] in {
0/0/5/8/box1,
0/0/2/4/box2,
1/1/4/7/box3,
0/0/3/6/box4
}{
\path (-2,0) ++(0,\j) coordinate (A);
\draw (\a,\b) rectangle (\c,\d);
\begin{scope}[ocg={name=box\j,ref=box\j,status=invisible,opts={radiobtngrp=myBoxes}}]
\fill[red!30] (\a,\b) rectangle (\c,\d);
\end{scope}
\draw[<-,red] (\a,\b) -- (A) node[anchor=east,pos=1,switch ocg=box\j] {\desc};
}
\end{tikzpicture}
\end{document}