# Insert labels inside table rows

I have a long table with different equation, I need to make a label and then refer to them in some cells, trying to do that by putting usual label giving me wrong results in LyX, more precisely if the table is in some section, strangely enough making a label in some cell, and referencing it somewhere, will make a link not to the cell's label, but to the section title it self.

Below is exported code from LyX to Plain LaTeX:

%% 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[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{babel}
\usepackage{float}
\usepackage[unicode=true,pdfusetitle,
bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
{hyperref}
\usepackage{breakurl}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}
\makeatother
\begin{document}
\section{A New Section}
\begin{table}[H]
\begin{centering}
\begin{tabular}{|c|c|}
\hline
\label{eq:Mass Energy}$E=mc^{2}$ & \tabularnewline
\hline
\end{tabular}
\par\end{centering}

\protect\caption{sample}
\end{table}
A reference to (\ref{eq:Mass Energy})
\end{document}


I'm not sure if this LyX bug or LaTeX specific, any ideas? (especially by using labels not hyperref).

PS:

1. Interestingly, If I totally will remove the section, the output of the reference became empty.
2. There are some similar questions here, like auto numbering with labelling table rows, but that is not what I need.
• are you using equation or some other referencable enviornmewnt such as align for your mathematics? If you just use  or \[ then the behaviour would be as you describe (whether or not the text is in a table). – David Carlisle Jan 19 '15 at 11:51 • @LaRiFaRi Imentioned in the notes that this is not what I need. – TMS Jan 19 '15 at 13:51 • @DavidCarlisle I use align on the table it self, not the equation, is it an issue? – TMS Jan 19 '15 at 13:51 • @TMS It is impossible for me to guess what you have done. Every question should have a complete small document that demonstrates the issue, you could edit the question to add a test document. – David Carlisle Jan 19 '15 at 14:01 • @DavidCarlisle: done, sorry for that, thought it is clear.. – TMS Jan 19 '15 at 15:40 ## 1 Answer \label records the last referencable item, which is the section head in your case. Normally to refer to a formula you would use equation or align but sometimes in tables you can do it "by hand" \documentclass[english]{article} \usepackage[T1]{fontenc} \usepackage[latin9]{inputenc} \usepackage{babel} \usepackage{float} \usepackage[unicode=true,pdfusetitle, bookmarks=true,bookmarksnumbered=false,bookmarksopen=false, breaklinks=false,pdfborder={0 0 0},backref=false,colorlinks=false] {hyperref} \usepackage{breakurl} \makeatletter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands. %% Because html converters don't know tabularnewline \providecommand{\tabularnewline}{\\} \makeatother \begin{document} \section{A New Section} \begin{table}[H] \begin{centering} \begin{tabular}{|c|c|} \hline \refstepcounter{equation}\label{eq:Mass Energy}E=mc^{2}\$ & (\theequation)\tabularnewline
\hline
\end{tabular}
\par\end{centering}

\protect\caption{sample}
\end{table}
A reference to (\ref{eq:Mass Energy})
\end{document}

• I believe I understood what happened now: when labeling equation directly in LyX it inserting equation environment by it self, but when the equation was inside a table, LyX didn't understand what I'm lebeling there, hence the mess, thank you David. – TMS Jan 19 '15 at 16:36
• Sorry for this, but there is still an issue: when making a formated/textual reference to that equation, it outputs section title "A new section" instade of "Eq. xx", can you please advice how to solve that? – TMS Jan 19 '15 at 17:00