7

I use the code below to make a box around equations. It puts the equations numbers outside the box, however I would like to have the equation numbers within the box.

How can I alter my code to do this? Thanks in advance.

\documentclass[11pt]{report}

    \usepackage{empheq}


    \newcommand*\widefbox[1]{\fbox{\hspace{2em}#1\hspace{2em}}}

    \begin{document}
    \begin{empheq}[box=\widefbox]{align}
    & a = b +c \\
    & d = e+f
    \end{empheq}
    \end{document}

enter image description here

(So: I would like to have the ''(1)'' and ''(2)'' within the box.)

6

For a change, use tcolorbox:

\documentclass[11pt]{report}

\usepackage[most]{tcolorbox}
\tcbset{myformula/.style={colback=white, %yellow!10!white,
    colframe=black, %red!50!black,
    top=0pt,bottom=0pt,left=0pt,right=0pt,
    boxsep=0pt,
    arc=0pt,
    outer arc=0pt,
}}

\begin{document}
\begin{tcolorbox}[ams align,myformula]
& a = b +c \\
& d = e+f
\end{tcolorbox}
\end{document}

enter image description here

3

Before I know for tcolorbox I use the following solution:

\documentclass{article}
    \usepackage{empheq}

    \newlength\fsep
    \setlength\fsep{2\fboxsep+2\fboxrule}
    \newsavebox\widebox
\newenvironment{mathbox}
    {\par\vskip\fsep\noindent%
     \begin{lrbox}{\widebox}%
     \begin{minipage}{\textwidth-\fsep}%
    }{\vskip\fsep\end{minipage}\end{lrbox}
      \framebox{\usebox\widebox}%
     }

    \begin{document}
\begin{mathbox}
    \begin{align}
a & = b +c \\
d & = e+f
    \end{align}
\end{mathbox}
    \end{document}

which gives:

enter image description here

3

Here is a simple solution with the framed package. I define a myframedeq environment, which has one optional argument, the width of the frame (default: \textwidth). One could in the same way define a shadedeq environment which would put wrap the math environment is a coloured box, with a coloured background.

\documentclass[11pt]{report}
\usepackage[showframe]{geometry}
\usepackage{empheq}
\usepackage{xcolor, framed}

\newcommand*\widefbox[1]{\fbox{\hspace{2em}#1\hspace{2em}}}
\newenvironment{myframedeq}[1][\linewidth]{\FrameSep=4pt\abovedisplayskip=0pt\belowdisplayskip=0pt
\framed\hsize=#1\leftskip=\dimexpr(\textwidth-#1)/2\relax}
{\endframed}

\begin{document}
\begin{empheq}[box=\widefbox]{align}
  & a = b +c \\
  & d = e+f
\end{empheq}
Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
\begin{myframedeq}
  \begin{align}
    a & = b + c \\
    d & =e + f
  \end{align}
\end{myframedeq}

\FrameRule=1pt
\begin{myframedeq}[0.6\linewidth]
  \begin{align}
    a & = b + c \\
    d & =e + f
  \end{align}
\end{myframedeq}

\end{document} 

enter image description here

2

TikZ can also make much fun:

\documentclass[11pt]{report}
\usepackage{amsmath,tikz}
\usetikzlibrary{tikzmark}
\begin{document}

\begin{tikzpicture}[remember picture,overlay]
\draw[fill=blue!10]([yshift=0pt]{pic cs:start}) rectangle ([yshift=.5em]{pic cs:end});
\end{tikzpicture}

\tikzmark{start}
\begin{align}
 a &= b+c \\
 d &= e+f
\end{align}\hfill\tikzmark{end}

\end{document}

You can leave or drop the [fill=blue!10] to get the following outputs:

enter image description here

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.