\label
command has to be placed after the \caption
command, not before.What happens if I put
\label
before \caption
?\label
command has to be placed after the \caption
command, not before.\label
before \caption
?NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
\caption
takes care of the figure counter that \label
should ise. If \label
comes before \caption
, it takes some previous counter, which is wrong.Code: Select all
\documentclass{article}\usepackage{graphicx}\begin{document}\section{Introduction}\section{Figures}\begin{figure}[hb]\centering\includegraphics[height=2cm,width=3cm]{example-image}\label{fig:example}% before \caption, which is wrong\caption{An example figure}\end{figure}\section{Appendix}\begin{figure}[hb]\centering\includegraphics[height=2cm,width=3cm]{example-image}\label{fig:other}% before \caption, which is wrong\caption{Another example figure}\end{figure}% Now we get wrong reference numbers:See example figure \ref{fig:example} and another figure \ref{fig:other}.\end{document}
\label
after \caption
, and the issue is fixed.NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p