3

egreg kindly answered my (previously-asked) question about giving numbers the same numbering as theorems here:

Numbering tables sequentially.

Unfortunately, this very good solution seems to be incompatible (in what is hopefully an easily fixable way) with preexisting code I've grown attached to. Here's a parody version of my document.

\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}

I get the following warning: LaTeX Error: Command \theorem already defined. Or name \end... illegal, see p.192 of the manual. It seems to be in part because I have \newtheorem{theorem}[thm]{Theorem}. But if I remove that, the document doesn't seem to know what a Theorem is anymore.

Removing thmtools gives a different error, but I want to use the restatable environment.

My naive guess for what to do with

\newtheorem{theorem}[table]{Theorem}

so as to obviate against the error—namely, to replace it with

\newtheorem{table}[thm]{Table}

—does not meet with success either.

I'd also like a way to make the text "Table X.X" bold like the theorem headings, if that's possible. Perhaps that should be another question.

2 Answers 2

4

The problem is that you are declaring theorem twice, first

\newtheorem{theorem}[thm]{Theorem}

and then

\newtheorem{theorem}[table]{Theorem}

I wouldn't also mix declarations made with \declaretheorem and with \newtheorem.

In your case, I think that the following should do what you want:

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

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

About your last request, load the package caption and issue

\captionsetup[table]{labelfont=bf}

Complete 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} 

Output:

enter image description here


EDIT

To have the same numbering for tables and figures, add the following lines in your preamble:

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

Also, if you don't want to use \numberwithin many times, you can proceed in this way. First of all, declare

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

and then declare your theorem-like environment as follows:

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

Complete 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} 

Output

enter image description here

2
  • Thanks! So, is the key takeaway that everything should be redefined to use the table counter? What if I had figures as well? What's the reasoning against mixing \declaretheorem with \newtheorem? I have many more theorem-types in the real document, and would rather not have to have a separate \numberwithin statement for each.
    – jdc
    Dec 15, 2014 at 8:14
  • 1
    @jdc See the edit. Dec 15, 2014 at 16:20
1

Because the real problem will be in documents with \chapter, there are some modifications of you code. Relevant one is marked 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}

(For some strange reason my picture was completely black here. If someone could try, if it is mine or the site's problem, please...)

1
  • This is currently an article, but it will be placed into something with chapters, so I appreciate this warning.
    – jdc
    Dec 15, 2014 at 8:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .