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}
——也沒有成功。
我還想要一種製作文字的方法“表二十「如果可能的話,像定理標題一樣加粗。也許這應該是另一個問題。
答案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}
(由於某種奇怪的原因,我的圖片在這裡完全是黑色的。如果有人可以嘗試,如果是我的問題或網站的問題,請...)