2

The code below shows in the caption "table 1", which is correct, but in the text reference, it shows "table 2". How can I fix that?

\documentclass[]{article}

\begin{document}
\section{Description}
\section{Measurements}
\label{sec:measx}
Table \ref{tab:meas}
\begin{table}[ht]
\label{tab:meas}
\begin{tabular}{|c|c|}
\hline
A   & B \\ \hline
\end{tabular}
\caption {Measurements}
\end{table}

\end{document}

enter image description here

5
  • 4
    You need to put \label in or after \caption.
    – user121799
    Commented Aug 24, 2018 at 4:15
  • Moving \label to the line after \caption makes no difference. Moving \label inside \caption{\label{} Measurements} does not make any difference either. Removing the previous \section works. It seems to mixup \section and \table enumerations.
    – Fabio
    Commented Aug 24, 2018 at 4:23
  • 1
    you have to compile two times until the label will be correct.
    – user2478
    Commented Aug 24, 2018 at 4:35
  • Yes, I am aware two compilations are needed. It does not work. Tried both on overleaf.com| and cygwin latex. overleaf.com/18835735vkgdyqsjfwdk
    – Fabio
    Commented Aug 24, 2018 at 6:02
  • 1
    I was moving below \caption the wrong label (the \label{sec:measx} one). It work, thanks.
    – Fabio
    Commented Aug 24, 2018 at 6:13

2 Answers 2

3

Too long for a comment. If I compile

\documentclass[]{article}

\begin{document}
\section{Description}
\section{Measurements}
\label{sec:measx}
Table \ref{tab:meas}
\begin{table}[ht]

\begin{tabular}{|c|c|}
\hline
A   & B \\ \hline
\end{tabular}
\caption {Measurements\label{tab:meas}}
\end{table}

\end{document}

on my TeXLive2018 distribution, I get

enter image description here

If you do not get that result, you have either not compiled twice or there is something really wrong with your TeX installation.

3

you also got the same result as in marmot answer with the following mwe (note, table label is after table caption):

\documentclass{article}

\begin{document}
\section{Description}
\section{Measurements}
\label{sec:measx}

Table \ref{tab:meas}

\begin{table}[ht]
\begin{tabular}{|c|c|}
\hline
A   & B \\ \hline
\end{tabular}
\caption {Measurements}
\label{tab:meas} % <---
\end{table}

\end{document}

tested in overleaf:

enter image description here

Not the answer you're looking for? Browse other questions tagged .