5

I'm trying to write a collection of problems and their solutions for my course's textbook. I've created an exercise environment. I'm currently using the mdframed package to create a leftbar that spans the exercise descriptions.

Here are some of my issues and questions:

  • Is it possible to create an exercise environment like mine so that "Exercise ---" appears on the same line as the exercise description (so no line breaks)?
  • Should the leftbar in my example be changed any? Does it go too far above/below the text? It seems like the bar goes farther above the text than it does below the text.
  • How would I change my example so that instead of a leftbar, the entire exercise environment (not including the solutions) is shaded a light gray?

    \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}
    

Output:

2
  • Why are you numbering the exercises manually? Jun 13, 2013 at 18:03
  • I want a collection of solved problems to distribute to students. I only intend on solving a select few of the exercises in the textbook.
    – Noob
    Jun 13, 2013 at 18:05

2 Answers 2

7

Here's another similar approach, but this time using the interface provided by the thmtools package; the idea is to define the structure as a theorem-like one, and use the mdframed key provided by 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}

enter image description here

1
  • Did you notice my message in the chat. I uploaded the new version with a lot of new hooks ;-) Jun 13, 2013 at 18:29
5

A lot of questions.

  • Is it possible to create an exercise environment like mine so that "Exercise ---" appears on the same line as the exercise description (so no line breaks)?

In this case I suggest to define a normal theorem environment with newtheorem and surround the environment with 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}

Of course the numbering scheme of exercise must be modified to your needs. I don't know why you are using a manual count.

  • Should the leftbar in my example be changed any? Does it go too far above/below the text? It seems like the bar goes farther above the text than it does below the text.

This can be fixed if you use ntheorem and mdframed with the option ntheorem=true to declare your theorems.

\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}
  • How would I change my example so that instead of a leftbar, the entire exercise environment (not including the solutions) is shaded a light gray?

Also with \surroundwithmdframed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .