LaTeX Troubleshooting LaTeX Referencing Issues for Your Third Year Project Report

  • Thread starter Thread starter ajclarke
  • Start date Start date
  • Tags Tags
    Latex
AI Thread Summary
The discussion revolves around a user learning LaTeX for a project report and encountering an issue with table referencing. The user provided sample code for a table and noted that while the table was correctly numbered as Table 1, the reference later appeared as Table 1.2. The solution involved placing the \label command after the \caption command, which resolved the issue upon recompiling the document. It was clarified that the \label command assigns a name to the last value of an internal counter, which is influenced by sections and chapters. The table environment itself does not affect numbering; instead, the \caption command increments the table-number counter. The user learned that proper placement of the \label is crucial for accurate referencing in LaTeX.
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
Does the table happen to be in section 1.2?

If so, try putting the \label command after (or inside) the \caption...
 
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).
 

Similar threads

Replies
9
Views
2K
Replies
3
Views
2K
Replies
3
Views
3K
Replies
2
Views
3K
Replies
1
Views
2K
Replies
2
Views
6K
Back
Top