Attractive Boxed Equations
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 ;-)
\documentclass{article}
\usepackage{color}
\definecolor{myblue}{rgb}{.8, .8, 1}
\usepackage{amsmath}
\usepackage{empheq}
\newlength\mytemplen
\newsavebox\mytempbox
\makeatletter
\newcommand\mybluebox{%
\@ifnextchar[%]
{\@mybluebox}%
{\@mybluebox[0pt]}}
\def\@mybluebox[#1]{%
\@ifnextchar[%]
{\@@mybluebox[#1]}%
{\@@mybluebox[#1][0pt]}}
\def\@@mybluebox[#1][#2]#3{
\sbox\mytempbox{#3}%
\mytemplen\ht\mytempbox
\advance\mytemplen #1\relax
\ht\mytempbox\mytemplen
\mytemplen\dp\mytempbox
\advance\mytemplen #2\relax
\dp\mytempbox\mytemplen
\colorbox{myblue}{\hspace{1em}\usebox{\mytempbox}\hspace{1em}}}
\makeatother
\begin{document}
\begin{empheq}[box={\mybluebox[5pt]}]{equation*}
c_i = \sum_j A_{ij}
\end{empheq}
\begin{empheq}[box={\mybluebox[2pt][2pt]}]{equation*}
c_i = \langle\psi|\phi\rangle
\end{empheq}
\end{document}
tcolorbox
also offers several options for boxed math expressions.
tcbhighmath
is an special box which can be used with empheq
package, but it's also easy to declare new boxes to use with empheq
.
Some examples with the code:
\documentclass{article}
\usepackage{amsmath}
\usepackage{empheq}
\usepackage[most]{tcolorbox}
\newtcbox{\mymath}[1][]{%
nobeforeafter, math upper, tcbox raise base,
enhanced, colframe=blue!30!black,
colback=blue!30, boxrule=1pt,
#1}
\begin{document}
\begin{empheq}[box=\tcbhighmath]{equation*}
c_i = \langle\psi|\phi\rangle
\end{empheq}
\tcbset{highlight math style={boxsep=5mm,colback=blue!30!red!30!white}}
\begin{empheq}[box=\tcbhighmath]{equation*}
c_i = \langle\psi|\phi\rangle
\end{empheq}
\begin{empheq}[box=\mymath]{equation*}
c_i = \langle\psi|\phi\rangle
\end{empheq}
\begin{empheq}[box={\mymath[colback=red!30,drop lifted shadow, sharp corners]}]{equation*}
c_i = \langle\psi|\phi\rangle
\end{empheq}
\end{document}
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
\usepackage{empheq}
\usepackage{xcolor}
\definecolor{lightgreen}{HTML}{90EE90}
in the preamble.
Full example:
\documentclass{article}
\pagestyle{empty}
\usepackage{amsmath}
\usepackage{empheq}
\usepackage{xcolor}
\definecolor{lightgreen}{HTML}{90EE90}
\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}}
\begin{document}
\boxedeq{eq:first}{c_i = \sum_jA_{ij}}
\coloredeq{eq:second}{c_i = \langle\psi|\phi\rangle}
\end{document}