# Shaded continuous across new enumerate environment

I'm trying to write up solutions where I include the original problem text, in a light gray shaded box. I had been creating the shading with the 'framed' package shaded environment, but some of the problems have enumerated parts, with some text before the parts. I would like to have the starting text and the first part continuously shaded, but apparently the shaded environment can't cross a \begin{enumerate}. So what I have right now is

\begin{shaded}Starting text...\end{shaded}
\begin{enumerate}
This is the first solution.
Second solution.
\end{enumerate}


Is there a way to have the shading continuous instead of that first gap?

-
Welcome to TeX.SE. While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. –  Peter Grill Jan 31 '12 at 19:14

## Basic Solution:

I would recommend that you use the mdframed package instead (as it will work across page breaks), and use the resume* option with lists via the enumitem package:

## Better Solution:

As @MarcoDaniel suggested, a better looking solution is to use the frametitle option with mdframed.

\newenvironment{Question}[1]{
\begin{mdframed}[
frametitle={#1},
frametitlerule=true,
frametitlebackgroundcolor=red!20,
frametitlebelowskip=2pt,
innerlinewidth=1.0pt
]
}{
\end{mdframed}
}


With this you simply enclose the part you wanted shaded in the first parameter to the Question environment, and the body of this environment is the answer, i.e., the part you don't wanted shaded. This yields:

• For some reason there is a display issue with this. There are lines at the top and bottom but with increasing magnification from 150% and incrementing by 1% with Acrobat Reader 10.1.2 on Mac different lines appear and disappear. I have updated this to use framemthod=tikz and innerlinewidth=1.0pt option as this make this display problem less noticeable (but problem is still there).

## Even Better Solution (Custom Counter):

If you are only using the enumerate to create a numbered list, you could simplify things even further by using a custom counter. This is also courtesy of @MarcoDaniel.

## Code: Basic Solution

\documentclass{article}
\usepackage{xcolor}
\usepackage{enumitem}
\usepackage{mdframed}

\begin{document}
Starting text...
\begin{enumerate}[series=MyQuestions,leftmargin=*]
\item This is the first problem.
\end{enumerate}
\begin{enumerate}[resume*=MyQuestions]
\item[] This is the first solution (not shaded)
\end{enumerate}
%
\begin{enumerate}[resume*=MyQuestions]
\item This is the second problem.
\end{enumerate}
\begin{enumerate}[resume*=MyQuestions]
\end{enumerate}
\end{document}


## Code: Better Solution:

\documentclass{article}
\usepackage{xcolor}
\usepackage{enumitem}
\usepackage[framemethod=tikz]{mdframed}

\newenvironment{Question}[1]{
\begin{mdframed}[
frametitle={#1},
frametitlerule=true,
frametitlebackgroundcolor=red!20,
frametitlebelowskip=2pt,
innerlinewidth=1.0pt
]
}{
\end{mdframed}
}

\begin{document}
\begin{Question}{
Starting text...
\begin{enumerate}[series=MyQuestions,leftmargin=*]
\item This is the first problem.
\end{enumerate}
}
This is the first solution (not shaded)
\end{Question}

\bigskip
\begin{Question}{
\begin{enumerate}[resume*=MyQuestions]
\item This is the second problem.
\end{enumerate}
}
\begin{enumerate}[resume*=MyQuestions]
\end{enumerate}
\end{Question}
\end{document}


## Code: Even Better Solution (Custom Counter):

\documentclass{article}
\usepackage{mdframed}
\mdfdefinestyle{QuestionsStyle}{%
frametitlerule=true,
frametitlebackgroundcolor=yellow,
linewidth=2pt,
frametitlerulewidth=1pt,
innerleftmargin=30pt,
frametitlebelowskip=.5\topskip,
innertopmargin=\topskip
}
\newcounter{QuestionCounter}
\setcounter{QuestionCounter}{0}
\newrobustcmd*\SetQuestionNum{\mbox{}\llap{\stepcounter{QuestionCounter}\theQuestionCounter\hspace*{10pt}}}
\newmdenv[style=QuestionsStyle]{Question}
\begin{document}
\begin{Question}[frametitle={
Some Text\\
\\
\SetQuestionNum This is the first problem.}]
This is the first solution (not shaded)
\end{Question}

\bigskip
\begin{Question}[frametitle={
\SetQuestionNum This is the second problem.}]

A solution by using frametitle seems to be possible. So you can set the frametitlebackgroundcolor. –  Marco Daniel Jan 31 '12 at 19:54
@MarcoDaniel: Excellent idea. I have replaced the earlier Better Solution to use frametitle. However, I notice a slight display issue as I pointed out in the solution. Definitely a problem with the Acrobat display as different magnifications show different lines. –  Peter Grill Jan 31 '12 at 20:17
Hmm, I can't typeset the 'better solution', I get frametitle undefined. –  Micah Dombrowski Jan 31 '12 at 23:12
@MicahDombrowski: You probably have an older version of mdframed. I think that was a recent enhancement. –  Peter Grill Jan 31 '12 at 23:43