225

How can you refer to a table number such that you get Table 7 for instance?

Sample data

Table \ref{table:questions} lorem lorem ipsun.

\begin{table}
\label{table:questions}
\begin{tabular}{| p{5cm} | p{5cm} | p{5cm} |}
  -- cut --
\end{tabular}
\end{table}

I get

Table 2.5 lorem lorem ipsun.

where 2.5 is the chapter number.

nbro
  • 15,395
  • 32
  • 113
  • 196
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

1 Answers1

419

You must place the label after a caption in order to for label to store the table's number, not the chapter's number.

\begin{table}
\begin{tabular}{| p{5cm} | p{5cm} | p{5cm} |}
  -- cut --
\end{tabular}
\caption{My table}
\label{table:kysymys}
\end{table}

Table \ref{table:kysymys} on page \pageref{table:kysymys} refers to the ...
dreamlax
  • 93,976
  • 29
  • 161
  • 209
  • 3
    For some reason, this pushes the table and caption to the bottom of the page, resulting in the caption to be the last sentence on the page, where the table sits nicely on top of the caption. _How can I remedy this, so that it just sits underneath the last typed sentence?_ I suspect it's to do with the `\beign{table}` and `\end{table}` command... – 3kstc Apr 29 '18 at 08:18
  • 3
    @3kstc You might try asking at https://tex.stackexchange.com/ – Increasingly Idiotic May 06 '18 at 06:54
  • 7
    @3kstc, i had the same problem, solved by changing \begin{table} to \begin{table}[H] from \usepackage{float} – Eurobeat Intensifies May 18 '18 at 12:12
  • @Anton Yes! I did that just that, it resolved all my problems – 3kstc May 18 '18 at 12:27
  • 1
    2019 Almost, the accepted answer is still valid. Ten years later. Just updating as I myself was skeptical at first. – Arka Mallick Nov 24 '18 at 05:20
  • Another note: if you were trying to put your table in a `figure` . . . *don't*. Merely `table` produces the desired effect. – geometrian Apr 15 '21 at 18:42
  • Placing the \caption before \begin{tabular} resolved the problem for me by placing the caption above the table. – Ishrak Apr 27 '23 at 08:06
  • mine put '??' instead of reference, anybody knows? – zEn feeLo Jun 22 '23 at 13:30