[Tex/LaTex] Making TikZ nodes hyperlinkable


I have a TikZ tree. Now I want to make the nodes click-able directing to relevant sections in the document (or directed to URLs). Some of the content in the nodes are not text. Is it possible to turn the nodes into links, and if so, how? I would prefer the nodes themselves to be links, and not the text they contain.

Addition: I am not really good at it, and still learning, but here is a skeletal outline of the idea I am working on… (a graphical table of contents)


\tikzstyle{level 1}=[sibling distance=60mm]
\tikzstyle{level 2}=[sibling distance=25mm]

\node[circle,draw,grow=down] {\textbf{COOL TOC}}
    child {node {installation}
        child {node {Linux}}
        child {node {Mac}}
        child {node {Windows}}
    child {node {Get Started}
        child {node {do A}}
        child {node {do B}}
    child {node {Looking Further}
        child {node {manual}}
        child {node {online}}
    child[grow=up] {node {troubleshoot}
        child {node {if X happens}}
        child {node {if Y happens}}


enter image description here

There are fancier examples for example this one would make for a great TOC.

Best Answer

Here's a new TikZ style called hyperlink node=<target> that takes a hypertarget reference. It works by measuring the node it is supplied to, and then placing a new invisible node on top of that. The new node has the content \hyperlink{<target>}{\phantom{\rule{<width of node>}{<height of node>}}, so it has the same size as the original node, but the whole area is clickable.

    hyperlink node/.style={
        append after command={
            let     \p1 = (sourcenode.north west),
                \p2=(sourcenode.south east),
                \n2={\y1-\y2} in
            node [inner sep=0pt, outer sep=0pt,anchor=north west,at=(\p1)] {\hyperlink{#1}{\XeTeXLinkBox{\phantom{\rule{\n1}{\n2}}}}}
                    %xelatex needs \XeTeXLinkBox, won't create a link unless it
                    %finds text --- rules don't work without \XeTeXLinkBox.
                    %Still builds correctly with pdflatex and lualatex

\tikz \node [draw, inner sep=2ex,hyperlink node=pagetwo] {Go to Page Two};

\hypertarget{pagetwo}{Page Two}