TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
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
up vote 3 down vote accepted

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

share|improve this answer
Thank you for your help! – user46589 Mar 27 '14 at 21:35

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

share|improve this answer
This works perfectly well, thank's! – gaborous Jan 5 '15 at 22:23

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

share|improve this answer
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 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.