4

Starting from this question \boxed border color I wanted to color only the box, but I also have number colored. Without to use mdframed, tcolorbox, or other package is there a very simple alternative (without macro) to have the color of the box? My MWE is:

enter image description here

\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)dt}}
\end{equation}
\end{document}
  • 1
    Just add \color{oldcolor} after the box, \begin{equation} \colorlet{oldcolor}{.} \color{magenta} \boxed{\color{oldcolor} F(x)=\int_{0}^{x}f(t)\,\mathrm{d}t}\color{oldcolor} \end{equation}. – user194703 Dec 30 '19 at 20:36
  • @Schrödinger'scat No no :-((( a comment please. Put an answer thus I vote it. :)))) I have only 4 votes for today. – Sebastiano Dec 30 '19 at 20:38
5

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}

enter image description here

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.

| improve this answer | |
6

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}

enter image description here

| improve this answer | |
  • Thank you always after 3 years of your cooperation. – Sebastiano Dec 30 '19 at 21:18
3

For reference, here's a version that uses tcolorbox's tcbhighmath command:

screenshot demonstrating the output using tcbhighmath

\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.

| improve this answer | |
  • 1
    I always wish you and all those who give their knowledge to improve our society with little culture and respect. – Sebastiano Dec 31 '19 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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