2

I want to make cross-referencing of Figures and Tables in text. I want them to appear in text with hyperlink, just like Journals. I have labeled all Figures and Tables and inserted them as cross reference in text. But in PDF output, only figure or table number ‘1’ appears with hyperlink such as. What I want is ,the word Table or Figure to appear with the number and hyperlinked together such as ‘Figure 1’. Can anyone please suggest me how to do this in Lyx? Many thanks.

1
  • Go to Help > User Guide and see the section "Cross-references", in particular "formatted reference". – scottkosty Jan 17 '16 at 7:41
5

First make sure you use refstyle, go to Document->Document Settings->Document Class and check "Use refstyle...". Now lets add references that are clickable: go to Document->Settings->PDF Properties and check "Use Hyperref Support".

Now when adding a cross-reference select "Formatted reference" in the Format option at the bottom of the window.

Choosing the "formetted reference" will add the "figure" or "table" for each cross reference, and the hyperref settings will add a hyperlink to any '\ref'. The problem ? the hyperlinks are only on "1" and not "figure 1" entirely. to fix that we need to add the following to your preamble

\newref{fig}{refcmd={\hyperref[#1]{Figure \ref{#1}}}}
\newref{tab}{refcmd={\hyperref[#1]{Table \ref{#1}}}}
\newref{eq}{refcmd={\hyperref[#1]{Eq. (\ref{#1})}}}

Of course you can change "Figure" to "Fig" or "Drawing" or anything you like

9
  • Thanks a lot Elad Den. It works now for all tables/figures in the main text. But how to modify these code for a figure/table in Appendix? I have numbered the tables in Appendix separately. I guess I need to add more lines to those three lines in the preamble for Appendix cross ref. My knowledge of coding is limited. Can you help me again? – Sadia Jan 20 '16 at 5:14
  • It works fine for me in the appendix too.... do you label your figures fig:mylabel in the appendix as well ? if use something like apendfig:mylabel then you need to add a line \newref{apendfig}{refcmd={\hyperref[#1]{Appendix Figure \ref{#1}}}} – Elad Den Jan 20 '16 at 7:15
  • Oh yes, it works for appendix as well. I don't need to add more code. I deleted previous labels, and labelled again. Then it works perfectly! Thanks a lot for your help. – Sadia Jan 20 '16 at 7:48
  • I put the following command at the begining of appendix to separate numbers for appendix tables like Table A1: \renewcommand{\thetable}{A\arabic{table}} \setcounter{table}{0} \renewcommand{\thefigure}{A\arabic{figure}} \setcounter{figure}{0} – Sadia Jan 20 '16 at 8:17
  • I put the following command at the begining of appendix to separate numbers for appendix tables like Table A1: \renewcommand{\thetable}{A\arabic{table}} \setcounter{table}{0} \renewcommand{\thefigure}{A\arabic{figure}} \setcounter{figure}{0} Now the problem is when I click Table A1, although it appears nice, it takes me to Table 1 (table 1 in main text, not the appendix one). What's going wrong? I tried adding your new code. But still same problem. – Sadia Jan 20 '16 at 8:20
1

To add a completely "in house" solution for LyX. (And yes, I do spend way too much time in LyX away from a proper TeX editor)

  1. In Document > Settings > Document Class make sure that Use refstyle (not prettyref) for cross-references is ticked

  2. In Document > Settings > PDF Properties tick the box for Use Hyperref Support (essentially tells LyX to use the hyperref package).

  3. Insert a Figure float and name it Foo. (By this I mean type Foo in the box for the label)

  4. Insert a label by going Insert > Label (or use the icon on the menu bar). If it is a figure called foo, name the label fig:Foo

  5. Insert a cross-reference by going Insert > Cross-Reference (or use the icon on the menu bar). A dialogue box will pop up (shown in the screen shot below)

LyX Cross Reference Dialogue Box

  1. Under format, I have chosen Formatted Reference. What this gives me is

"Figure 1 on Page 1"

  1. If you would like this to happen with a table, then you must use a Table Float and use tab:Goo

Result:

My LaTeX source code (viewable by going View > Source Plane) for this example looks like this:

\begin{figure}[h]
\protect\caption{Foo}
\label{fig:Foo}
\end{figure}

According to \prettyref{fig:Foo}

\begin{table}[h]
\protect\caption{Goo}
\label{tab:Goo}
\end{table}

According to \nameref{tab:Goo}

And the output is: LyX Reference Output

Of course, if you you need more functionality then Elad's solution is great! But if you like using LyX's user face more then have go with my suggestion :)

3
  • This is how I usually do my references, but this way the hyperlink is only on the number. OP wanted the hyperlink on the entire formatted ref. I think his best solution is a mix of both our answers, setting up hyperref with the GUI, and adding the setting for the format in the preamble... :) I updated my answer accordingly – Elad Den Jan 17 '16 at 12:45
  • My mistake! I didn't realise that the "figure" in "figure 1" wasn't clickable. When I tested it I must have only been clicking on the number hmm – Alwin Jan 18 '16 at 9:06
  • Thanks Alwin for your effort to help me. Elad's suggestion works in my case. – Sadia Jan 20 '16 at 3:00

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.