我刚刚发现,使用后tabularx
,我的文档中的表格编号不正确,如下所示
前四个表都是使用 完成的,tabularx
并且都是偶数编号,尽管中间没有其他表,而使用普通完成的表tabularx
编号正确。以下代码是我使用的结构
\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}
除了桌号之外,一切都很好。有什么建议可以解决吗?提前谢谢。
答案1
ltablex
longtable
在后台使用以合并tabularx
可破坏的表格环境的特点。
但是,即使没有命令也会longtable
增加计数器。table
\caption
该\caption
命令应位于longtable
环境内部,此时环境不再是浮动环境,一切正常。在重新定义的tabularx
环境外部使用该命令,环境将会增加table
,外部\caption
将再次对其进行步进,因此表号将按 2 步进,而不是按 1 步进,正如预期的那样。
解决方案:使用\caption
within \begin{tabularx}...\end{tabularx}
,而不是 after 。
在我看来,table
重新定义的环境周围的环境并不是很有用。删除它会使得外部变得不可能,所以除了操纵计数器之外,转移内部是最好的方法tabularx
\caption
tabularx
\caption
tabularx
table
\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}