I am using the following code:
\documentclass[10pt,onecolumn,twoside,draftcls]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{amsbsy}
\usepackage{placeins}
\let\Oldsection\section
\renewcommand{\section}{\FloatBarrier\Oldsection}
\let\Oldsubsection\subsection
\renewcommand{\subsection}{\FloatBarrier\Oldsubsection}
\let\Oldsubsubsection\subsubsection
\renewcommand{\subsubsection}{\FloatBarrier\Oldsubsubsection}
\usepackage{datatool}
\usepackage{url}
\usepackage{graphicx}
\usepackage{graphics}
\usepackage{epstopdf}
\usepackage{algorithm}
\usepackage{bm}
\usepackage{algorithmic}
\usepackage{subfigure}
\usepackage{cite}
\usepackage{multirow}
\usepackage{pgfplotstable,filecontents}
\usepackage{ctable}
\usepackage{enumitem}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage[pagewise]{lineno}
\renewcommand*\familydefault{\sfdefault}
\begin{document}
\listoffigures
\listoftables
See Figs.~\ref{fig:1} and~\ref{fig:2} and Tables~\ref{table:1} and~\ref{table:2}.
\section{section 1}
\section{section 2} \label{sec4}
\begin{table}[H] \label{table:1}
\caption{table 1 caption}
\end{table}
\begin{figure} [H]\label{fig:1}
\caption{fig 1 caption}
\end{figure}
\subsection{subsection}
\begin{table}[H] \label{table:2}
\caption{table 2 caption}
\end{table}
\begin{figure} [H]\label{fig:2}
\caption{fig 2 caption}
\end{figure}
\end{document}
When I compile, I see that the table numberings are correct in the table, but wrong when I refer to them. They get the number of their section/subsection. The same thing happens for figure numberings as well:
List of Figures
1 fig 1 caption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 fig 2 caption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
List of Tables
1 table 1 caption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 table 2 caption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
See Figs. 2 and 2.1 and Tables 2 and 2.1.
1 section 1
2 section 2
Table 1: table 1 caption
Figure 1: fig 1 caption
2.1 subsection
Table 2: table 2 caption
Figure 2: fig 2 caption 1
I need that the table numberings become independent of the section/subsection. The numbering starts at 1, and when I add a new table, it increases by 1. The same when I refer to them. I want the same thing for figure numberings as well. Can you help?
I got a comment that the label has to be placed after the caption. I did that but nothing changed. The same issue is there. So, this is not duplicate.
Edit after the second comment: I fixed it. The label has to be placed right after the caption. What I did and did not work was placing the label after caption, but it was not right after the caption. It was after the \end{figure} or \end{table}. When I put it right after the caption, it works.
\labelcommands are input before the\captionfor each table. It's the caption that resets the numbering, so placing the label before the caption will refer to whatever the previous element was that has a referenceable number. (This is certainly a duplicate; I'll look for a suitable one.) – barbara beeton Nov 28 '19 at 19:20.auxfile in the first run, and read back in in the second run. Unless you delete the.auxfile(s) first (which will force you to run the job twice, and which I should have mentioned earlier), you will still be getting the "old" values. So the safest approach is to delete the.auxfile(s) before rerunning. If this doesn't change anything, something is seriously wrong. – barbara beeton Nov 28 '19 at 19:54\labelin teh wrong place, before\captionyou have\label{fig:1} \caption{fig 1 caption}– David Carlisle Nov 28 '19 at 23:16fig:2as the label has no connection to the printed number and it's confusing to look at the source if Figure 4 has labelfig:3– David Carlisle Nov 28 '19 at 23:18\label{fermat}then\ref{fermat}will make whatever number fermat's last theorem gets in the final presentation. – David Carlisle Nov 29 '19 at 09:10