6

I'm writing a presentation for the Shannon Switching Game. In this game, players take turns picking edges from a graph. For fun, I decided to try to include an example game in the presentation.

The effect I want: when I click on a certain edge, I go to a specified slide. The edges will not always be vertical or horizontal.

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}

\begin{tikzpicture}\label{picture:first}
  \node (A) {$A$};
  \node (B) [below right=2 and 3 of A] {$B$};
  \path (A) edge[line width=5pt] (B); % I want this edge to be click-able
\end{tikzpicture}

\newpage

\begin{tikzpicture}\label{picture:second}
  \node (A) {$A$};
  \node (B) [below right=2 and 3 of A] {$B$};
  \path (A) edge[line width=5pt,red] (B)
\end{tikzpicture}

\end{document}

I've found answers to similar questions, either where the node is a hyperlink or where the edge is horizontal. Until I find a way to do this, my temporary solution is to put a node by each edge to label it and click on the edge labels.

Pi Fisher
  • 559
  • 3
  • 11
  • 2
    it's the PDF hyperlink specification that makes this not possible. – percusse May 02 '16 at 00:00
  • Would it be possible to generate several invisible nodes along the path each being a link? – Pi Fisher May 02 '16 at 00:03
  • If you already know how to add nodes and make them hyperlinks, can't you do this already? If the nodes have no content, they will be invisible (other things being equal). – cfr May 02 '16 at 00:11
  • Another possibility is to hide lyperlinks under the image. See http://tex.stackexchange.com/questions/176280/image-link-clickable-in-non-white-areas-excluding-the-background/261071?s=1|0.3780#261071 – John Kormylo May 02 '16 at 00:51
  • @cfr, I don't know how to add nodes along the path, but I suppose that would be a separate question. I think the answer to this question is that it can't be done nicely. – Pi Fisher May 02 '16 at 00:55
  • But you said you added them as labels. Just make empty labels. – cfr May 02 '16 at 00:58
  • It would help if you provided links to the related questions you've found. If you did, I could probably answer your question. As it is, I'd have to start searching. – cfr May 02 '16 at 00:59
  • @cfr I'm currently doing things with

    \path (A) edge[ultra thick] node {\hyperlink{210000}{1}} (1);

    which puts the label next to the edge (I think one of my packages changes this from default, which is centered on top of the edge). Doing it with empty labels, I would want to make a type of edge edge[link=2100000] that creates nodes along its entire length. This is something I don't know how to do.

    Links: [http://tex.stackexchange.com/questions/120861/making-tikz-path-into-a-hyperlink?rq=1] [http://tex.stackexchange.com/questions/169111/using-tikz-path-as-hyperref-link?rq=1]

    – Pi Fisher May 02 '16 at 01:17
  • 1
    Oh, and please don't use minimal for examples. I've illustrated the idea I had, guessing how you created the links. You can just make the nodes invisible and on top of the edge. I created 6. Of course you could make more. – cfr May 02 '16 at 01:21

1 Answers1

6

This creates 6 hyperlinks along the first edge which link to the second slide.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
  \begin{frame}{First}
  \begin{tikzpicture}\label{picture:first}
    \node (A) {$A$};
    \node (B) [below right=2 and 3 of A] {$B$};
    \path (A) edge [line width=5pt] node [pos=0, circle] {\hyperlink<1>{target}{}} node [pos=.2, circle] {\hyperlink<1>{target}{}} node [pos=.4, circle] {\hyperlink<1>{target}{}} node [pos=.6, circle] {\hyperlink<1>{target}{}} node [pos=.8, circle] {\hyperlink<1>{target}{}} node [pos=1, circle] {\hyperlink<1>{target}{}}  (B);
  \end{tikzpicture}
\end{frame}
\begin{frame}{Second}
  \hypertarget<1>{target}{}
  \begin{tikzpicture}\label{picture:second}
    \node (A) {$A$};
    \node (B) [below right=2 and 3 of A] {$B$};
    \path (A) edge [line width=5pt, red] (B);
  \end{tikzpicture}
\end{frame}
\end{document}

EDIT

Since it doesn't have to be an edge, it is straightforward to create a number of nodes along the path with a \foreach loop. I've also made the links a bit bigger by adding some more substantial invisible content ;). Here, I create 11 links:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
  \begin{frame}{First}
  \begin{tikzpicture}\label{picture:first}
    \node (A) {$A$};
    \node (B) [below right=2 and 3 of A] {$B$};
    \draw [line width=5pt] (A) -- (B) \foreach \i in {0,...,10} { node [pos=\i/10, circle] {\hyperlink<1>{target}{\phantom{X}}} };
  \end{tikzpicture}
\end{frame}
\begin{frame}{Second}
  \hypertarget<1>{target}{}
  \begin{tikzpicture}\label{picture:second}
    \node (A) {$A$};
    \node (B) [below right=2 and 3 of A] {$B$};
    \path (A) edge [line width=5pt, red] (B);
  \end{tikzpicture}
\end{frame}
\end{document}
cfr
  • 198,882
  • Cool! Is there a way to not have to specify each node individually? Maybe a foreach loop? – Pi Fisher May 02 '16 at 01:20
  • I tried a foreach loop but couldn't get it to work. Does it have to be an edge? If it was a regular path, it would be easy. – cfr May 02 '16 at 01:23
  • It does not need to be an edge. I'm just used to using edges in graphs because the first example I saw for how to make automata used them. – Pi Fisher May 02 '16 at 01:44
  • 1
    @PiFisher In that case, please see edit above. – cfr May 02 '16 at 02:06