## LaTeX forum ⇒ Math & Science ⇒ Symetrical box around equation

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

### Symetrical box around equation

I'm using the code below to draw a nice fancy box around some important equations in my documents. I would like to draw a vertically symetrical box around the equal sign, whatever the symbols entering the equation. Currently, the box is a bit too high above the "=", and I have to hack the equation by adding some invisible symbols (adding \phantom{\frac{1}{2}}, for example, but then the box may become too big). Is there a way to modify the macro so all boxes are perfectly symetrical (vertical symetry !), while not too big at the same time ?

\documentclass[12pt,letterpaper,twoside]{book}\usepackage{xcolor} \usepackage{empheq}\definecolor{beige}{RGB}{240,235,225} \newenvironment{important}[2][]{	\setkeys{EmphEqEnv}{#2}	\setkeys{EmphEqOpt}{box={\setlength{\fboxsep}{10pt}\fcolorbox{black}{beige}},#1}	\EmphEqMainEnv}{\endEmphEqMainEnv} \begin{document} 	\begin{important}{equation}		E = m \, c^2.	\end{important} \end{document}

Take note that some equations may not have an "=" in them. Also, using other environments like align (instead of equation) may cause some problems with the vertical symetry idea. How to define a vertical symetry if there are two aligned equations one on top of another ?

Stefan Kottwitz
Posts: 8705
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
At least a quick hack auto-scaling delimiters around the equation, vertically centered, made white:


Stefan

Cham
Posts: 830
Joined: Sat Apr 02, 2011 4:06 pm
I guess the white color used is just to show the effect ?

And how is this working for any equation ? Should this hack be part of the box macro itself, instead of inserting the vertical bars separately ?

And how should this aply to boxed aligned equations like these below ?

\begin{important}{align}		E &= m \, c^2. \\[12pt]		E &= \hbar \, \omega.	\end{important}

Actually, my problem is to get an aesthetical pleasing box around any equation, with equilibrated space above and below the boxed equation. Without any hack, the box is often not well "equilibrated" (too much space above or under the equation).

Stefan Kottwitz
Posts: 8705
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
The white color was for "hiding" the bar, so it takes space without being visible. (\vphantom doesn't work with the auto-sizing delimiter)

Yes, it could be part of the box macro, but that's a bit more work and at first one should decide if to choose that way.

Because of the vertical centering of both the equal sign and the delimiter, the distance will be symmetrical. That the vertically centered delimiter adjusts its size automatically to height and depth of the equation, is a nice thing that we used, so it's a solution for single equations.

Multiple equations in a single box are a different beast. Again, one could use delimiters with an aligned environment inside, or array, \venter, ... On the other hand, boxed and colored equations are maybe for school kids books and not so for serious publications, so I'm not sure if it's really useful to work on that... maybe at the end you might choose a serious formal classical display anyway.

Stefan