0

I am creating a user manual for an ERP software and I am using \hyperlink{}{} option to create the links. After clicking on the link, it is pointing to the first page always. I tried the solution given in the link Hyperref \pageref links point to first page . But the given solution is not working for me.

The code is:

\documentclass[a4paper, 12pt]{article}  
\usepackage[top=1.65cm, bottom=2cm, right=1.25cm, left=1.25cm]{geometry}  
\usepackage{subfiles}  
\usepackage{tcolorbox}  
\usepackage{hyperref}  
\newcommand{\hlabel}{\phantomsection\label}  
\hypersetup{hidelinks}  

For defining labels I tried both:  
\section{Module}  
\phantomsection\label{sec:st}  
 and  
\section{Module}  
\label{sec:st}  

What should I do to correct this issue?

Thanks in advance.

5
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.
    – BambOo
    Aug 23 '18 at 10:56
  • When you say the given solution is notworking for me, do you mean you cannot compile or the result is not what you expect ?
    – BambOo
    Aug 23 '18 at 10:57
  • 1
    Your minimal working example doesn't compile...
    – user30471
    Aug 23 '18 at 11:13
  • @BambOo, I can compile, but if I click on the hyperlink, it will go to the first page not to the section which I intended. Aug 23 '18 at 14:20
  • \hyperlink and \hypertarget use the same name. The hypertarget name for \label is generated by \refstepcounter. You can find out what it is using \csname @currentHref\endcsname or look it up in the aux file. Aug 23 '18 at 19:16
0

This is too long for a comment, but as far as I can see this works as expected without the need for a \phantomsection command. I suspect that the problem is a misunderstanding of how the labels work, so let me show this by way of example. The MWE below produces three pages with the sections with labels defined via \label{sec:st1} and \label{sec:st2} on page 2 and the hyerplinks inserted using \ref{sec:st1} and \ref{sec:st2} on page 3. The following screenshot shows that the hyerlink is working correctly for \ref{sec:st2} (my PDf viewer is skim, which shows these elegant mouse-overs for hyperlinks). As requested in the comments, I have used \hyperref[sec:st1]{some text} for the first link to show how to specify your own text for the link.

enter image description here

Here is the code:

\documentclass[a4paper, 12pt]{article}
\usepackage[top=1.65cm, bottom=2cm, right=1.25cm, left=1.25cm]{geometry}
\usepackage{subfiles}
\usepackage{tcolorbox}
\usepackage{hyperref}
\newcommand{\hlabel}{\phantomsection\label}
\hypersetup{colorlinks}

\begin{document}
  blank page
  \newpage
  For defining labels I tried both:
  \section{Module}
  \label{sec:st1}
   and
  \section{Module}
  \label{sec:st2}

  \newpage some stuff
  \hyperref[sec:st1]{some text}
  and \ref{sec:st2}

\end{document}

I have also used \hypersetup{colorlinks} to highlight the links (instead of \hypersetup{idelinks} in the MWE). `

2
  • I tried to \hyperlink, because I can enter some text using the command. \hyperlink{label name}{Some Text}. It is not possible to add texts using \ref command. What package I should use for this purpose? Aug 23 '18 at 14:17
  • @adhokshajaA.M Use \hyperref[label]{text}. See my edit.
    – user30471
    Aug 23 '18 at 20:50

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.