2

I am using a template given by the department, the tables I create as of now was only in chapter 2 which used to come as \label{tab:my_label} generates a label Table 2.1 for first table of chapter 2.

table 2.1

But now in chapter 3 I create another table. Here is how my relevant section of code.

appear below the table (See Table \ref{Table 1}).
\begin{table}[h]
\begin{center}
\vspace{1ex}
\begin{tabular}{|c|c|} \hline
    {\bf Technique} & {\bf Category} \\\hline
    Supervised anomaly detection &   A\\
    \hline
    Semi Supervised Anomaly Detection & B \\ \hline
    Unsupervised anomaly detection & C\\
    \hline
\end{tabular}
\caption{\label{tab:my_label}Type of anomaly detection techniques.}
\end{center}
\end{table}

but now in the above code I do not know how to refer to table in chapter 3. The above code is in chapter 3 for the table 3.1 .

table 3.1

The name table 3.1 is automatically generated with \label{tab:my_label}. But I am not able to understand how do I refer to this table within the chapter or even outside the chapter. The full template with which I am working can be seen here.

4
  • 5
    Use a speaking name in the label, e.g. \label{tab:anomaly-detection}, and then \ref{tab:anomaly-detection}. Btw: the number in the table is not created by the \label command, but by the \caption. Commented May 6, 2020 at 17:40
  • 1
    oh I did not knew this it was so simple. Do we need to do same for referencing images in the document.
    – koeradoera
    Commented May 6, 2020 at 17:45
  • 2
    You can label almost everything (if is has a counter). Put e.g. \label{sec:something} behind a section command and then look what \ref{sec:something} gives. figures works too, as soon as the \label is in or behind the \caption. Commented May 6, 2020 at 17:47
  • 1
    There are also \pageref. Try` see table \ref{...} in page \pageref{...}.
    – Fran
    Commented May 6, 2020 at 17:49

1 Answer 1

2

There are no problems in your example, as long as you use different labels (that is, the argument of \label{} for every figure/table of floating element that you have. Just remember to always put \label after \caption (it is the latter that creates the number, as Ulrike already said).

Also, prefer \centering instead of \begin{center} ... \end{center}

\documentclass{article}

\begin{document}
\begin{table}[tb]
    \centering
    \caption{Type of anomaly detection techniques.}
    \label{tab:my_label}
    \begin{tabular}{|c|c|} \hline
        {\bf Technique} & {\bf Category} \\\hline
        Supervised anomaly detection &   A\\
        \hline
        Semi Supervised Anomaly Detection & B \\ \hline
        Unsupervised anomaly detection & C\\
        \hline
    \end{tabular}
\end{table}
Here is a reference \ref{tab:my_label} and a page reference \pageref{tab:my_label}.
\end{document}

I can also suggest the use of the cleveref package ;)

enter image description here

2
  • 1
    Instead {\bf Technique} in LaTeX is more correct to use \textbf{Technique}} or if you more prefer {\bfseries Techniques} :-)
    – Zarko
    Commented Oct 4, 2020 at 2:15
  • thanks for pointing that out! Commented Oct 9, 2020 at 8:17

You must log in to answer this question.

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