4

This question already has an answer here:

In a longtable, I need the first column to display numbers based on an enumeration by references to labels. This means I can refer to the rows somewhere else in the text.

I imagined it would help to create a label and reference to that label in the same cell, but I keep getting 1-figures instead of an incrementing number.

Here's an example of what I have:

\documentclass[a4paper]{article}
\usepackage{longtable}
\begin{document}

\begin{longtable}{|l|l|}


\hline
\textbf{Number} & \textbf{Title} \\
\hline
\endfirsthead

\label{row:thefirst}
\ref{row:thefirst} &
First \\
\hline

\label{row:thesecond}
\ref{row:thesecond} &
Second \\
\hline

\label{row:thethird}
\ref{row:thethird} &
Third \\
\hline

\end{longtable}

\end{document}

I have tried changing the "row:" to something like "itm:" or "fig:", but nothing helps.

Perhaps, I need to put it in some context like when using \begin{figure}, but I am not sure how that would turn out when in a table cell.

Any suggestions? Thanks!

marked as duplicate by zeroth, Peter Jansson, m0nhawk, barbara beeton, Jesse Dec 21 '13 at 3:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    The "row:" is just a name you define. The funcionality isn't touched by this definition. (That's the reason why it did not help.) – Ruben Dec 20 '13 at 13:21
  • Alright, but then what should I do to get to the numbers working...? – Gerard Nijboer Dec 20 '13 at 13:30
  • 1
    Does tex.stackexchange.com/questions/54881/… help you? – zeroth Dec 20 '13 at 13:55
  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Martin Schröder Dec 20 '13 at 14:53
  • 1
    \label always refers to the last counter stepped with \refstepcounter (or actually whatever counter is saved in \@currentlabel), independently from the label name you choose. In your case it is the table counter as \begin{longtable} does \refstepcounter{table} internally. You need some counter that is stepped every row if you want to be able to refer to the rows. – clemens Dec 20 '13 at 15:13
4

enter image description here

The form of the label string has no effect whatsoever: it is an arbitrary internal string for cross referencing. You need to increment a counter if you want to count something.

\documentclass[a4paper]{article}
\usepackage{longtable,array}
\newcounter{ltrow}
\begin{document}

\setcounter{ltrow}{0}
\begin{longtable}{|>{\refstepcounter{ltrow}\theltrow}l|l|}


\hline
\multicolumn{1}{|l|}{\textbf{Number}} & \textbf{Title} \\
\hline
\endfirsthead

\label{row:thefirst}
 &
First \\
\hline

\label{row:thesecond}
 &
Second xxx\\    
\hline

\label{row:thethird} &
Third \\    
\hline

\end{longtable}


xxx is on row \ref{row:thesecond}
\end{document}

Not the answer you're looking for? Browse other questions tagged or ask your own question.