5

When creating a boxed environment with mdframed, I ran into an issue with a line with an equation, that also happens to be the first line of a definition.

The dA protrudes from the box

Is there a way to fix the problem automatically, without resorting to using \linebreak? If not, what is the best practice solution?

Full MWE:

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{mdframed}

\theoremstyle{definition}
\newtheorem{defn}{Definition}
\surroundwithmdframed[leftmargin=20pt,rightmargin=20pt]{defn}

\begin{document}
\begin{defn}
The double integral of $f$ on $R$, denoted as $\iint_R f(x,y) \, \operatorname{d}\!A$
\end{defn}
\end{document}
1
  • 1
    This isn't mdframed specific and is just a question of how one resolves overfull boxes. A good discussion is to be found at tex.ac.uk/FAQ-overfull.html . I would suggest adjusting \emergencystretch after fixing the grammar of the sentence. Apr 26, 2016 at 7:41

2 Answers 2

4
+50

First things first: An algorithm most probabilly will never cover all use cases at once. A good rule of thumb is to assume that on average a LaTeX document will reach 90% of the final quality without any direct intervention. That said, inserting a \linebreak here and there should not be the end of the world, i.e.

\begin{defn}
  The double integral of $f$ on $R$, denoted as \linebreak $\iint_R f(x,y) \, \operatorname{d}\!A$
\end{defn}

will work perfectly.

If you really want to automate this you can wrap the definition text into a \parbox, which has a fixed width by definition:

\documentclass{article}
\usepackage{lipsum}
\usepackage{amsmath}
\usepackage{amsthm}
  \theoremstyle{definition}
  \newtheorem{definition}{Definition}
\usepackage{mdframed}
\usepackage{environ}

\makeatletter
\parindent\z@
\NewEnviron{defn}{%
  \mdframed[leftmargin=20\p@, rightmargin=20\p@]
    \centering
    \parbox[c]{\hsize}{\definition\BODY\enddefinition}
  \endmdframed
}
\makeatother

\begin{document}
\lipsum[1]

\begin{defn}
  The double integral of $f$ on $R$, denoted as $\iint_R f(x,y) \, \operatorname{d}\!A$
\end{defn}

\lipsum[2]
\end{document}

output_cut

However, I think you don't need mdframed for this. You may want to try the following definition for defn:

\NewEnviron{defn}{%
  \vskip10\p@
  \begingroup\centering
    \fbox{%
      \hskip5\p@
      \parbox[c]{\dimexpr\hsize-60\p@\relax}{%
        \definition\BODY\enddefinition}
      \hskip5\p@}
    \par
  \endgroup
  \vskip10\p@
}
5
  • 2
    Great answer! If nothing better shows up, I'll award the bounty.
    – 0az
    Apr 22, 2016 at 14:24
  • The last parts do not really address the issue. A \parbox can also be overfull and equations spill into the margin. One should be looking at adjust the associated parameters, or as you originally suggest add line breaks, or alternatively display long material. Apr 26, 2016 at 8:32
  • @AndrewSwann -- I agree: \parboxes may also be under or overfull. But I slightly disagree that my solution does not address the problem. In fact it adds another boundry for the outer mdframed environment, thus takes care that not the wrong boxes get under-/overfull.
    – Ruben
    Apr 26, 2016 at 23:55
  • If the parbox is overfull the result may still stick out of the mdframe - just try a longer equation. Apr 27, 2016 at 9:29
  • @AndrewSwann -- I tried a longer equation without any problems. Anyways, I don't claim that the automatic version does cover every eventaulity. That's what (as you noted) I tried to explain in the upper part of the answer. I justed wanted to show what one can try if automation is really desired in order to provide a complete answer.
    – Ruben
    Apr 27, 2016 at 21:41
0
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{mdframed}
\theoremstyle{definition}
\newtheorem{defn}{Definition}
\surroundwithmdframed[leftmargin=-10pt,rightmargin=20pt]{defn}
\begin{document}
\begin{defn}
The double integral of $f$ on $R$, denoted as $\iint_R f(x,y) \, 
\operatorname{d}\!A$
\end{defn}
\end{document}
Same code only left margin is assigned with -10pt   

mdframed

1
  • Try \lipsum\begin{defn}...\end{defn}\lipsum with your solution.
    – Ruben
    Apr 21, 2016 at 13:03

You must log in to answer this question.

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