4

I'm having trouble using labels and cross-referencing in Lyx. I put a label into the document where I want it. It is not embedded in anything, it's just in the text. Then I put a cross-reference to link it at a different point in the paper. When I make the pdf, the cross-reference does not go to the link but rather to the top of the section it's in. What going on? However, within Lyx, whenever I use the (Navigate Bar -> Other Lists -> Labels and References) then the reference appears to work fine. It's just not working in the pdf..

What could be the problem?

Thank you in advance!

  • 3
    You must be loading hyperref also. What does the cross-reference print in the document? A number of the section or just text? If you want it to just to the correct location, you'll have to place an ERT with \phantomsection just before the label. – Werner Oct 24 '13 at 4:43
  • In the document the number of the section is printed. The \phantomsection works. Thank you. – user38403 Oct 24 '13 at 17:39
  • Is that what you want? If so, then all you need to do is insert an ERT with \phantomsection just before the label. Then your reference will jump to that spot in the PDF. – Werner Oct 24 '13 at 17:42
5

The problem is that a \label attaches itself to the last numbered element in the document -- in your case a section -- it does not correspond to the exact position in the code/PDF.

As an alternative to Werner's suggestion, is to use \hyperlink and \hypertarget from hyperref. There is as far as I know no way of accessing these via the LyX GUI however, so you have to add them in ERTs. And as hyperref is required, you have to enable that under Document --> Settings --> PDF Properties, if you haven't already.

The syntax for these commands is

\hyperlink{<name>}{<text>}
\hypertarget{<name>}{<text>}

where <name> is the label, and <text> is printed in the PDF. As there is no support for these in the GUI, you can't use LyX' cross-referencing mechanism.

An example is seen in the screenshot below. I added \hypertarget{thing}{Cool stuff!} one place, and \hyperlink{thing}{Check this out.} where I wanted the link to be. Note that <text> in the \hypertarget can be empty if you want that.

enter image description here

  • 2
    I can confirm that there is currently no LyX GUI way of doing this. I would like to implement it as many users find it useful, especially for Beamer presentations. – scottkosty Oct 26 '13 at 9:42

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.