I'm working with LyX. Do you know how to apply cross reference when using "Tex code" option in LyX?

That's the example of what I'm writing in Tex code:


Where I should put the label in this case so that cross reference option can work?

I hope the question is clear...thank you for your help!

  • I like Werner's answer better than what I'm about to propose. Nontheless... you could put the label in a LyX note outside of the ERT. Because it's in a LyX note it will not be exported in the LaTeX so it won't override the real label. However, LyX will let you cross-reference that label. – scottkosty Mar 24 '14 at 5:51
  • You could consider accepting one of the answers by clicking the checkmark next to it, if you feel any of them solved your problem. You could also upvote all answers you feel are useful. Accepting marks the question as solved. (This applies to all of your questions that have been answered.) – Torbjørn T. Mar 30 '14 at 7:06

You are not using LyX's interface for managing labels and cross-references. As such, if you're using \label{abc} in an ERT (or "TeX code"), then you need to also use an ERT for the reference \ref{abc} as well.

enter image description here

enter image description here


Just enter the label manually in the "Cross-reference" dialog. LyX will display it with a BROKEN: prefix (as it cannot find the respective label), but it works nevertheless. You have to be a bit careful if editing it later, though.

Using the LyX dialog has the advantage that you can easily use LyX built-in support for formatted references:

enter image description here

If you don't like the BROKEN: thing or have to insert the cross-reference multiple times and consider it as to tedious to do this manually, there is a trick to teach LyX the existence of a label (also suggested in the comment of scottosky): Just have a LyX note at some place inside your document that contains pseudo-labels for all ERT-inserted labels:

enter image description here


This is not really answering your question, but providing a workaround for the specific situation.

If you'd like to, you can use a combination of LyX-stuff and ERTs:

  1. Add a table float, with Insert --> Float --> Table, or the corresponding button the toolbar.
  2. This will give you a table float with a caption. Write your caption, and add the label inside (or just after) it with Insert --> Label, or via the toolbar.

  3. Move the cursor before the caption, add an ERT, and write

  4. Move the cursor after the caption, add a second ERT, and write


This method will allow you to use LyX's cross-referencing system.

enter image description here

  • This is nice. It allows for ERT and using LyX's dialogs, but without the hack I suggested in the comment to the question. – scottkosty Mar 24 '14 at 11:15

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.