无法将图片添加到新环境

无法将图片添加到新环境

我复制粘贴了我发现的环境这周围创建如下定义的“示例”部分:

\usepackage[framemethod=tikz]{mdframed}
\usepackage{amssymb}
\usepackage{etoolbox}

\newlength\mylen

\newcommand{\xxqed}[1]{%
  \settowidth\mylen{$#1$}%
  \vskip-2\baselineskip\hspace*{-\mylen}\llap{\hbox{\ensuremath{#1}}}%
}

\newcommand{\xqed}[1]{%
  \leavevmode\unskip\penalty9999 \hbox{}\nobreak\hfill
  \quad\hbox{\ensuremath{#1}}}

\AtBeginEnvironment{example}{\stepcounter{example}}
\AtEndEnvironment{example}{\xqed{\textcolor{black}{\blacksquare}}}

\AtBeginEnvironment{lexample}{\stepcounter{example}}
\AtEndEnvironment{lexample}{\xxqed{\textcolor{black}{\blacksquare}}}

\colorlet{myred}{black}

\newmdenv[
  hidealllines=true,
  frametitle={Example~\theexample},
  frametitlerule=true,
  frametitlerulecolor=black,
  frametitlerulewidth=2pt,
  frametitlefont=\bfseries,
  innerleftmargin=0pt,
  innerrightmargin=0pt,
  skipabove=.6\topskip,
  skipbelow=.6\topskip
]{lexample}

\newmdenv[
  hidealllines=true,
  frametitle={Example~\theexample},
  frametitlerule=true,
  frametitlerulecolor=black,
  frametitlerulewidth=2pt,
  frametitlefont=\bfseries,
  innerleftmargin=0pt,
  innerrightmargin=0pt,
  skipabove=.6\topskip,
  skipbelow=.6\topskip
]{example}

\newcounter{example}[chapter]
\renewcommand\theexample{\thesection.\arabic{example}}

但是,当我向该环境添加图片(使用正常的 \begin{figure} 和 \includegraphics)时,编译时出现错误,并且不会添加图片。

我究竟做错了什么?

提前致谢!

答案1

好吧,我已经按照你的建议解决了图形问题。我按照建议添加了图形,没有“图形”环境,而是使用:

\begin{center}
\includegraphics[width=0.25\linewidth]{imgs/Image.pdf}
\captionof{figure}{Caption for figure.}
\end{center}

相关内容