# Table number not right after using tabularx

I just found that after I used tabularx, the table number in my document is not right, shown as follows

where the first four tables were done using tabularx and they are all even numbered, despite the fact that no other tables are there in between, while the tables done using normal tabularx are numbered rightly. The following code is the structure I used

\documentclass[12pt]{article}
\usepackage[margin=0.85in, paperwidth=8.5in, paperheight=11in ]{geometry}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage{subcaption}
\newsavebox{\largestimage}
\usepackage{tocloft}
\newlength{\mylen}
\usepackage{siunitx}   %%package for scientific notation

\renewcommand{\cftfigpresnum}{\figurename\enspace}
\renewcommand{\cftfigaftersnum}{:}
\settowidth{\mylen}{\cftfigpresnum\cftfigaftersnum}

\renewcommand{\cfttabpresnum}{\tablename\enspace}
\renewcommand{\cfttabaftersnum}{:}
\settowidth{\mylen}{\cfttabpresnum\cfttabaftersnum}

\usepackage{verbatim}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{pdflscape}
\usepackage{soul}
\usepackage{color}
\usepackage{url}

%\captionsetup[table]{aboveskip=0pt}
\captionsetup[table]{belowskip=11pt}

%%%%%tables
\usepackage{geometry}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{ltablex}
\usepackage{ragged2e}
\usepackage{enumitem}
\usepackage{makecell}
\usepackage{textcomp}
\renewcommand\tabularxcolumn[1]{>{\RaggedRight\arraybackslash}p{#1}}
\newcommand{\tabitem}{~~\llap{\textbullet}~~} %%% bullet in table

\renewcommand{\baselinestretch}{1.5}
\numberwithin{equation}{section}
\numberwithin{figure}{section}
\numberwithin{table}{section}

\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage[
backend=biber,
natbib=true,
hyperref=true,
style=authoryear,firstinits,
uniquename=false,
doi=false,
isbn=false,
url=false,
mincitenames=1,
maxcitenames=2,
maxbibnames=999,
]{biblatex}
\setlength\bibitemsep{\baselineskip}
\DeclareNameAlias{sortname}{family-given}

\usepackage{float}
\usepackage{hyperref}
\hypersetup{
citecolor    = Blue
}
\usepackage{filecontents}

\usepackage[utf8]{inputenc} %%page number
\usepackage[english]{babel}
\setlength{\parindent}{0pt} %no indentation
\usepackage{mathptmx}
\begin{document}
\begin{center}
\begin{table}[H]
\footnotesize\keepXColumns
\setcellgapes{3pt}\makegapedcells
\setlist[itemize]{wide =0pt, leftmargin=*, nosep, before=\vspace{-\baselineskip}, after = \vspace{-\baselineskip}}
\begin{tabularx}{\linewidth}{|c |X |} \hline
\hline
\textbf{Things One} &  Content One\\
\hline
\end{tabularx}
\caption[Blah Blah]{Blah Blah}
\label{tab:one}
\end{table}
\end{center}
\end{documen}


and how it looks like in the report

Everything is fine apart from the table number. Any suggestions on how to fix it. Thanks in advance.

– TH.
Jun 15, 2017 at 3:47
• A minimal working example is the code that is minimal and has the same issue as described. The code above misses \documentclass, the relevant packages and is not compilable
– user31729
Jun 15, 2017 at 4:16
• @ChristianHupfer I've added whatever package I used for my thesis, cz It is really long, I am not sure which one is for the table now. Jun 15, 2017 at 4:30
• @ZhifangHu: You're using ltablex which is the longtable version for tabularx. Just put the \caption and the \label command before \end{tabularx}
– user31729
Jun 15, 2017 at 4:40

ltablex uses longtable in the background in order to merge the features of tabularx and breakable tabular environment.

However, longtable increases the table counter even if there is no \caption command.

The \caption command should be inside in the longtable environment, which is no floating environment then and everything will be alright. Using it outside in the redefined tabularx environment the environment will increase table and the outer \caption will step it again, so the table number steps by 2 and not by one, as expected.

Solution: Use \caption within \begin{tabularx}...\end{tabularx}, not after it.

The table environment around the redefined tabularx environment is not really useful, in my point of view. Removing it would make \caption outside of tabularx impossible any way, so shifting the \caption inside of tabularx is the best way, other than manipulating the table counter

\documentclass[12pt]{article}
\usepackage{longtable}
\usepackage{ltablex}

\begin{document}

\begin{longtable}{c}

\end{longtable}

The table number is now: \thetable -- although there is no caption command.

\begin{table}
\centering
\begin{tabularx}{\linewidth}{|c |X |}
\hline
\caption[Blah Blah]{Blah Blah}    \label{tab:inside}  % 'Correct' counting should be 2
\end{tabularx}
\end{table}

% Now with wrong \caption outside

\begin{table}
\centering
\begin{tabularx}{\linewidth}{|c |X |}
\hline
\end{tabularx}
\caption[Blah Blah]{Blah Blah}    \label{tab:outside} % Now tabularx increases and \caption increases again: counter is 4
\end{table}
\end{document}