2

I have been using a simple method for adding a framed, colored box around important equations I want to highlight. The empheq package has worked well. However, I am having a lot of trouble figuring out the best way to add some vertical space around the frame.

Here is what I have done to create a new command called "myyellowonebox" -- the color is "myyellow1"

Preamble:

\definecolor{myyellow1}{RGB}{255, 255, 219}

\newcommand*\myyellowonebox[1]{%
\fcolorbox{myblue1}{myyellow1}{\hspace{2em}#1\hspace{2em}}}

And in the body, I have:

\begin{empheq}[box=\myyellowonebox]{equation}
 y = \frac{1}{4p} x^2
\end{empheq}

This produces the following output:

enter image description here

However, I would like to add a larger gap above and below this equation. I was able to add horizontal padding using the \hspace in the argument of \framebox. But I can't seem to do the same for extra vertical space.

Any help would be greatly appreciated. I'd rather not use a fancy package, as this is about the sophistication I need for highlighting equations!

  • 1
    Since you're using \fcolorbox, adjust \fboxsep: \setlength{\fboxsep}{<len>}... – Werner Feb 15 '17 at 19:25
  • Thank you -- I tried that and it didn't seem to work. Perhaps I did not put the command in the correct place. Where would I insert the \setlength command as you suggested? – G. Khanna Feb 15 '17 at 19:54
  • 1
    Add it in your preamble somewhere so it has the same effect across the whole document. – Werner Feb 15 '17 at 20:17
  • Thank you -- that seemed to work. One last question -- is there a way to override this on an individual basis? – G. Khanna Feb 15 '17 at 20:28
1

\fcolorbox uses \fboxsep and \fboxrule as the widths of the separation and rule. So, adjusting that (globally) within the preamble would make for a consistent gap in your \myyellowonebox. You can adjust this locally as well and restore it as needed:

enter image description here

\documentclass{article}

\usepackage{xcolor,empheq}

\newcommand*\myyellowonebox[1]{\fcolorbox{blue!80}{yellow!15}{\hspace{2em}#1\hspace{2em}}}

\newlength{\fboxsave}\setlength{\fboxsave}{5pt}
\newcommand{\restorefboxsep}{\setlength{\fboxsep}{\fboxsave}}
\restorefboxsep% Default is 3.0pt

\begin{document}

\begin{empheq}[box=\myyellowonebox]{equation}
 y = \frac{1}{4p} x^2
\end{empheq}

\setlength{\fboxsep}{10pt}% Update \fboxsep
\begin{empheq}[box=\myyellowonebox]{equation}
 y = \frac{1}{4p} x^2
\end{empheq}
\restorefboxsep

\end{document}
0

The suggestion by Werner worked -- thank you! Here is the output I get when I add

\setlength{\fboxsep}{1em}

in the preamble. It looks like

enter image description here

Now just trying to figure out how I can override this if I need to on an individual basis.

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.