2

I am using mdframed to box equations to include the equation number, as I quite like how it looks. However I've noticed that this results in a misalignment between equation numbers that are boxed, and those that are not. Is there an easy fix for this, or is it recommended to use a different method to mdframed?

Below is an example of how I'm using it.

\documentclass{article}

\usepackage{amsmath}
\usepackage{mdframed}

\begin{document}

Here is an important equation I would like to highlight:
\begin{mdframed}
\begin{equation}
e^{i\pi}=-1
\end{equation}
\end{mdframed}

Here is an equation not important enough to deserve a highlight:
\begin{equation}
y=mx+c
\end{equation}

\end{document}

enter image description here

Any advice is appreciated.

  • 2
    Unless you make the box run into the right margin, aligning the equation numbers with those outside won't look good, I think. So I am wondering what you want to achieve. Do you want to shift ordinary equation numbers to the left, or run the frame through the numbers, or let the frame intrude the right margin? – marmot Oct 3 '18 at 18:50
  • I reckon the best would probably be to shift the unframed numbers left a little - I imagine there's a simple command for that I could probably look up – Garf Oct 3 '18 at 20:02
2

It is easiest to let the frame extend in to the right margin:

Sample output

\documentclass{article}

\usepackage{amsmath}
\usepackage{mdframed}

\newlength{\mywidth}
\setlength{\mywidth}{\dimexpr\linewidth+\mdflength{innerrightmargin}+\mdflength{linewidth}}

\begin{document}


Here is an important equation I would like to highlight:
\begin{mdframed}[userdefinedwidth=\mywidth]
\begin{equation}
e^{i\pi}=-1
\end{equation}
\end{mdframed}

Here is an equation not important enough to deserve a highlight:
\begin{equation}
y=mx+c
\end{equation}

\end{document}

To go the other way, you could perhaps include all displays in an mdframed, but just hide the lines:

Second sample

\documentclass{article}

\usepackage{amsmath}
\usepackage{mdframed}

\newbool{equationframe}
\surroundwithmdframed[hidealllines=\ifbool{equationframe}{false}{true}]{equation}
\boolfalse{equationframe}

\begin{document}

Here is an important equation I would like to highlight but first
enough text to show the width of the line:
{\booltrue{equationframe}%
\begin{equation}
  e^{i\pi}=-1
\end{equation}}

Here is an equation not important enough to deserve a highlight but
first enough text to show the width of the line:
\begin{equation}
  y=mx+c
\end{equation}

\end{document}

Here I have added an extra flag dedicated to frames for equations, to avoid setting hidealllines globally and thus affecting other mdframed environments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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