我如何创建一个 TikZ 形状,作为投影仪中幻灯片特定覆盖的超链接?

我如何创建一个 TikZ 形状,作为投影仪中幻灯片特定覆盖的超链接?

我是一名 TikZ 新手,正在尝试创建超链接的 TikZ 形状。我使用 MiKTeX 2.9 和 xelatex。请参阅下面的 MWE。

问题:

  • 这四个框是由矩阵中的一组节点创建的。出于某种原因,框 1 没有超链接到幻灯片 2。是因为它位于矩阵中吗?
  • 幻灯片 2 上的箭头超链接到幻灯片 1。但是,如果我想让它超链接到幻灯片 1 上的覆盖 #2,该怎么办?如果只是替换hyperlink node=slide1hyperlink node=slide1<2>,超链接就会失效。

感谢您的任何建议/解释/帮助。


\documentclass[11pt,t]{beamer}

\usepackage{textpos}
\usepackage{amsmath}
\usepackage{xcolor}
\definecolor{myblue}{RGB}{0,125,195}
\definecolor{mygreen}{RGB}{191,215,48}
\usepackage{tikz}
\usetikzlibrary[arrows,backgrounds,intersections,shapes,decorations,calc,positioning,graphs]


% Hyperlinking nodes
\setlength{\XeTeXLinkMargin}{0pt}
\tikzset{
    hyperlink node/.style={
        alias=sourcenode,
        append after command={
            let \p1 = (sourcenode.north west),
            \p2=(sourcenode.south east),
            \n1={\x2-\x1},
            \n2={\y1-\y2} in
            node [inner sep=0, outer sep=0, anchor=north west,at=(\p1)]
            {\hyperlink{#1}{\XeTeXLinkBox{\phantom{\rule{\n1}{\n2}}}}}
        }
    },
}

% TiKZ visible on

\tikzset{
    invisible/.style={opacity=0,text opacity=0},
    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
}
\begin{document}

\begin{frame}[fragile]{\hypertarget{slide1}{} Slide 1}
    \begin{center}
        \begin{tikzpicture}[transform canvas ={scale=0.75,yshift=-25mm},
            hv path/.style={to path={-| (\tikztotarget)}},
            vh path/.style={to path={|- (\tikztotarget)}},
            param/.style={
                rectangle, minimum size=6mm,
                very thick,
                draw = mygreen,
                top color = white,
                bottom color = mygreen!50!white!50,
                align = center},
            important/.style={
                rectangle, minimum size=6mm, rounded corners=3mm,
                very thick,
                draw = red!50!black!50,
                top color = white,
                bottom color = red!50!black!20,
                font = \LARGE,
                align = center},
            values/.style={
                rectangle, minimum size=6mm, rounded corners=3mm,
                very thick,
                draw = yellow!50!red!50,
                top color = white,
                bottom color = yellow!50!red!20,
                align = center},
            ivalues/.style={
                rectangle, minimum size=6mm, rounded corners=3mm,
                very thick,
                draw = yellow!50!red!50,
                top color = white,
                bottom color = yellow!50!red!20,
                font = \LARGE,
                align = center},
            >=stealth',thick,myblue,text=black,
            every new ->/.style={shorten >=1pt}
            ]
            \matrix[row sep=20mm, column sep=25mm, align=center]
            {
                \node (B4) [visible on=<8->, param, minimum size=2cm] {Box 4};&

                \node (c1) [visible on=<1->] {}; &

                \node [hyperlink node=slide2, visible on=<2->, param, minimum
                size=2cm] (B1) {Box1}; \\

                \node (B3) [visible on=<6->,param, minimum size=2cm] {Box 3};&
                \node (c2) {}; &
                \node (B2) [visible on=<4->,param, minimum size=2cm] {Box 2};\\
            };

            \graph{
                (c1) -> [visible on=<1->, align = center] (B1);
                (B1) -> [visible on=<3->, align = center] (B2);
                (B2) -> [visible on=<5->, align = center] (B3);
                (B3) -> [visible on=<7->, align = center] (B4);
                (B4) -> [visible on=<9->, align = center] (c1);
            };
        \end{tikzpicture}
    \end{center}
\end{frame}

\begin{frame}[fragile]{\hypertarget{Slide2}{} Slide 2}
    \begin{block}{BLAH BLAH}
        Foobar
    \end{block}

    \begin{textblock*}{1cm}(4cm,4cm)
        TEST
        \begin{tikzpicture}
            \node[hyperlink node=slide1, visible on=<2->, single arrow,draw=mygreen,fill=mygreen!50!white!50,minimum
            height=1cm,shape border rotate=90] at (0,0) {Up};
        \end{tikzpicture}
    \end{textblock*}

\end{frame}
\end{document}

答案1

正如我上面的评论所述:

\documentclass[11pt,t]{beamer}

\usepackage{textpos}
\usepackage{amsmath}
\usepackage{xcolor}
\definecolor{myblue}{RGB}{0,125,195}
\definecolor{mygreen}{RGB}{191,215,48}
\usepackage{tikz}
\usetikzlibrary[arrows,backgrounds,intersections,shapes,decorations,calc,positioning,graphs]

\makeatletter
\newcommand{\theslide}{\the\beamer@slideinframe}
\makeatother

% Hyperlinking nodes
\setlength{\XeTeXLinkMargin}{0pt}
\tikzset{
    hyperlink node/.style={
        alias=sourcenode,
        append after command={
            let \p1 = (sourcenode.north west),
            \p2=(sourcenode.south east),
            \n1={\x2-\x1},
            \n2={\y1-\y2} in
            node [inner sep=0, outer sep=0, anchor=north west,at=(\p1)]
            {\hyperlink{#1}{\XeTeXLinkBox{\phantom{\rule{\n1}{\n2}}}}}
        }
    },
}

% TiKZ visible on

\tikzset{
    invisible/.style={opacity=0,text opacity=0},
    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
}
\begin{document}

\begin{frame}[fragile]{\hypertarget{slide1<\theslide>}{}Slide 1}
    \begin{center}
        \begin{tikzpicture}[scale=0.75,
            hv path/.style={to path={-| (\tikztotarget)}},
            vh path/.style={to path={|- (\tikztotarget)}},
            param/.style={
                rectangle, minimum size=6mm,
                very thick,
                draw = mygreen,
                top color = white,
                bottom color = mygreen!50!white!50,
                align = center},
            important/.style={
                rectangle, minimum size=6mm, rounded corners=3mm,
                very thick,
                draw = red!50!black!50,
                top color = white,
                bottom color = red!50!black!20,
                font = \LARGE,
                align = center},
            values/.style={
                rectangle, minimum size=6mm, rounded corners=3mm,
                very thick,
                draw = yellow!50!red!50,
                top color = white,
                bottom color = yellow!50!red!20,
                align = center},
            ivalues/.style={
                rectangle, minimum size=6mm, rounded corners=3mm,
                very thick,
                draw = yellow!50!red!50,
                top color = white,
                bottom color = yellow!50!red!20,
                font = \LARGE,
                align = center},
            >=stealth',thick,myblue,text=black,
            every new ->/.style={shorten >=1pt}
            ]

            \matrix[row sep=20mm, column sep=25mm, align=center]
            {
                \node (B4) [visible on=<8->, param, minimum size=2cm] {Box 4};&

                \node (c1) [visible on=<1->] {}; &

                \node [hyperlink node=Slide2, visible on=<2->, param, minimum
                size=2cm] (B1) {Box1}; \\

                \node (B3) [visible on=<6->,param, minimum size=2cm] {Box 3};&
                \node (c2) {}; &
                \node (B2) [visible on=<4->,param, minimum size=2cm] {Box 2};\\
            };

            \graph{
                (c1) -> [visible on=<1->, align = center] (B1);
                (B1) -> [visible on=<3->, align = center] (B2);
                (B2) -> [visible on=<5->, align = center] (B3);
                (B3) -> [visible on=<7->, align = center] (B4);
                (B4) -> [visible on=<9->, align = center] (c1);
            };
        \end{tikzpicture}
    \end{center}
\end{frame}

\begin{frame}[fragile]{\hypertarget{Slide2}{}Slide 2}
    \begin{block}{BLAH BLAH}

    \end{block}

    \begin{textblock*}{1cm}(4cm,4cm)
        TEST
        \begin{tikzpicture}
            \node[hyperlink node=slide1<2>,visible on=<2->, 
            single arrow,draw=mygreen,fill=mygreen!50!white!50,minimum
            height=1cm,shape border rotate=90] at (0,0) {Up};
        \end{tikzpicture}
    \end{textblock*}

\end{frame}
\end{document}

相关内容