如果我取消注释注释行,则以下 MWE 无法编译:
\documentclass[a4paper,10pt]{book}
\usepackage{amsmath}
\usepackage{mdframed}
\usepackage{graphicx}
\usepackage{xcolor}
\mdfdefinestyle{theoremSty}{backgroundcolor=yellow!10, linewidth=0pt, innerleftmargin=3ex, innerrightmargin=3ex, innertopmargin=1ex, innerbottommargin=1ex, innermargin =+1cm, outermargin =+1cm}
\newcounter{theoremCounter}[chapter]
\numberwithin{theoremCounter}{chapter}
\newmdtheoremenv[style=theoremSty]{theorem}[theoremCounter]{Theorem}
\begin{document}
\begin{theorem}
\lipsum[1]
%\begin{figure}
\includegraphics[width=0.6\linewidth]{example-image-a}
% \caption{Example image A.}
% \label{fig:example-image-a}
%\end{figure}
\lipsum[2]
\end{theorem}
\end{document}
问题是为什么我不能把这个图放在定理里面吗如果有一个解决方法。
(我已检查过该图形是否符合该定理。)
答案1
有可能为 定义\usepackage{floatrow}
一个新的选项。H
\begin{figure}[H]
这样,图形就不会浮动,而只会放置在您包含它的位置。
您可以使用类似于浮动图形的标题和标签。
\documentclass[a4paper,10pt]{book}
\usepackage{amsmath}
\usepackage{mdframed}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{floatrow}
\usepackage{lipsum}
\mdfdefinestyle{theoremSty}{backgroundcolor=yellow!10, linewidth=0pt, innerleftmargin=3ex, innerrightmargin=3ex, innertopmargin=1ex, innerbottommargin=1ex, innermargin =+1cm, outermargin =+1cm}
\newcounter{theoremCounter}[chapter]
\numberwithin{theoremCounter}{chapter}
\newmdtheoremenv[style=theoremSty]{theorem}[theoremCounter]{Theorem}
\begin{document}
\begin{theorem}
\lipsum[1]
\begin{figure}[H]
% \includegraphics[width=0.6\linewidth]{example-image-a}
THE IMAGE
\caption{Example image A.}
\label{fig:example-image-a}
\end{figure}
\lipsum[2]
\end{theorem}
Have a look at fig. \ref{fig:example-image-a}.
\end{document}