5

I currently put some boxes around equations using:

\newcommand*\eqbox[1]{
\definecolor{shadowcolor}{RGB}{0, 0, 102}\setlength\shadowsize{2pt}\shadowbox*{#1}
}
\eqbox{$1+1=2$}

How to have the same visual result but with equations between \begin{equation}\end{equation} ?

\documentclass[11pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{fancybox}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{empheq}

\newcommand*\eqbox[1]{\definecolor{shadowcolor}{RGB}{0, 0, 102}\setlength\shadowsize{2pt}\shadowbox*{#1}}
\begin{document}
\eqbox{$1+1 = 2$} % OK
\eqbox{\begin{equation}1+1 = 2\end{equation}} % NOT OK
\begin{equation}\eqbox{1+1 = 2}\end{equation} %OK
\begin{equation}\eqbox{r_{s} = \frac{2GM}{c^{2}}}\end{equation} % NOT OK
\end{document}

Note: I do not want the equation number to be in the box...

  • Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 May 7 '14 at 15:58
  • @ChristianHupfer Sorry for that : MWE added – Vincent May 7 '14 at 16:09
  • Perhaps you should consider tcolorboxes instead? – user31729 May 7 '14 at 16:21
  • Or maybe the hf-tikz package? – jotagah May 7 '14 at 17:56
5

The package empheq does this quite easily:

\documentclass[11pt,a4paper]{book}
\usepackage{fancybox,xcolor}
\usepackage{empheq}

\definecolor{shadowcolor}{RGB}{0, 0, 102}
\newcommand*\eqbox[1]{%
  \setlength\shadowsize{2pt}%
  \shadowbox*{#1}%
}


\begin{document}
Some text
\begin{empheq}[box=\eqbox]{equation}
1+1 = 2
\end{empheq}
Some text
\begin{empheq}[box=\eqbox]{align}
r_{s} &= \dfrac{2GM}{c^{2}} \\
v &= ab+cd
\end{empheq}

\end{document}

enter image description here

Is this something I like? No.

2

equation needs somme space for the reference, then one has to use a minipage.

enter image description here

\documentclass[11pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{fancybox}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{empheq}

\newcommand*\eqbox[1]{\definecolor{shadowcolor}{RGB}{0, 0, 102}\setlength\shadowsize{2pt}\shadowbox*{#1}}

\newcommand{\EqBox}[2][.8]{%
    \definecolor{shadowcolor}{RGB}{0, 0, 102}
    \setlength\shadowsize{2pt}
    \begin{equation}
        \shadowbox*{%
        \begin{minipage}{#1\linewidth}
        \[#2\]
        \end{minipage}      
        }
    \end{equation}
    }

\begin{document}
\eqbox{$1+1 = 2$} % OK
\begin{equation}\eqbox{1+1 = 2}\end{equation} %OK


\EqBox[.27]{r_{s} = \dfrac{2GM}{c^{2}}}

\end{document}
  • Yes... except that I do not want the number to be in the box... – Vincent May 7 '14 at 16:30
  • Not so piece of cake... (it works for 1+1=2 but not for things with math symbols -> see the edited MWE) – Vincent May 7 '14 at 16:38
  • 1
    Let's try again ;-) – Tarass May 7 '14 at 16:58

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.