Troubleshooting LaTeX Referencing Issues for Your Third Year Project Report

  • Context: LaTeX 
  • Thread starter Thread starter ajclarke
  • Start date Start date
  • Tags Tags
    Latex
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 3K views
ajclarke
Messages
34
Reaction score
1
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 isn't 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
 
Physics news on Phys.org
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 I am guessing that sections automatically become labels, and since I have a section named J1501 its thinking i was referencing to that instead?
 
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).