Take this as an example
\begin{figure}[htbp]
\centering
\includegraphics[keepaspectratio, width=0.8\linewidth]{transformer_img.pdf}
\caption{Transformer}
\label{fig:transformer}
\end{figure}
I've searched online but didnt find similar questions? Many questions such as this Is there any difference between nesting \label in \caption and putting \label outside \caption? did not tell me the differences between them.
I wonder where people learnt the basics of this?
Also, from my vague understanding, after using \label{fig:transformer} I can cross-reference the figure anywhere by using \ref{fig:transformer}. Is it right? Besides this, where else can \label be used for?
\captionincrements the figure counter (\refstepcounter{figure}) and writes the caption.\labelwrites\@currentlabeland\thepageto the aux file (\newlabel). The caption packaage and hyperref modify the code is several ways. – John Kormylo Feb 20 '23 at 17:15\label{}is not shown anywhere in the output pdf. – user900476 Feb 20 '23 at 17:17\labelis likeid=in html, it makes no output. It is just an internal name for\refto reference – David Carlisle Feb 20 '23 at 17:17\label{}used for? Im still very confused about this. PS: Oh thank you I see. So It is only used in\ref– user900476 Feb 20 '23 at 17:18see figure \ref{fig:transformer}and latex will fill in the number. It is like having<h2 id="foo">a heading</h2>in html which you link to with<a href="#foo">xxx</a>the textfoodoes not appear in the html – David Carlisle Feb 20 '23 at 17:21\begin{document}in the next run. BTW,\newlabel{foo}{...}will create a global macro\r@foo. – John Kormylo Feb 20 '23 at 17:30