我有很多定理,其中有一些图,我必须根据各自的定理编号对它们进行编号。原则上,这适用于\numberwithin{figure}{Theorem}
。但是,如果我在定理中只有一个图(例如在定理 1 中),我只希望它被称为“图 1”而不是“图 1.1”。有办法吗?
以下是示例代码:
\documentclass{article}
\usepackage{amsmath}
\newtheorem{Theorem}{Theorem}
\numberwithin{figure}{Theorem}
\begin{document}
\begin{Theorem}
This is Theorem 1.
\begin{figure}[htp]
\centering Figure
\caption{This should be Figure 1 (instead of Figure 1.1).}
\end{figure}
\end{Theorem}
\begin{Theorem}
This is Theorem 2.
\begin{figure}[htp]
\centering Figure
\caption{This is Figure 2.1.}
\end{figure}
\begin{figure}[htp]
\centering Figure
\caption{This is Figure 2.2.}
\end{figure}
\end{Theorem}
\end{document}
答案1
由于与图形相关的图形不能“浮动”(在 LaTeX 特定意义上),您可能不应该一figure
开始就为这些图形使用环境。相反,使用minipage
环境和\captionof{figure}{...}
语句来创建类似图形的标题。最后,对于那些具有多个图形的定理,发出指令
\counterwithin{figure}{Theorem}
在定理环境开始之前
\counterwithout{figure}{Theorem}
环境结束后立即。
\documentclass{article}
\usepackage{caption}
\usepackage{amsthm}
\newtheorem{Theorem}{Theorem}
\begin{document}
\begin{Theorem}
This is Theorem 1.
\noindent\begin{minipage}{\textwidth}\upshape
\centering
Figure
\captionof{figure}{This is Figure 1.}
\end{minipage}
\end{Theorem}
\counterwithin{figure}{Theorem}
\begin{Theorem}
This is Theorem 2.
\noindent\begin{minipage}{\textwidth}\upshape
\centering
Figure
\captionof{figure}{This is Figure 2.1.}
\bigskip
Figure
\captionof{figure}{This is Figure 2.2.}
\end{minipage}
\end{Theorem}
\counterwithout{figure}{Theorem}
\begin{Theorem}
This is Theorem 3.
\noindent\begin{minipage}{\textwidth}\upshape
\centering
Figure
\captionof{figure}{This is Figure 3.}
\end{minipage}
\end{Theorem}
\end{document}