Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
Your code works fine for me . I added \pageref{hello} without problem. I work with pgf 2.1 cvs and I have the latest hyperref package –  Alain Matthes Mar 27 '11 at 6:40

2 Answers 2

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}
share|improve this answer
    
Why do you want remove \labeland \ref? it's possible to navigate from one drawing to the other one with these macros. I agree that we can create links directly with hyperref but without hyperref we can compile the initial code and for a paper version you have the references (black on white). –  Alain Matthes Mar 27 '11 at 10:21
    
@Altermundus: I can't see anything to \label or to \reference in the example code. What number should \ref display? The \label only works with macros which define an internal label which is then used. The parts of the drawings don't do that. You would have to add these anyway manually. It all depends on what exactly the OP wants, which is (now) not fully clear to me. Using \pageref to insert the page number is a good idea, but \label wont work well. I think the zref package would be well suited. –  Martin Scharrer Mar 27 '11 at 10:43
    
What number should \ref display? is a very good question and I think the final answer depends of this question. I agree with you about \labelworks only with some macros... this is why I think \pageref is useful. I don't understand why the OP gets an error stating that the labels are undefined ? I don't have this error and the link is correct. And if you add a section then the references are displayed correctly. –  Alain Matthes Mar 27 '11 at 10:54

The problem is perhaps the reference number. In this case you can use \pageref. With \section, you can use \ref{...}.

\documentclass{report}    
\usepackage{tikz,hyperref}    
\begin{document}

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

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

and with \section

\documentclass{report}

\usepackage{tikz,hyperref}

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

\section{}
\begin{tikzpicture}
     \node[draw] at (20 mm , 20 mm ) {Reference: \ref{hello}};
\end{tikzpicture}
\end{document}   

enter image description here

share|improve this answer

Your Answer

 
discard

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.