Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to define a custom environment within mdframed for handling questions in a document. The reason for the question-solution structure is to enable parsing into other formats (html etc).

The following code demonstrates my problem; the enumerate does not display properly in mdframed.

I realise there have been related posts but I cannot find a solution to this.

\documentclass[12pt, a4paper]{article}

\usepackage{tikz,pgf}
\usetikzlibrary{shadows}
\usepackage[framemethod=tikz]{mdframed}

\newcounter{exercises}
\def\theexercise{\thesection.\arabic{exercises}}

\newenvironment{exercises1}
{ \refstepcounter{exercises} 
 \begin{enumerate} }
{ \end{enumerate} 
}

\newenvironment{exercises_mdf}
{ \refstepcounter{exercises} 
\begin{mdframed}[backgroundcolor=black!10, frametitle={Exercise \theexercise}]
\begin{enumerate} }
{ \end{enumerate} 
\end{mdframed} 
}

\newenvironment{question}{ \item } { }
\newenvironment{solution}{ \\ {\bf Solution:} \\ }{ }

\begin{document}

\begin{exercises1}
\begin{question} Q1 
\begin{solution} S1 \end{solution}
\end{question}
\begin{question} Q2
\begin{solution} S1 \end{solution}
\end{question}
\end{exercises1}

\begin{exercises_mdf}
\begin{question} Q1 
\begin{solution} S1 \end{solution}
\end{question}
\begin{question} Q2 
\begin{solution} S2 \end{solution}
\end{question}
\end{exercises_mdf}

\end{document}
share|improve this question
    
Can you provide a small picture that demonstrate your request? –  Marco Daniel Jul 23 '12 at 15:45

1 Answer 1

up vote 1 down vote accepted

I find your construct a bit complicate. I always try to avoid so much typing:

\documentclass[12pt, a4paper]{article}
\usepackage{tikz,pgf}
\usetikzlibrary{shadows}
\usepackage[framemethod=tikz]{mdframed}

\newcounter{exercises}
\def\theexercise{\thesection.\arabic{exercises}}


\newenvironment{exercises_mdf}
{ \refstepcounter{exercises} 
\begin{mdframed}[backgroundcolor=black!10, frametitle={Exercise \theexercise}]
\begin{enumerate} }
{ \end{enumerate} 
\end{mdframed} 
}

\newcommand{\qu}{\item}
\newcommand{\sol}{\\\textbf{Solution}\\}

\begin{document}

\begin{exercises_mdf}
\qu Do you know? \sol YES!
\qu What is the answer? \sol 42
\end{exercises_mdf}

\end{document}

Hopefully this is what you want. If not i recommend that you include a picture as @Marco Daniel said.

share|improve this answer
    
This fixes the problem - thanks –  Chris Barnes Jul 23 '12 at 16:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.