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}
\addtolength{\cftfignumwidth}{\mylen}
\renewcommand{\cfttabpresnum}{\tablename\enspace}
\renewcommand{\cfttabaftersnum}{:}
\settowidth{\mylen}{\cfttabpresnum\cfttabaftersnum}
\addtolength{\cfttabnumwidth}{\mylen}
\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{
colorlinks = true,
citecolor = Blue
}
\usepackage{filecontents}
\addbibresource{MyCollection.bib}
\usepackage[utf8]{inputenc} %%page number
\usepackage[english]{babel}
\setlength{\parindent}{0pt} %no indentation
\usepackage{mathptmx}
\begin{document}
\begin{center}
\begin{table}[H]
\footnotesize\keepXColumns
\renewcommand\theadfont{\bfseries\itshape}
\setcellgapes{3pt}\makegapedcells
\setlist[itemize]{wide =0pt, leftmargin=*, nosep, before=\vspace{-\baselineskip}, after = \vspace{-\baselineskip}}
\begin{tabularx}{\linewidth}{|c |X |} \hline
\thead{Title One} & \thead{Title Two} \\
\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.
Best Answer
ltablex
useslongtable
in the background in order to merge the features oftabularx
and breakable tabular environment.However,
longtable
increases thetable
counter even if there is no\caption
command.The
\caption
command should be inside in thelongtable
environment, which is no floating environment then and everything will be alright. Using it outside in the redefinedtabularx
environment the environment will increasetable
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 redefinedtabularx
environment is not really useful, in my point of view. Removing it would make\caption
outside oftabularx
impossible any way, so shifting the\caption
inside oftabularx
is the best way, other than manipulating thetable
counter