Graphics, Figures & TablesCross referencing Tables/Figures in Lyx fails in pdf

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
dead_mantra
Posts: 10
Joined: Tue Feb 10, 2015 5:32 pm

Cross referencing Tables/Figures in Lyx fails in pdf

Post by dead_mantra »

Dear all,

I'm a new Lyx user currently writing my theses on it.
My problem is that, after exporting my document to pdf, the click-able links to the figures/tables don't quite match the location of the figure/table! Instead, they seem to match more a section/subsection having the same numbering with the figure/table that the link is supposed to point.

I have tried putting the label inside, outside, at the front/back of the caption (but still in the float box) but to no success. Also, using 'formatted' cross reference only produces Table ??. Finally, I tried an ERT with \hyperlink{....} just before inserting the label, but that doesn't work either.

I'm using Lyx 2.1.2 and the hyperref package in the preamble.

Thanks for any suggestions!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Cross referencing Tables/Figures in Lyx fails in pdf

Post by Johannes_B »

Hi and welcome,

the label of the object hast to be inside the caption or just after it. It sounds like it is before in your case, which would lead to the result you describe. Can you check again?

If the problem persists, please export your document to the more basic and general LaTeX which is more suited for new users and post the code here. There is a simple method described at the LyX homepage on how to boil the document down to just the trouble maker.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
dead_mantra
Posts: 10
Joined: Tue Feb 10, 2015 5:32 pm

Re: Cross referencing Tables/Figures in Lyx fails in pdf

Post by dead_mantra »

Hi Johannes,

I have tried putting the label both in and after the caption. The problem however persists.
After creating a minimal version of my document (kept only hyperref, pslatex and nonfloat in preamble) I realised that removing the modules
'number equations/figures/tables by Section' under the Settings menu improves the situation.
I have attached the .lyx and corresponding pdf of the minimal version.
It can be seen there that both links point to where they are supposed to. However,
one table is fully visible whereas the other is not.
Looks like we are almost there in solving it.

Thanks for any further help.
Attachments
cross_ref_issue.lyx
(13.3 KiB) Downloaded 294 times
cross_ref_issue.pdf
(27.68 KiB) Downloaded 241 times
dead_mantra
Posts: 10
Joined: Tue Feb 10, 2015 5:32 pm

Re: Cross referencing Tables/Figures in Lyx fails in pdf

Post by dead_mantra »

Sorry not too familiar with all these yet.
Here is the .tex file too, if that's more of a help.
Attachments
cross_ref_issue.tex
(7.58 KiB) Downloaded 275 times
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Cross referencing Tables/Figures in Lyx fails in pdf

Post by Johannes_B »

Indeed, only the tex-code is useful for me.

I wrote some comments of Dos and Don'ts in the code below. Two things are quite important, if you fix those, everything should be fine. If you can't figure it out yourself, i will point you in the right direction, but the satisfaction of finding the problem cause on your own is priceless ;-)

Code: Select all

%% LyX 2.1.2 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[12pt,a4paper,english]{report}
%\renewcommand{\familydefault}{\rmdefault}%the default
\usepackage[T1]{fontenc}%contradicts with the next line
%\usepackage[utf8]{luainputenc}%commented out
\setcounter{secnumdepth}{3}
\setlength{\parindent}{0.8cm}
\usepackage{babel}
\usepackage{setspace}
\usepackage[numbers]{natbib}
\onehalfspacing
\usepackage[unicode=true,pdfusetitle,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
 {hyperref}%usually, hyperref is loaded last

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\pdfpageheight\paperheight
\pdfpagewidth\paperwidth

%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
%\usepackage[T1]{fontenc}
%\usepackage{pslatex}% i really bet you don't need this
% Please check out the link below
% http://chat.stackexchange.com/transcript/41?m=18922843#18922843

%\usepackage{hyperref}%why loading it again? 
%\usepackage{prettyref}
%\usepackage{floatrow}
%\usepackage{nonfloat}% I wouldn't really recommend that package
%better use package `caption` which is actively maintained
%and provide the command `captionof` which can be used if you really want a non-floating object. It also fixes the target position of hyperlinks.
%\usepackage{amsmath, amssymb, amsthm} % AMS packages
%\usepackage{graphicx,color}           % Packages for graphics and color
%\usepackage[left=1.5in, right=1in, top=1in, bottom=1in, includefoot, headheight=13.6pt]{geometry}


%\pagenumbering{arabic}
%\setcounter{page}{1}

%\usepackage{tikz} %draw graphics
%\usepackage{pgfplots} %for drawing again
%\pgfplotsset{compat=newest} %need to show graphics FFS!!

\makeatother

\begin{document}

\chapter{Title}


\section{Text}

\ref{tab:Test-table-2}Text and some more text Text and some more
text Text and some more text Text and some more text Text and some
more text Text and some more text Text and some more text Text and
some more text Text and some more text Text and some more text Text
and some more text Text and some more text Text and some more text
Text and some more text Text and some more text Text and some more
text Text and some more text Text and some more text Text and some
more text Text and some more text Text and some more text Text and
some more text Text and some more text Text and some more text Text
and Text and some more text Text and some more text Text and some
more text Text and some more text Text and some more text Text and
some more text Text and some more text Text and some more text Text
and some more text Text and some more text Text and some more text
Text and some more text Text and some more text Text and some more
text Text and some more text Text and some more text Text and some
more text Text and some more text Text and some more text Text and
some more text Text and some more text Text and some more text Text
and some more text Text and some more text Text and some more text
Text and some more text Text and some more text Text and some more
text Text and some more text Text and some more text Text and some
more text Text and some more text Text and some more text Text and
some more text Text and some more text Text and some more text Text
and some more text Text and some more text Text and some more text
Text and some more text Text and some more text Text and some more
text 

.

\begin{table}[ph]


\begin{tabular}{|c|c|c|}
\hline 
 &  & \tabularnewline
\hline 
\hline 
 &  & \tabularnewline
\hline 
 &  & \tabularnewline
\hline 
\end{tabular}\protect\caption{Test table\label{tab:Test-table}}
\end{table}



\section{Text}

Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more and more text Text and moreand more text Text and moreand more
text Text and moreand more text Text and moreand more text Text and
moreand more text Text and moreand more text Text and moreand more
text Text and moreand more text Text and moreand more text Text and
moreand more text Text and moreand more text Text and moreand more
text Text and moreand more text Text and moreand more text Text and
moreand more text Text and moreand more text Text and moreand more
text Text and moreand more text Text and moreand more text Text and
moreand more text Text and moreand more text Text and more \ref{tab:Test-table}


\section{Text}

Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more text Text and more text Text and more text Text and more text
Text and more text Text and more text Text and more text Text and
more 

\begin{table}[ph]
\begin{tabular}{|c|c|c|}
\hline 
 &  & \tabularnewline
\hline 
\hline 
 &  & \tabularnewline
\hline 
 &  & \tabularnewline
\hline 
\end{tabular}

\protect\caption{Test table 2\label{tab:Test-table-2}}
\end{table}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
dead_mantra
Posts: 10
Joined: Tue Feb 10, 2015 5:32 pm

Re: Cross referencing Tables/Figures in Lyx fails in pdf

Post by dead_mantra »

Thanks a lot Johannes!
I'm pretty sure I can sort this after following your comments.
Just realised that exporting the code allows for a much deeper understanding of what's going on really :D
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Cross referencing Tables/Figures in Lyx fails in pdf

Post by Johannes_B »

dead_mantra wrote:Just realised that exporting the code allows for a much deeper understanding of what's going on really :D
Yep, that's the deal. A LyX developer once noted, that you need a working understandment of LaTeX before diving into LyX.
LyX is something predefined, but with LaTeX as a markup/macro language, the whole world is more clear ;-)

If you have any more questions, just ask ;-)
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
dead_mantra
Posts: 10
Joined: Tue Feb 10, 2015 5:32 pm

Re: Cross referencing Tables/Figures in Lyx fails in pdf

Post by dead_mantra »

Thanks.
I was able to sort the problem. Now my preamble is minimal and tidy (for the time being) :)
Post Reply