Border color only on boxed equation
OK, per request. You most likely want to switch back to the normal color anyway, so
\documentclass[12pt]{article}
\usepackage{amsmath,amssymb,xcolor}
\begin{document}
\begin{equation}
\colorlet{oldcolor}{.}
\color{magenta}
\boxed{\color{oldcolor} F(x)=\int_{0}^{x}f(t)\,\mathrm{d}t}\color{oldcolor}
\end{equation}
\end{document}
Needless to say that there are packages like empheq
, tcolorbox
and in particular the combination of the two which take care of these things automatically.
I propose to define a colorboxed
command, based on \fcolorbox
, which has two mandatory argument – the colour of the frame and the content of the frame, and the background of the frame as an optional argument:
\documentclass[12pt]{article}
\usepackage{amsmath,amssymb}
\usepackage[svgnames]{xcolor}
\makeatletter
\newcommand{\colorboxed}[3][white]{\fcolorbox{#2}{#1}{\m@th$\displaystyle#3$}}
\makeatother
\begin{document}
\begin{equation}
\colorboxed{IndianRed}{F(x)=\int_{0}^{x}f(t)dt}
\end{equation}
\begin{equation}
\colorboxed[LavenderBlush!30]{IndianRed}{F(x)=\int_{0}^{x}f(t)dt}
\end{equation}
\end{document}
For reference, here's a version that uses tcolorbox
's tcbhighmath
command:
\documentclass{article}
\usepackage[many]{tcolorbox}
\tcbset{
every box/.style={
highlight math style={sharp corners,colback=white,colframe=magenta},
}
}
\begin{document}
\begin{equation}
\tcbhighmath{F(x)=\int_{0}^{x}f(t)dt}
\end{equation}
\end{document}
You might like to see Section 17.1 of the tcolorbox documentation for further reading; in particular, you might like to see \tcboxmath
.