2

I'm using mdframed for all my theorem-like environments. By default, mdframed titles appear above the body. I want one of my mdtheorem environments to start the body on the same line as the title, which is the behaviour of LaTeX's default newtheorem command.

(For search engines: that means I want an inline title, so no newline after the title.) I couldn't find the right option for this in the documentation of the frame title.

MWE:

\documentclass{article}

\usepackage{mdframed}
\mdtheorem[font=\slshape, linewidth=1pt]{exercise}{Exercise}[section]

\begin{document}

\begin{exercise}
Sketch a decider machine for the halting problem.
\end{exercise}

\end{document}

1 Answer 1

1

Run-in titles are the default if you use \newmdtheorem instead:

Sample output

\documentclass{article}

\usepackage{mdframed}
\mdtheorem[font=\slshape, linewidth=1pt]{exercise}{Exercise}[section]

\newmdtheoremenv[linewidth=1pt]{exercisetwo}{Exercise}[section]

\begin{document}

\begin{exercise}
Sketch a decider machine for the halting problem.
\end{exercise}

\begin{exercisetwo}
Sketch a decider machine for the halting problem.
\end{exercisetwo}

\end{document}

However, as you can see the default also use the italic font rather than the slanted. Adding font=\slshape will also change the shape of the heading Exercise which you probably do not want. Loading the amsthm package, before mdframed, gives the chance to define new styles, see the documentation. For example, a slanted font, with no vectical space before the title and no punctuation after the title is given by defining a myexercise style and used in exercisethree:

Second sample

\documentclass{article}

\usepackage{amsthm}
\usepackage{mdframed}
\mdtheorem[font=\slshape, linewidth=1pt]{exercise}{Exercise}[section]

\newmdtheoremenv[linewidth=1pt]{exercisetwo}{Exercise}[section]

\newtheoremstyle{myexercise}{-\topsep}{}{\slshape}{}{\bfseries}{}{.5em}{}
\theoremstyle{myexercise}
\newmdtheoremenv[linewidth=1pt]{exercisethree}{Exercise}[section]

\begin{document}

\begin{exercise}
Sketch a decider machine for the halting problem.
\end{exercise}

\begin{exercisetwo}
Sketch a decider machine for the halting problem.
\end{exercisetwo}

\begin{exercisethree}
Sketch a decider machine for the halting problem.
\end{exercisethree}

\end{document}
2
  • Brilliant. Would've never guessed the subtle difference. If I may ask: if I nest exercisethree in a regular \mdtheorem (let's say \mdtheorem[topline=false,bottomline=false,rightline=false,linewidth=1.25pt]{example}{Example}[section]) in the document, it not only inherits that outer frame's style (the exercise loses three sides), but the outer environment's title is also copied overtop the title of exercisethree. This doesn't happen when nesting exercisethree into itself. I guess adding default before linewidth=... is one solution to prevent this. Is there a better one?
    – Mew
    Aug 31, 2022 at 13:06
  • That doubling is strange. I guess you would want to wrap an ordinary theorem with the given style \theoremstyle{myexercise}\newtheorem{exercisefour}{Exercise}[section] instead. Aug 31, 2022 at 13:49

You must log in to answer this question.

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