Sign up ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I often used \boxed{...} from the AMS math package to place a box around important equations. However, this approach often produces somewhat awkward looking output. Consider

 \boxed{c_i = \sum_jA_{ij}}
 \boxed{c_i = \langle\psi|\phi\rangle}

enter image description here

Observe that in the first case the box looks unbalanced while in the second case could do with more padding on both the top and bottom. What is the best way to go about this? I know that I could use a \phantom but am wondering if more elegant solutions exist.

share|improve this question
Those boxed equations might look attractive to you, but once you get past elementary level (up to high school) texts, you will not see boxed equations used very often, if at all. – David Hammen Jun 12 '11 at 23:22
@David Hammen: I have seen world class PhD theses with boxed equations to emphasise an important equation. – Danie Els Jun 13 '11 at 5:37
@Danie: I'm curious. What makes a Ph.D. thesis world class? – TH. Jun 13 '11 at 6:27
@TH: David Hammen has commented that emphasised (boxed) equitions are only used for elementry level books. My answer was that I've seen it being used with good effect up to the highest levels of academic publishing. The issues of what is a world class thesis and bad typesetting has nothing to do with boxed equations. So what is you problem here? – Danie Els Jun 13 '11 at 8:02
DavidHammen Wrong; a load of physics and mathematics textbooks use boxes (regardless of the level). @TH- Who says it's for publication? – User 17670 Apr 21 '13 at 14:42

2 Answers 2

up vote 21 down vote accepted

You can use the empheq package and then define your own boxing command. It can be a standard Latex \fbox or a Tikz box, or any other type of box. Look at the example below. I have defined a color box (to make it more interesting) with two optional arguments for padding the space above and below the equation

\mybluebox[<top pad>][<bot pad>]{<contents>}

The keyval package is already loaded so you can make a fancy keyval interface, but I leave that as an exercise to the reader ;-)


\definecolor{myblue}{rgb}{.8, .8, 1}





    \advance\mytemplen #1\relax
    \advance\mytemplen #2\relax


    c_i = \sum_j A_{ij}

    c_i = \langle\psi|\phi\rangle

enter image description here

share|improve this answer
Will any of these work within an align environment where I only want to shade one of the equations. – Peter Grill Jun 14 '11 at 3:40
@Peter Grill: The \Aboxed command form the mathtools package can box one line of and aligned environment. To change it to shadeding the line, the internal command \@Aboxed need to be redefined, but it is not to difficult. – Danie Els Jun 14 '11 at 5:33

Perhaps these commands will be of some help:

> \newcommand{\boxedeq}[2]{\begin{empheq}[box={\fboxsep=6pt\fbox}]{align}\label{#1}#2\end{empheq}}
> \newcommand{\coloredeq}[2]{\begin{empheq}[box=\colorbox{lightgreen}]{align}\label{#1}#2\end{empheq}}

Don't forget to put


in the preamble

share|improve this answer
Forgot to mention: the 1-st argument is a label for the equation, the 2-nd one is the emphasized equation itself. – user1999 Jun 13 '11 at 13:17
The framed package is not required in your answer. The xcolor package is required (maybe with some option to access the lightgreen color). – Gonzalo Medina Jun 13 '11 at 13:48
Thanks Gonzalo. It appears, however, that the \empheq package is needed, see here: – user1999 Jun 13 '11 at 19:04
Of course empheq is needed. I only wanted to point out that framed is not needed but xcolor is. – Gonzalo Medina Jun 13 '11 at 19:06
How do you get a border around it? – leastaction Nov 2 at 6:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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