2

Im new to this, I just have a simple question.

How to declare a table let's say after I mention it in the text.

What I want:

Blah blah blah blah blah blah blah blah blah as shown in Table ~\ref{tab:table_Languages}

MY TABLE CAPTION

| Rank | Language | Share | Trend |
-----------------------------
....

What I have:

MY TABLE CAPTION

| Rank | Language | Share | Trend |
-----------------------------
.....

Blah blah blah blah blah blah blah blah blah as shown in Table ~\ref{tab:table_Languages}

What I use:

\begin{table}
    \centering
    \label{tab:table_Languages}
    \setlength{\tabcolsep}{0.3cm}
    \begin{tabular}{|c|p{2cm}|l|l|}
        \hline
        \textbf{Rank} & \textbf{Language} & \textbf{Share} & \textbf{Trend} \\ 
        \hline 
        \textbf{1} & Python     & 26.42\%  & +5.2\% \\ \hline
        \textbf{2} & Java       & 21.20\%  & -1.3\% \\ \hline
        \textbf{3} & JavaScript & 08.21\%  & -0.3\% \\ \hline
        \textbf{4} & C\#        & 07.57\%  & -0.5\% \\ \hline
        \textbf{5} & PHP        & 07.34\%  & -1.2\% \\ \hline
        \textbf{6} & C/C++      & 06.23\%  & -0.3\% \\ \hline
        \textbf{7} & R          & 04.13\%  & -0.1\% \\ \hline
    \end{tabular}
\end{table}

UPDATE:

Adding \caption{Best ranking Programming Languages in 2019.} creates a nice caption above my example. However it doesn't fix the position and also the value of the counter for the tables is not right, as it gets the Chapter number for a reason as shown in the figure.

Demo

1 Answers1

3

(updated the answer to include the OP's piece of information that the bangorcsthesis document class is in use)

You're almost there: In addition to providing \label and \ref statements, you need to inform LaTeX which counter or item to associate the \label with. In the case of figure and table environments, the way to make this association is to issue a \caption directive. This directive not only typesets a (hopefully meaningful) caption, it also increments a figure or table counter in such a way that the subsequent \label statement "knows" what to latch on to. Incidentally, because \label statements try to "latch on" to the most recently incremented counter variable, it is essential to issue figure- and table-related \label statements after the corresponding \caption statements.

The LaTeX kernel provides the basic, yet flexible and quite powerful \label-\ref mechanism. Many LaTeX packages have been written to extend this basic mechanism. Please see the posting Cross-reference packages: which to use, which conflict? for more information about these packages.

enter image description here

\documentclass[bsc]{bangorcsthesis}
\usepackage{array} % for "\newcolumntype" macro
\newcolumntype{C}{>{\bfseries}c}
\begin{document}
\setcounter{chapter}{3} % just for this example

\begin{table}
\centering
\caption{Best Programming Languages in 2019}
\label{tab:table_Languages}
\setlength{\tabcolsep}{3mm}
\begin{tabular}{|C|l|l|r|}
\hline
Rank & \textbf{Language} & \textbf{Share} & \textbf{Trend} \\ 
\hline 
1 & Python     & 26.42\%  & +5.2\% \\ 
2 & Java       & 21.20\%  & $-$1.3\% \\ 
3 & JavaScript & 08.21\%  & $-$0.3\% \\ 
4 & C\#        & 07.57\%  & $-$0.5\% \\ 
5 & PHP        & 07.34\%  & $-$1.2\% \\ 
6 & C/C++      & 06.23\%  & $-$0.3\% \\ 
7 & R          & 04.13\%  & $-$0.1\% \\ 
\hline
\end{tabular}
\end{table}

\noindent
\dots as shown in Table~\ref{tab:table_Languages}, \dots

\end{document}
Mico
  • 506,678
  • I updated my question due to some issues. – Loizos Vasileiou Mar 06 '19 at 19:37
  • @LoizosVasileiou - I've updated my answer to reflect the pieces of information that (a) you use the bangorcsthesis document class and (b) that the table occurs somewhere in chapter 3. – Mico Mar 06 '19 at 20:53