The scenario comes from a usage of the solution found here.
The actual scenario is much more complex, involving custom environments and longtables. However, the problem can be produced using the following MWE.
\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\newcounter{tp}
\fancyfoot[L]{\stepcounter{tp}\thetp/\ref{tptotal\cc}}
\usepackage{lipsum}
\def\anotherset#1#2{\setcounter{tp}{0}\gdef\cc{#1}
\section{#2}}
\begin{document}
\anotherset{a}{This works fine, no table, text only}
\lipsum[1-10]
% Remember to adjust double increment of the same counter
\refstepcounter{tp}\label{tptotal\cc}\addtocounter{tp}{-1}
\clearpage
\anotherset{b}{This DOES NOT work, table ONLY is forced to move to next page}
\lipsum[1-9]
\begin{tabular}{c}
\hline
One row\\
\hline
One row\\
\hline
One row\\
\hline
One row\\
\hline
One row\\
\hline
One row\\
\hline
One row\\
\hline
\end{tabular}
% Remember to adjust double increment of the same counter
\refstepcounter{tp}\label{tptotal\cc}\addtocounter{tp}{-1}
\clearpage
\anotherset{c}{This works as well, table remains in the same page}
\lipsum[1-20]
\begin{tabular}{c}
\hline
One row\\
\hline
One row\\
\hline
One row\\
\hline
One row\\
\hline
One row\\
\hline
One row\\
\hline
One row\\
\hline
\end{tabular}
% Remember to adjust double increment of the same counter
\refstepcounter{tp}\label{tptotal\cc}\addtocounter{tp}{-1}
\end{document}
My adaptation works fine except when a table alone is forced to move to next page. The same scenario happens for similar objects, e.g., minipage. This works fine when there are some texts before the table in the same page.









\anothersetafter\clearpage? That is, the\sectionstarts on a new page? – Werner Aug 18 '16 at 19:02\sections are not present there. It was used in the MWE only to improve readability. – Masroor Aug 19 '16 at 02:37longtable, along with some starting text. The long table is followed by another shorter three row table. When this last short table is forced alone in the last page of part, the problem occurs. – Masroor Aug 19 '16 at 05:57\def\Label#1{\immediate\protected@write\@auxout{} {\string\newlabel{#1}{{\thetp\relax}{\thepage}}}}and using it. But that did not work. Is this the approach you suggested? – Masroor Aug 19 '16 at 15:21\def\Label#1{\immediate\protected@write\@auxout{} {\string\newlabel{#1}{{\@currentlabel}{}}}}, leaving out\thepage. This also did not work. – Masroor Aug 19 '16 at 15:26