## LaTeX forum ⇒ Math & Science ⇒ Large box around a part of an equation ? Topic is solved

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Cham
Posts: 830
Joined: Sat Apr 02, 2011 4:06 pm

### Large box around a part of an equation ?  Topic is solved

I just came across a new problem that I didn't had before, for my usual documents. I now need to show a calculation on several lines (using the align environment), then emphasize the end result on the last line with a large box around it. How to achieve this ?

Here's a MWE code to work with :

\documentclass[12pt,letterpaper]{article}\usepackage{amsmath}\usepackage{empheq} \begin{document} Test : 	\begin{align}		3d + 7 y - 3 x &= aba \nonumber \\[12pt]		&= 32g hy - \frac{1}{2} \, x y 	\end{align} \end{document}

In my usual documents, I simply put the whole equation inside a box using the following code in the preamble :
\newenvironment{important}[2][]{	\setkeys{EmphEqEnv}{#2}	\setkeys{EmphEqOpt}{box={\setlength{\fboxsep}{10pt}\fcolorbox{black}{gray}},#1}	\EmphEqMainEnv}{\endEmphEqMainEnv}

However, this would not work for a part of an align display. How could I enclose the last part (after the equal sign) inside a large box ?

Cham
Posts: 830
Joined: Sat Apr 02, 2011 4:06 pm
Doh ! Apparently, the simple command \boxed{} do the trick !

Is there another way in doing this ? Maybe with a color background inside the box ?

cgnieder
Site Moderator
Posts: 1985
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:
You can have fancy boxes with tcolorbox and its theorems library:

\documentclass[12pt,letterpaper]{article}\usepackage{amsmath}\usepackage{tcolorbox}\tcbuselibrary{theorems} \begin{document} Test : \begin{align}  3d + 7 y - 3 x &= aba \nonumber \\[12pt]                 &= \tcboxmath{32g hy - \frac{1}{2} \, x y}\end{align} \end{document}

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

Cham
Posts: 830
Joined: Sat Apr 02, 2011 4:06 pm
Wow ! This box is nice, thanks ! Maybe a bit too big, though. I'll check the documentation.

cgnieder
Site Moderator
Posts: 1985
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:
Cham wrote:Maybe a bit too big, though. I'll check the documentation.

tcolorbox has so many possibilities customization that I have no doubt the box can be adapted to whatever you wish.
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim