\boxed border color
The following example defines \colorboxed
as wrapper around amsmath
's \boxed
to set the frame color. It uses package xcolor
for the color support to save the current color .
before changing the color for the frame. Inside the box, the previous saved color is restored. This avoids a white background of \fcolorbox
, since there is no "transparent" color.
The macro also supports an optional argument for specifying the color model.
\documentclass{article}
\usepackage{amsmath}
% Definition of \boxed in amsmath.sty:
% \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}
\usepackage{xcolor}
% Syntax: \colorboxed[<color model>]{<color specification>}{<math formula>}
\newcommand*{\colorboxed}{}
\def\colorboxed#1#{%
\colorboxedAux{#1}%
}
\newcommand*{\colorboxedAux}[3]{%
% #1: optional argument for color model
% #2: color specification
% #3: formula
\begingroup
\colorlet{cb@saved}{.}%
\color#1{#2}%
\boxed{%
\color{cb@saved}%
#3%
}%
\endgroup
}
\begin{document}
\begin{equation*}
\boxed{
E_{F_i}-E_c =
\frac{E_v-E_c}{2} +
\frac{K_B T}{2}\log\left[ \frac{N_v}{N_c} \right]
}
\end{equation*}
\begin{equation*}
\colorboxed{red}{
E_{F_i}-E_c =
\frac{E_v-E_c}{2} +
\frac{K_B T}{2}\log\left[ \frac{N_v}{N_c} \right]
}
\end{equation*}
\begin{equation*}
\colorboxed[rgb]{0, 0, 1}{
E_{F_i}-E_c =
\frac{E_v-E_c}{2} +
\frac{K_B T}{2}\log\left[ \frac{N_v}{N_c} \right]
}
\end{equation*}
\end{document}
Here's a way with \color{}
change before and then switching back to the old colour which has been stored before with a \colorlet{...}{.}
statement. The name oldcolor
is arbitray, effectively, unless some other colorname should be overwritten.
\documentclass{article}
\usepackage{xcolor}
\usepackage{mathtools}
\begin{document}
\begin{equation*}
\colorlet{oldcolor}{.}
\color{blue}
\boxed{\color{oldcolor}E_{F_i}-E_c = \frac{E_v-E_c}{2} +\frac{K_B T}{2}\log\left[ \frac{N_v}{N_c} \right]}
\end{equation*}
{\color{brown}
\begin{equation*}
\colorlet{oldcolor}{.}
\color{blue}
\boxed{\color{oldcolor}E_{F_i}-E_c = \frac{E_v-E_c}{2} +\frac{K_B T}{2}\log\left[ \frac{N_v}{N_c} \right]}
\end{equation*}
}
\end{document}
The simplest is to use the empheq
package, which is done for that. Needless to load amsmath
, since it loads mathtools
:
\documentclass{article}
\usepackage{empheq}
\newcommand\widecolourbox[1]{{\setlength\fboxrule{1pt}\setlength\fboxsep{8pt}\fcolorbox{DarkSeaGreen3}{white}{\enspace#1\enspace }}}
\usepackage[x11names]{xcolor}
\begin{document}
\begin{equation*}
\boxed{
E_{F_i}-E_c =
\frac{E_v-E_c}{2} +
\frac{K_B T}{2}\log\left[ \frac{N_v}{N_c} \right]}
\end{equation*}
\vspace{4ex}
\begin{empheq}[box =\widecolourbox]{equation*}
E_{F_i}-E_c =
\frac{E_v-E_c}{2} +
\frac{K_B T}{2}\log\left[ \frac{N_v}{N_c} \right]
\end{empheq}
\end{document}