为什么我的使用 mdframed 的环境无法工作?

为什么我的使用 mdframed 的环境无法工作?

我正在尝试创建一个新的环境,mdframed但是我尝试定义的某些选项不起作用。

以下是代码:

\documentclass[11pt, twosided]{book}
\usepackage[T1]{fontenc}
\usepackage[framemethod]{mdframed}
\usepackage{setspace}
\usepackage{xcolor}

\mdfdefinestyle{mdfexample1}{leftmargin=1cm,rightmargin=2cm,%
innerleftmargin=1cm,innerrightmargin=1cm,roundcorner=10pt}
\newmdenv[skipabove=15pt,
skipbelow=7pt,
rightline=true,
leftline=true,
topline=true,
bottomline=true,
linecolor=green,
backgroundcolor=green!10,
innerleftmargin=15pt,
innerrightmargin=15pt,
innertopmargin=15pt,
leftmargin=2cm,
rightmargin=2cm,
linewidth=2pt,
innerbottommargin=15pt,
roundcorner=10pt]{mBox}

\newenvironment{caixa}
{\begin{mBox}\onehalfspacing\small\color{blue}\ttfamily}{\end{mBox}}
\begin{document}
\begin{caixa}
\begin{itemize}
\item Parque 1
\item Parque 2
\end{itemize}
\end{caixa}

\begin{mdframed}[style=mdfexample1]
In any right triangle, the area of the square whose side is the hypotenuse
is equal to the sum of the areas of the squares whose sides are the two
 legs.
 \end{mdframed}
 \end{document}

这是我得到的结果: 框架

如您所见,它不尊重我定义的几个选项,例如roundcorners和。有人知道出了什么问题leftmarginrightmargin?提前谢谢您!

答案1

必须framemethod指定为tikz,而不是空framemethod键。

如果在twoside模式下工作,应使用outermargin和选项而不是和。innermarginrightmarginleftmargin

\documentclass[11pt, twoside]{book}
\usepackage[T1]{fontenc}
\usepackage{setspace}
\usepackage{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\colorlet{azul}{blue}


\makeatletter % The code checks for twoside or oneside options
\if@twoside
\mdfdefinestyle{mdfexample1}{
  innermargin=1cm,
  outermargin=2cm,%
  innerleftmargin=1cm,
  innerrightmargin=1cm,
  roundcorner=10pt}
\else
\mdfdefinestyle{mdfexample1}{
  leftmargin=1cm,
  rightmargin=2cm,%
  innerleftmargin=1cm,
  innerrightmargin=1cm,
  roundcorner=10pt}
\fi
\makeatother

\newmdenv[skipabove=15pt,
skipbelow=7pt,
rightline=true,
leftline=true,
topline=true,
bottomline=true,
linecolor=green,
backgroundcolor=green!10,
innerleftmargin=15pt,
innerrightmargin=15pt,
innertopmargin=15pt,
leftmargin=2cm,
rightmargin=2cm,
linewidth=2pt,
innerbottommargin=15pt,
roundcorner=10pt]{mBox}

\newenvironment{caixa}
{\begin{mBox}\onehalfspacing\small\color{azul}\ttfamily}{\end{mBox}}
\begin{document}
\begin{caixa}
\begin{itemize}
\item Parque 1
\item Parque 2
\end{itemize}
\end{caixa}

\begin{mdframed}[style=mdfexample1]
In any right triangle, the area of the square whose side is the hypotenuse
is equal to the sum of the areas of the squares whose sides are the two
 legs.
\end{mdframed}
\end{document}

在此处输入图片描述

相关内容