修改 Latex 中的自动表格编号

修改 Latex 中的自动表格编号

我正在写一篇论文,其中附件包含一系列表格。

我的文档中的所有表格都已编号,但我希望附件中的表格开始新的编号。以下表为例:

\begin{table}[!htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{My very interesting table is in the first in one in the Annex \label{tab:mytab}}
\small\begin{tabularx}{\textwidth}{l>{\centering}X>{\centering}X>{\centering}X>{\centering\arraybackslash}X}
\toprule
                    &\multicolumn{2}{c}{FIRST DV}     &\multicolumn{2}{c}{SECOND DV} \\\cmidrule(lr){2-3}\cmidrule(lr){4-5}
                    &\multicolumn{1}{c}{(1)}         &\multicolumn{1}{c}{(2)}         &\multicolumn{1}{c}{(3)}         &\multicolumn{1}{c}{(4)}         \\
\midrule

WTO Membership      &       0.045\sym{*}  &       0.051\sym{*}  &      -0.095         &      -0.190         \\
                    &     (0.023)         &     (0.026)         &     (0.078)         &     (0.116)         \\
Export \% of GDP    &       0.001         &       0.000         &       0.001         &       0.005         \\
                    &     (0.001)         &     (0.001)         &     (0.003)         &     (0.004)         \\
\midrule
N                   &     874.000         &     874.000         &     896.000         &     896.000         \\
Country FE          &         yes         &         yes         &         yes         &         yes         \\

Hansen J            &       0.971         &       0.960         &       0.193         &       0.937         \\
\bottomrule
\multicolumn{5}{p{\linewidth}}{\footnotesize my footnote}\\
\end{tabularx}
\end{table}

在正文中它产生以下输出:

在此处输入图片描述

表格是正确的,但它的编号为“表格 2”,因为它是文档的第二个表格。有没有办法更改表格的编号?我有两个目标:首先,如果这些表格在附件中,则在表格编号前面添加一个“A”:例如“表格 A1”和“表格 A2”;其次是从附件重新开始计数。因此,即使在正文中还有其他表格提前出现,附件中的第一个表格也应该编号为“表格 A1”。

这是主要的 tex 文件。也许某些标题有问题?

% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
\PassOptionsToPackage{dvipsnames,svgnames*,x11names*}{xcolor}
%
\documentclass[
]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
  pdftitle={title},
  pdfauthor={name},
  colorlinks=true,
  linkcolor=blue,
  filecolor=Maroon,
  citecolor=Blue,
  urlcolor=Blue,
  pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage[margin=1in]{geometry}
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}
\usepackage{dcolumn}
\usepackage{amsmath}
\usepackage[fontsize=11pt]{scrextend}
\usepackage{indentfirst}
\usepackage{dcolumn}
\usepackage{multirow}
\usepackage{rotating,booktabs}
\usepackage{caption}
\usepackage{longtable}
\usepackage{lscape}
\usepackage{tabularx}
\usepackage{threeparttable}
\usepackage{adjustbox}
\usepackage{ragged2e}
\usepackage{float}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{threeparttablex}
\usepackage{siunitx}
\usepackage{lipsum}
\usepackage{tablefootnote}

\title{title}
\author{name}
\date{\today}

\begin{document}
\maketitle

{
\hypersetup{linkcolor=}
\setcounter{tocdepth}{2}
\tableofcontents
}
\captionsetup{
  justification = centering
}

\begin{table}[!htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{This is a table in the main text \label{tab:mytab}}
\small\begin{tabularx}{\textwidth}{l>{\centering}X>{\centering}X>{\centering}X>{\centering\arraybackslash}X}
\toprule
                    &\multicolumn{2}{c}{FIRST DV}     &\multicolumn{2}{c}{SECOND DV} \\\cmidrule(lr){2-3}\cmidrule(lr){4-5}
                    &\multicolumn{1}{c}{(1)}         &\multicolumn{1}{c}{(2)}         &\multicolumn{1}{c}{(3)}         &\multicolumn{1}{c}{(4)}         \\
\midrule

IV      &       0.045\sym{*}  &       0.051\sym{*}  &      -0.095         &      -0.190         \\
                    &     (0.023)         &     (0.026)         &     (0.078)         &     (0.116)         \\
IV2    &       0.001         &       0.000         &       0.001         &       0.005         \\
                    &     (0.001)         &     (0.001)         &     (0.003)         &     (0.004)         \\
\midrule
N                   &     874.000         &     874.000         &     896.000         &     896.000         \\
Country FE          &         yes         &         yes         &         yes         &         yes         \\

Hansen J            &       0.971         &       0.960         &       0.193         &       0.937         \\
\bottomrule
\multicolumn{5}{p{\linewidth}}{\footnotesize my footnote}\\
\end{tabularx}
\end{table}

\newpage
ANNEX

\begin{table}[!htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{My very interesting table is in the first in one in the Annex \label{tab:mytab}}
\small\begin{tabularx}{\textwidth}{l>{\centering}X>{\centering}X>{\centering}X>{\centering\arraybackslash}X}
\toprule
                    &\multicolumn{2}{c}{FIRST DV}     &\multicolumn{2}{c}{SECOND DV} \\\cmidrule(lr){2-3}\cmidrule(lr){4-5}
                    &\multicolumn{1}{c}{(1)}         &\multicolumn{1}{c}{(2)}         &\multicolumn{1}{c}{(3)}         &\multicolumn{1}{c}{(4)}         \\
\midrule

WTO Membership      &       0.045\sym{*}  &       0.051\sym{*}  &      -0.095         &      -0.190         \\
                    &     (0.023)         &     (0.026)         &     (0.078)         &     (0.116)         \\
Export \% of GDP    &       0.001         &       0.000         &       0.001         &       0.005         \\
                    &     (0.001)         &     (0.001)         &     (0.003)         &     (0.004)         \\
\midrule
N                   &     874.000         &     874.000         &     896.000         &     896.000         \\
Country FE          &         yes         &         yes         &         yes         &         yes         \\

Hansen J            &       0.971         &       0.960         &       0.193         &       0.937         \\
\bottomrule
\multicolumn{5}{p{\linewidth}}{\footnotesize my footnote}\\
\end{tabularx}
\end{table}





\end{document}

相关内容