# Using TikZ path as hyperref link

In the following example, clicking the text on the two blocks will take us to either the second section or a piece of text within that section. I would like to be able to navigate using the edge connecting the two blocks, that is, I want to click on the edge and be taken to a label or hypertarget. Is this doable?

\documentclass{report}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes}
\usepackage{hyperref}
\begin{document}

\section{First section}

\begin{tikzpicture}
\node[draw, rectangle] (A) {\hyperlink{gotext}{Go to linked text}};
\node[draw, rectangle, right=of A] (B) {\hyperref[sec:mysection]{Go to 2nd section}};

\draw (A) -- (B);    % The edge I want to click on to navigate.
\end{tikzpicture}

\newpage
\section{Second section}
\label{sec:mysection}

Corruption can occur on different scales. There is corruption that occurs as small favours between a small number of people (petty corruption), corruption that affects the government on a large scale (grand corruption), and corruption that is so prevalent that it is part of the every day structure of society, including corruption as one of the symptoms of organized crime (systemic corruption).

Judicial corruption refers to corruption related misconduct of judges, through receiving or giving bribes, improper sentencing of convicted criminals, bias in the hearing and judgement of arguments and other such misconduct.

\hypertarget{gotext}{%
Governmental corruption} of judiciary is broadly known in many transitional and developing countries because the budget is almost completely controlled by the executive. The latter undermines the separation of powers, as it creates a critical financial dependence of the judiciary. The proper national wealth distribution including the government spending on the judiciary is subject of the constitutional economics.

\newpage
empty page

\end{document}


This question is somewhat related to what I want although I could not make much sense of what is happening there.

## 1 Answer

Here is some hair pin curve.

   \path let   \p1=(A.east),
\p2=(B.west) ,
\n1={veclen(\x2-\x1,\y2-\y1)} in
node[outer sep=0pt,inner xsep=0pt,align=left,anchor=west,minimum width=\n1,minimum height=1ex]
at (A.east) (link)  {\hyperlink{gotext}{\hphantom{\hspace*{\n1}}}};


Full code:

\documentclass{report}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,calc}
\usepackage{hyperref}
\begin{document}

\section{First section}

\begin{tikzpicture}
\node[draw, rectangle] (A) {{Go to linked text}};
\node[draw, rectangle, right=of A] (B) {\hyperref[sec:mysection]{Go to 2nd section}};

\path let   \p1=(A.east),
\p2=(B.west) ,
\n1={veclen(\x2-\x1,\y2-\y1)} in
node[outer sep=0pt,inner xsep=0pt,align=left,anchor=west,minimum width=\n1,minimum height=1ex] at (A.east) (link)  {\hyperlink{gotext}{\hphantom{\hspace*{\n1}}}};
%  \node[minimum width={veclen(A.east-B.west)}] at (A.east) {\hyperlink{gotext}{}};
\draw (A) -- (B);    % The edge I want to click on to navigate.
\end{tikzpicture}

\newpage
\section{Second section}
\label{sec:mysection}

Corruption can occur on different scales. There is corruption that occurs as small favours between a small number of people (petty corruption), corruption that affects the government on a large scale (grand corruption), and corruption that is so prevalent that it is part of the every day structure of society, including corruption as one of the symptoms of organized crime (systemic corruption).

Judicial corruption refers to corruption related misconduct of judges, through receiving or giving bribes, improper sentencing of convicted criminals, bias in the hearing and judgement of arguments and other such misconduct.

\hypertarget{gotext}{%
Governmental corruption} of judiciary is broadly known in many transitional and developing countries because the budget is almost completely controlled by the executive. The latter undermines the separation of powers, as it creates a critical financial dependence of the judiciary. The proper national wealth distribution including the government spending on the judiciary is subject of the constitutional economics.

\newpage
empty page

\end{document}


Run the code, click yourself and testify ;)