我尝试使用定理连续编号表格时遇到错误

我尝试使用定理连续编号表格时遇到错误

egreg请在此回答我(之前提出的)关于给予数字与定理相同编号的问题:

按顺序对表格进行编号

不幸的是,这个非常好的解决方案似乎与我所依赖的现有代码不兼容(希望可以轻松修复)。这是我的文档的模仿版本。

\documentclass{article}
\usepackage{amsmath,amsthm,thmtools,float,cleveref}

\declaretheorem[name=Theorem,numberwithin=section]{thm}
\newtheorem{theorem}[thm]{Theorem}
\newtheorem{corollary}[thm]{Corollary}
\newtheorem{theorem}[table]{Theorem}

\begin{document}
Look at \Cref{TABLE}!

\begin{restatable}{theorem}{TheThm}\label{THM}
I said to look at \Cref{TABLE}!
\end{restatable}

\begin{theorem}[Best theorem]
Hello, world!
\end{theorem}
\begin{table}[H]    
\caption{Good table-caption}\label{TABLE}
\begin{center}
\begin{tabular}{l | l}
ABCD & EFG \end{tabular}
\end{center}
\end{table}

That was so exquisite we must recapitulate:
\TheThm*

\end{document}

我收到以下警告:LaTeX Error: Command \theorem already defined. Or name \end... illegal, see p.192 of the manual.这似乎部分是因为我有\newtheorem{theorem}[thm]{Theorem}。但如果我删除它,文档似乎不再知道定理是什么。

删除thmtools会出现不同的错误,但我想使用该restatable环境。

我天真地猜测如何处理

\newtheorem{theorem}[table]{Theorem}

以避免错误——即用

\newtheorem{table}[thm]{Table}

—也没有成功。

我还想找到一种方法来让文本“[0377]表 XX“如果可能的话,像定理标题一样加粗。也许这应该是另一个问题。

答案1

问题是你声明了theorem两次,首先

\newtheorem{theorem}[thm]{Theorem}

进而

\newtheorem{theorem}[table]{Theorem}

我也不会混淆用\declaretheorem和做出的声明\newtheorem

就您而言,我认为以下操作应该可以满足您的要求:

\newtheorem{theorem}[table]{Theorem}
\newtheorem{corollary}[table]{Corollary}

\numberwithin{table}{section}
\numberwithin{theorem}{section}
\numberwithin{corollary}{section}

关于您的上一个请求,请加载包caption并发出

\captionsetup[table]{labelfont=bf}

完成 MWE:

\documentclass{article}
\usepackage{amsmath,amsthm,thmtools,float,cleveref}
\usepackage{caption}

\captionsetup[table]{labelfont=bf}

\newtheorem{theorem}[table]{Theorem}
\newtheorem{corollary}[table]{Corollary}

\numberwithin{table}{section}
\numberwithin{theorem}{section}
\numberwithin{corollary}{section}

\begin{document}

\section{Test}

Look at \Cref{TABLE}!

\begin{restatable}{theorem}{TheThm}\label{THM}
I said to look at \Cref{TABLE}!
\end{restatable}

\begin{theorem}[Best theorem]
Hello, world!
\end{theorem}
\begin{table}[H]
\caption{Good table-caption}\label{TABLE}
\begin{center}
\begin{tabular}{l | l}
ABCD & EFG \end{tabular}
\end{center}
\end{table}

\begin{corollary}
And this is a corollary
\end{corollary}

That was so exquisite we must recapitulate:
\TheThm*

\end{document} 

输出:

在此处输入图片描述


编辑

要使表格和图形具有相同的编号,请在序言中添加以下几行:

\makeatletter
\let\c@figure\c@table
\makeatother

另外,如果你不想\numberwithin多次使用,也可以按照以下方式进行。首先,声明

\numberwithin{table}{section}
\numberwithin{figure}{section}

然后按如下方式声明类定理环境:

\declaretheorem[numberlike=table]{theorem}
\declaretheorem[numberlike=theorem]{corollary}

完成 MWE:

\documentclass{article}
\usepackage{amsmath,amsthm,thmtools,float,cleveref}
\usepackage{graphicx}
\usepackage{caption}

\captionsetup{labelfont=bf}

\numberwithin{table}{section}
\numberwithin{figure}{section}

\makeatletter
\let\c@figure\c@table
\makeatother

\declaretheorem[numberlike=table]{theorem}
\declaretheorem[numberlike=theorem]{corollary}

\begin{document}

\section{Test}

Look at \Cref{TABLE}!

\begin{restatable}{theorem}{TheThm}\label{THM}
I said to look at \Cref{TABLE}!
\end{restatable}

\begin{theorem}[Best theorem]
Hello, world!
\end{theorem}

\begin{table}[H]
\caption{Good table-caption}\label{TABLE}
\centering
\begin{tabular}{l | l}
ABCD & EFG \end{tabular}
\end{table}

\begin{corollary}
And this is a corollary
\end{corollary}

\begin{figure}[H]
\caption{Good figure-caption}\label{FIGURE}
\centering
\includegraphics[scale=.3]{example-image}
\end{figure}

That was so exquisite we must recapitulate:
\TheThm*

\end{document} 

输出

在此处输入图片描述

答案2

因为真正的问题出现在带有 的文档中\chapter,所以您的代码有一些修改。相关的代码已标记为 PS。

\documentclass{report}
%\usepackage{amsmath,amsthm,thmtools,float,cleveref}
\usepackage{amsmath,amsthm,float,cleveref}

%\declaretheorem[name=Theorem,numberwithin=section]{thm}
%\newtheorem{theorem}[thm]{Theorem}
\newtheorem{theorem}{Theorem}
%\newtheorem{corollary}[thm]{Corollary}
%\newtheorem{theorem}[table]{Theorem}


\def\thetable{\arabic{table}} % This is important - PS
\begin{document}
\chapter{First}
\section{First}

Look at \Cref{TABLE}!

%\begin{restatable}{theorem}{TheThm}\label{THM}
\begin{table}
\label{THM}
I said to look at \Cref{TABLE}!
\end{table}
%\end{restatable}

\begin{theorem}[Best theorem]
Hello, world!
\end{theorem}
\begin{table}[H]    
\caption{Good table-caption}\label{TABLE}
\begin{center}
\begin{tabular}{l | l}
ABCD & EFG \end{tabular}
\end{center}
\end{table}

That was so exquisite we must recapitulate:
%\TheThm*

\end{document}

(由于某种奇怪的原因,我的图片在这里完全是黑色的。如果有人可以尝试,如果这是我的问题或网站的问题,请...)

相关内容