LaTeX forum ⇒ Math & ScienceLarge 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).
User avatar
Cham
Posts: 813
Joined: Sat Apr 02, 2011 4:06 pm

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

Postby Cham » Sat May 20, 2017 4:08 am

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 :

  1. \documentclass[12pt,letterpaper]{article}
  2. \usepackage{amsmath}
  3. \usepackage{empheq}
  4.  
  5. \begin{document}
  6.  
  7. Test :
  8.  
  9. \begin{align}
  10. 3d + 7 y - 3 x &= aba \nonumber \\[12pt]
  11. &= 32g hy - \frac{1}{2} \, x y
  12. \end{align}
  13.  
  14. \end{document}


In my usual documents, I simply put the whole equation inside a box using the following code in the preamble :
  1. \newenvironment{important}[2][]{
  2. \setkeys{EmphEqEnv}{#2}
  3. \setkeys{EmphEqOpt}{box={\setlength{\fboxsep}{10pt}\fcolorbox{black}{gray}},#1}
  4. \EmphEqMainEnv}
  5. {\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 ?

User avatar
Cham
Posts: 813
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sat May 20, 2017 4:13 am

Doh ! Apparently, the simple command \boxed{} do the trick ! :lol:

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

User avatar
cgnieder
Site Moderator
Posts: 1974
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Sat May 20, 2017 10:38 am

You can have fancy boxes with tcolorbox and its theorems library:

  1. \documentclass[12pt,letterpaper]{article}
  2. \usepackage{amsmath}
  3. \usepackage{tcolorbox}
  4. \tcbuselibrary{theorems}
  5.  
  6. \begin{document}
  7.  
  8. Test :
  9.  
  10. \begin{align}
  11. 3d + 7 y - 3 x &= aba \nonumber \\[12pt]
  12. &= \tcboxmath{32g hy - \frac{1}{2} \, x y}
  13. \end{align}
  14.  
  15. \end{document}


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

User avatar
Cham
Posts: 813
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sat May 20, 2017 2:08 pm

Wow ! This box is nice, thanks ! Maybe a bit too big, though. I'll check the documentation.

User avatar
cgnieder
Site Moderator
Posts: 1974
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Sat May 20, 2017 2:13 pm

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


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 6 guests