This question here garnered an interesting response on how to make TikZ node text clickable.

I am using the graphdrawing package in order to automatically set up the graph, so I am unable to use the \hyperlink command in the \graph "environment. My file at the moment looks like this:

\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{trees, layered}


    \tikz [rounded corners] 
    \graph [layered layout, sibling distance=8mm, level distance=8mm]
       A -> B -> C -> A

\section{Target A} 

\section{Target B}

\section{Target C}


How could I set up hyperlinks to be such that if click on A in the graph, it takes me to the section titled "A" if I am using graphdrawing?

1 Answer 1


Good timing! — I just made a similar “graph of contents” for my own document. :o)

How this works: I assign labels to all sections, and use those as the names of the graph nodes. The nodes are then typeset using the command \myref, which outputs three hyperlinks to the given label as part of the node text.

% Use frenchlinks for nifty small caps

% Hyperlinks to:     Section #         Section name                    Page  number
%                    —————————         ————————————                    ————————————
\newcommand\myref[1]{\ref{#1}. \textbf{\nameref{#1}}\\\footnotesize p. \pageref{#1}}
%                            — —————————————————————  —————————————
%                     Period ^         Bold            Small  text

\section*{Graph of contents}
% (Note that you don’t need both \begin{tikzpicture} and \tikz)
\graph [
  layered layout, level distance=4em, sibling distance=3em,
    % Draw nodes as rectangles with centered text and a bit of horizontal padding
    draw, align=center, inner xsep=0.5em,
    % Use \myref to typeset nodes using their name (viz. section label) as input
] { a -> { b -> c, d } };

\section{The first section}  \label{a}
\section{The second section} \label{b}
\section{The third section}  \label{c}
\section{The fourth section} \label{d}

If you want to keep the sec: prefix in your section labels, you could just stick it at the beginning of the \ref, \nameref, and \pageref commands.

If you want the entire rectangle to be clickable, maybe take a look at this question.


While reading the draft of Computer Vision: Algorithms and Applications, I noticed a good example of a “graph of contents” on page 42:

This kind of graph should be possible to make using the method I gave above.

Possibly related questions:

  • Looks cool. This could be automated.
    – 1010011010
    Jun 28, 2014 at 17:13
  • Hm? How much more automated could you possibly make this?
    – hftf
    Jun 28, 2014 at 17:57
  • It's totally doable to hijack the \tableofcontents command to produce that tikzpicture that you show here.
    – 1010011010
    Jun 28, 2014 at 19:06
  • @1010011010 It has been a long time since you made this comment, but would you mind commenting further on automating this, perhaps with a minimal example? I would be happy to provide a bounty.
    – bzm3r
    Mar 18, 2016 at 3:27
  • @1010011010 In particular, I am curious to know how you might end up automating how the links between the material are specified.
    – bzm3r
    Mar 18, 2016 at 3:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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