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

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?

share|improve this question
up vote 12 down vote accepted

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.

share|improve this answer
Looks cool. This could be automated. – 1010011010 Jun 28 '14 at 17:13
Hm? How much more automated could you possibly make this? – hftf Jun 28 '14 at 17:57
It's totally doable to hijack the \tableofcontents command to produce that tikzpicture that you show here. – 1010011010 Jun 28 '14 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. – user89 Mar 18 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. – user89 Mar 18 at 3:28

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.