[LaTeX] Referencing Issue

  • LaTeX
  • Thread starter ajclarke
  • Start date
  • #1
35
1

Main Question or Discussion Point

Hey guys.

I recently went into a foray in learning LaTeX for my third year project report, because I want it to look professional and it's a good skill to say I have for PhD application.

I have however hit a stumbling block. Below is some sample code:

Code:
\begin{table}[!h]
	\begin{center}
	\begin{tabular}{|c|c|}

		\hline
		\bf{Name} & \bf{J1501-434} \\\hline
		RA & 15 01 \\\hline
		Dec & -43 \\\hline
		Mag & 12 \\\hline
		Spec Type. & dM0e \\\hline
	\end{tabular}
	\end{center}
		\label{j1501}
		\caption{Observational Data for J1501}
\end{table}
and

Code:
Table \ref{j1501} specifies the data required for observation.
However When I compile this is what I get as output. (Note: the reference isnt in the place i specified, its elsewhere in the document, I just moved it so that you didnt have to troll through my code)

Pretty Table of Data Looking as Expected
Table 1: Observational Data for J1501
And then later on:

Table 1.2 specifies the data required for observation.

I don't understand why its clearly made the table, numero uno, which is right since its the first table I have added, but then when i ref back to it, it thinks its table 1.2 :/

Thanks
 

Answers and Replies

  • #2
CompuChip
Science Advisor
Homework Helper
4,302
47
Does the table happen to be in section 1.2?

If so, try putting the \label command after (or inside) the \caption...
 
  • #3
35
1
You sir, are a genius =D Thank you very much. Changed it to

\caption{\label{j1501}Observational Data for J1501}

And had to compile twice for it to register but it worked fine. So Im guessing that sections automatically become labels, and since I have a section named J1501 its thinking i was referencing to that instead?
 
  • #4
CompuChip
Science Advisor
Homework Helper
4,302
47
Well, basically what \label does is assign the name you give it ("j1501") to the last value that some internal counter was set to. This counter is set, among other things, by chapters and sections.
The table environment does basically nothing except create a floating frame. The incrementing of the table-number counter is done by the \caption command, and this also sets this special counter. So \label only works inside, or after, \caption.
I bet you that
Code:
\begin{table}[!h]
   ...
   \caption{Observational Data for J1501}
\end{table}
\label{j1501}
also does what you want (although maybe not what you expect).
 

Related Threads on [LaTeX] Referencing Issue

Replies
1
Views
19K
  • Last Post
Replies
2
Views
1K
  • Last Post
Replies
6
Views
2K
Replies
3
Views
3K
Replies
8
Views
2K
Replies
0
Views
2K
Replies
2
Views
2K
Replies
1
Views
6K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
8
Views
2K
Top