TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Please add a minimal working example (MWE) that shows what you've done thus far in terms of creating a tikz tree with some document elements. – Werner Nov 25 '11 at 4:10
@Werner I added the MWE. – yayu Nov 25 '11 at 4:47
I added a little code to complete the MWE. An MWE should provide sufficient code for a simple copy-paste-compile so that someone interested in finding a solution doesn't have to do any puzzling over what packages you're using, or type \documentclass etc. which gets boring. This is a nice question! – qubyte Nov 25 '11 at 14:47
up vote 31 down vote accepted

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}
share|improve this answer
Very nice! I wanted to put a url link into the document so I exchanged \hyperlink with \href. This works as expected. – Sebastian Mar 4 '13 at 16:15
This doesn't work for me. The output PDF has the node but it is not clickable. There were no errors in compilation, and I tried it with both Okular and Evince. – jja Mar 12 '13 at 14:50
@jja: Are you using pdflatex for the compilation? – Jake Mar 12 '13 at 15:05
Ah, that was it. I was using xelatex and it didn't work, but I just compiled with pdflatex and it worked perfectly. I guess a follow-up question would be how to do this with xelatex, if it can be done at all... – jja Mar 12 '13 at 16:23
I've tried to add this to an existing drawing and get the error message Package pgf Error: No shape named is known. (note the two spaces after named. Any ideas? – vwegert Feb 10 '14 at 19:59

Apart from Jake's nice idea – here's some code that works fine here in a recent document using the code from Drawing a directory listing a la the tree command in TikZ (answer of A. Stacey) and your MWE. It's not as fancy as your's, but maybe stylish, too.


  \global\advance\dirtree@plvl by 1
  \expandafter\xdef\csname dirtree@p@\the\dirtree@plvl\endcsname{\the\dirtree@lvl}
  \global\advance\dirtree@lvl by 1\relax
  \advance\dirtree@clvl by -\csname dirtree@p@\the\dirtree@plvl\endcsname
  \pgf@xa=0.5cm\relax % change the length to your needs
  \pgf@ya=-0.75cm\relax % change the length to your needs
  \global\advance\dirtree@plvl by -1
\tikzset{ %definition of a new style "dirtree"
    growth function=\dirtree@growth,
    every node/.style={anchor=north},
    every child node/.style={anchor=west},
    edge from parent path={(\tikzparentnode\tikzparentanchor) |- (\tikzchildnode\tikzchildanchor)}



\begin{tikzpicture}[dirtree] % it's what we defined above

\node {\textbf{COOL TOC}}
    child { node {\hyperref[install]{installation} }
        child { node {\hyperref[linux]{Linux}} }
        child { node {\hyperref[mac]{Mac}} }
        child { node {\hyperref[win]{Windows}} }
    child {node {\hyperref[start]{Get Started}}
        child { node {\hyperref[caseA]{do A}} }
        child { node {\hyperref[caseB]{do B}} }
    child {node {\hyperref[trbl-shoot]{troubleshoot}}
        child {node {\hyperref[caseX]{if X happens}}}
        child {node {\hyperref[caseY]{if Y happens}}}
    % I've put the external resources to the end:
    child {node {Looking Further}
        child { node {\href{file:manual.pdf}{manual}} }% works only, if "manual.pdf" is in
                                                       % the same directory as the compiled
                                                       % version of this document
        child { node {\href{http://website.example.com/online-resource/}{online}} }

Some content.

Some content.

Some content.

\section*{Get started}\label{start}
\subsection*{First: Do A}\label{caseA}
Some content.

\subsection*{Second: Do B}\label{caseB}
 Some content.

\section*{Trouble shooting}\label{trbl-shoot}
\subsection*{If X happens:}\label{caseX}
Some content.

\subsection*{If Y happens:}\label{caseY}
 Some content.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.