使用 mdframed 的新环境

使用 mdframed 的新环境

我正在尝试为我的课程教科书编写一系列问题及其解决方案。我创建了一个练习环境。我目前正在使用该mdframed包创建一个涵盖练习描述的左栏。

以下是我的一些问题和疑问:

  • 是否可以创建一个像我这样的练习环境,以便“练习---”与练习描述出现在同一行(因此没有换行符)?
  • 我的示例中的左栏是否需要更改?它是否超出文本太多/太少?似乎栏超出文本太多,超出文本太少。
  • 我该如何改变我的例子,以便整个练习环境(不包括解决方案)而不是左栏都变成浅灰色?

    \documentclass[11pt]{article}
    
    \usepackage{amsmath,amssymb,amsfonts}
    \usepackage{color, linegoal}
    \usepackage{amsthm,array}
    \usepackage[framemethod=tikz]{mdframed}
    \usepackage[margin=1.2in]{geometry}
    
    % Exercise environment
    \definecolor{ExerciseColor}{gray}{0.65}
    
    \newenvironment{exercise}[1]
    {\mdfsetup{
    skipabove=\topsep,
    skipbelow=\topsep,
    innertopmargin=0pt,
    innerbottommargin=4pt,
    leftmargin=-13pt,
    splitbottomskip=0ex,
    splittopskip=0ex,
    topline=false,
    leftline=true,
    bottomline=false,
    rightline=false,
    innerrightmargin=0pt,
    innerlinewidth=2pt,
    font=\normalfont,
    frametitle={\textbf{Exercise #1.}}, 
    linecolor=ExerciseColor,
    }
    \begin{mdframed}%
    }
    {\end{mdframed}}
    
    % Solution environment
    \newenvironment{solution}{\begin{proof}[\itshape Solution]}{\end{proof}}
    
    \begin{document}
    \title{Title}
    \author{Author}
    \date{\today}
    \maketitle
    
    \section*{\centering \bfseries \S 1.3 Exercises}
    
    \begin{exercise}{1.3.1}
    Here is an exercise. Here is an exercise. Here is an exercise. Here is an exercise. Here is an exercise. Here is an equation:
    \[
    a + b = c.
    \]
    Here is an exercise. 
    \end{exercise}
    \begin{solution}
    Here is my solution. Here is an equation:
    \[
    1+2 = 3.
    \]
    Here is my solution. 
    \end{solution}
    
    \begin{exercise}{1.3.5}
    Here is an exercise. Here is an exercise. Here is an exercise. Here is an exercise. Here is an exercise. Here is an equation:
    \[
    a + b = c.
    \]
    Here is an exercise. 
    \end{exercise}
    \begin{solution}
    Here is my solution.
    \end{solution}
    
    \end{document}
    

输出:

答案1

这是另一种类似的方法,但这次使用thmtools包;想法是将结构定义为类似定理的结构,并使用mdframed提供的关键thmtools

\documentclass[11pt]{article}
\usepackage{xcolor}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage[framemethod=tikz]{mdframed}

\definecolor{ExerciseColor}{gray}{0.65}

\declaretheoremstyle[
headfont=\normalfont\bfseries,
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont,
postheadspace=0.5em,
mdframed={
  skipabove=\topsep,
  skipbelow=\topsep,
  hidealllines=true,
  backgroundcolor={ExerciseColor!20},
  innerleftmargin=0pt,
  innerrightmargin=0pt}
]{mystyle}
\declaretheorem[style=mystyle,name=Exercise]{exer}
\newenvironment{exercise}[1]
  {\renewcommand\theexer{#1}\begin{exer}}
  {\end{exer}}

\begin{document}

\begin{exercise}{1.3.5}
Here is an exercise. Here is an exercise. Here is an exercise. Here is an exercise. Here is an exercise. Here is an equation:
\[
a + b = c.
\]
Here is an exercise. 
\end{exercise}

\begin{exercise}{1.3.7}
Here is an exercise. Here is an exercise. Here is an exercise. Here is an exercise. Here is an exercise. Here is an equation:
\[
a + b = c.
\]
Here is an exercise. 
\end{exercise}

\end{document}

在此处输入图片描述

答案2

有很多问题。

  • 是否可以创建一个像我这样的练习环境,以便“练习---”与练习描述出现在同一行(因此没有换行符)?

在这种情况下,我建议用定义一个正常定理环境并newtheorem用包围该环境mdframed:\definecolor{ExerciseColor}{gray}{0.65}

\newtheorem{exercise}{Exercise}
\mdfdefinestyle{exercise}{%
skipabove=\topsep,skipbelow=\topsep,
innertopmargin=0pt,innerbottommargin=4pt,
leftmargin=-13pt,splitbottomskip=0ex,
splittopskip=0ex,topline=false,leftline=true,
bottomline=false,rightline=false,
innerrightmargin=0pt,innerlinewidth=2pt,
font=\normalfont,linecolor=ExerciseColor,
}
\surroundwithmdframed[style=exercise]{exercise}

当然,编号方案exercise必须根据您的需要进行修改。我不知道您为什么要使用手动计数。

  • 我的示例中的左栏是否需要更改?它是否超出文本太多/太少?似乎栏超出文本太多,超出文本太少。

ntheorem如果您使用并mdframed选择ntheorem=true声明您的定理,就可以解决这个问题。

\usepackage[amsmath]{ntheorem}
\usepackage[framemethod=tikz]{mdframed}\newtheorem{exercise}{Exercise}
\mdfdefinestyle{exercise}{%
skipabove=\topsep,skipbelow=\topsep,
innertopmargin=0pt,innerbottommargin=4pt,
leftmargin=-13pt,splitbottomskip=0ex,
splittopskip=0ex,topline=false,leftline=true,
bottomline=false,rightline=false,
innerrightmargin=0pt,innerlinewidth=2pt,
font=\normalfont,linecolor=ExerciseColor,ntheorem=true,
}
\surroundwithmdframed[style=exercise]{exercise}
  • 我该如何改变我的例子,以便整个练习环境(不包括解决方案)而不是左栏都变成浅灰色?

也与\surroundwithmdframed

相关内容