[Tex/LaTex] TikZ Document Navigation (\label and \ref commands)

cross-referencinghyperreflinkstikz-pgf

I am currently a university student studying engineering. I have been a user of LaTeX for a few years now and cannot work out how to solve the following issue.

In Australia, there are standards which describe the way in which referencing within technical drawings should be done. I am trying to create a method within LaTeX to allow me to create a set of drawings (all TikZ pictures) where sections, elevations and details can all be navigated between within the document (using the hyperref package). Unfortunately, I am currently receiving an error stating that the labels are undefined and thus the referencing breaks down. I think this is because the labels are not being associated with a 'figure' type environment.

Ideally, these links would appear as text that, when clicked, would take the viewer to the page on which the section is shown. In addition, and if possible, it would also be great if reference could be made to the page on which the section is shown.

I have included below a minimal example that shows my thoughts. Perhaps someone has already managed to solve this issue.

\documentclass{report}

\usepackage{tikz,hyperref}

\begin{document}

\begin{tikzpicture}
     \node at ( 20 mm , 20 mm ) {Hello World!\label{hello}} ;
\end{tikzpicture}

\newpage

\begin{tikzpicture}
     \node at (20 mm , 20 mm ) {Reference\ref{hello}};
     % This (hopefully) would make it possible to link
     % from Page X to Y within the .pdf document.
\end{tikzpicture}

\end{document}

Thank you to everyone who takes the time to read this and I look forward to receiving your response.

Best Answer

You want to be able to navigate from one drawing to the other one using hyperlinks, right? In this case you should use the macros of the hyperref package directly, i.e. \hypertarget{<label>}{<target text>} and \hyperlink{<label>}{<link text>}, and not the implicit ones added to \label and \ref:

\documentclass{report}

\usepackage{tikz,hyperref}

\begin{document}

\begin{tikzpicture}
    \node [draw] at ( 20 mm , 20 mm ) {\hypertarget{hello}{Hello World!}} ;
\end{tikzpicture}

\newpage

\begin{tikzpicture}
    \node [draw] at (20 mm , 20 mm ) {\hyperlink{hello}{Reference}};
\end{tikzpicture}

\end{document}

Then "Reference" is a hyperlink to "Hello World". By default a colored frame is added around it. You can change that using the hyperref options as described in the manual.

One problem here is that the hyper-anchor is at the baseline of the "Hello World" text. So if you jump there you actually don't see the text, because it is just above the top of the window. I normally fix this by putting the \hypertarget with empty text into a \raisebox with 0pt official height and raising it an amount over the text. Then the link jumps to a display which shows the target text just below the top of the window:

\documentclass{report}

\usepackage{tikz,hyperref}

\begin{document}

\begin{tikzpicture}
    \node [draw] at ( 20 mm , 20 mm ) {\raisebox{3ex}[0pt]{\hypertarget{hello}{}}Hello World!} ;
\end{tikzpicture}

\newpage

\begin{tikzpicture}
    \node [draw] at (20 mm , 20 mm ) {\hyperlink{hello}{Reference\strut}};
     % This (hopefully) would make it possible to link
     % from Page X to Y within the .pdf document.
\end{tikzpicture}

\end{document}