I am trying to combine this answer on how to create hyperlinks with a tree hierarchy taken from the filesystem tree example. While the basic hyperlinking works, I get an error message as soon as I introduce the link style into the tree nodes. The error message is
! Package pgf Error: No shape named is known.
How can I combine the two partial solutions? The example I use is
\documentclass{article}
\usepackage[hidelinks]{hyperref}
\usepackage{tikz}
\usetikzlibrary{trees,calc}
\begin{document}
\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=0pt, outer sep=0pt,anchor=north west,at=(\p1)] {\hyperref[#1]{\phantom{\rule{\n1}{\n2}}}}
}
}
}
\tikzstyle{every node}=[draw=black,thick,anchor=west]
% simple drawing - works
\begin{tikzpicture}
\node [draw, inner sep=2ex,hyperlink node=sec:foo] {Go to Page Two};
\end{tikzpicture}
% tree without link - works
\begin{tikzpicture}[%
grow via three points={one child at (0.5,-0.7) and
two children at (0.5,-0.7) and (0.5,-1.4)},
edge from parent path={([xshift=2ex]\tikzparentnode.south west) |- (\tikzchildnode.west)},
growth parent anchor=west]
\node {Root Beer Rag}
child { node {Go to Page Two}};
\end{tikzpicture}
% tree with link - error
\begin{tikzpicture}[%
grow via three points={one child at (0.5,-0.7) and
two children at (0.5,-0.7) and (0.5,-1.4)},
edge from parent path={([xshift=2ex]\tikzparentnode.south west) |- (\tikzchildnode.west)},
growth parent anchor=west]
\node [hyperlink node=sec:foo] {Root Beer Rag}
child { node {Go to Page Two}};
\end{tikzpicture}
\clearpage
\section{Target}
\label{sec:foo}
\end{document}

\makeatletterbe\makeatother? – vwegert Feb 11 '14 at 08:00