Sequence of Caption and Label in Latex Table Matters
Introduction
Once I was writing papers on Overleaf, I met an error about the numbering of tables in Latex. When referring several different tables, I've gotton the same numbering. After trying some alternatives of sequencing of the elements inside a table, I've found out that the order of caption and label can't be exchanged.Table in Latex
Tables are common elements in academic reports and scientific research papers. Latex provides a wide range of customization of tables, such changing sizes, combining cells, modifying the colors etc. The following code snapshot illustrates how to construct a basic table in Latex.\begin{table}[h!]
\centering
\caption{Table 1.}
\label{tab:1}
\begin{tabular}{|c|c|c|}
\hline
cell1 & cell2 & cell3 \\
\hline
cell4 & cell5 & cell6 \\
\hline
cell7 & cell8 & cell9 \\
\hline
\end{tabular}
\end{table}
\begin{table}[h!]
\centering
\label{tab:2}
\caption{Table 2.}
\begin{tabular}{|c|c|c|}
\hline
cell1 & cell2 & cell3 \\
\hline
cell4 & cell5 & cell6 \\
\hline
cell7 & cell8 & cell9 \\
\hline
\end{tabular}
\end{table}
\begin{enumerate}
\item Table \ref{tab:1} should be Table 1.
\item Table \ref{tab:2} should be Table 2.
\item Table \ref{tab:3} should be Table 3.
\end{enumerate}
After compilation, you can see that the reference of the second table is missing while the first and third table is referred nicely. This project can be accessed here.
