8

I am trying to get my equations to show up like: enter image description here

This is my attempt thus far:

\documentclass[11pt,fleqn]{book} 
\usepackage[top=3cm,bottom=3cm,left=3.2cm,right=3.2cm,headsep=10pt,a4paper]{geometry} 

\usepackage{xcolor}
\definecolor{ocre}{RGB}{243,102,25}
\usepackage{avant} 
\usepackage{empheq}
\usepackage{mathptmx}

\usepackage{microtype} 
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage{calc} 
\begin{document}

\newcommand*\Ocrebox[2][Example]{%
\sbox{\mysaveboxM}{#2}%
\sbox{\mysaveboxT}{\fcolorbox{ocre}{ocre!10}{#1}}%
sbox{\mysaveboxM}{%
\parbox[b][\ht\mysaveboxM+.5\ht\mysaveboxT+.5\dp\mysaveboxT][b]{%
\wd\mysaveboxM}{#2}%
}%
\sbox{\mysaveboxM}{%
\fcolorbox{black}{shadecolor}{%
\makebox[\linewidth-10em]{\usebox{\mysaveboxM}}%
}%
}%
\usebox{\mysaveboxM}%
\makebox[0pt][r]{%
\makebox[\wd\mysaveboxM][c]{%
\raisebox{\ht\mysaveboxM-0.5\ht\mysaveboxT
+0.5\dp\mysaveboxT-0.5\fboxrule}{\usebox{\mysaveboxT}}%
}%
}%
}

\begin{empheq}[box=\Ocrebox]
\frac{C(s)}{R(s)}= \frac{G(s)}{1+G(s)H(s)}
\label{e5}
\end{empheq}

\end{document}

I am not getting this to compile though. Any help will be greatly appreciated!

8

For the frame around theorem-like structures, one possibility is to use mdframed and amsthm; for a simple frame around equations, empheq-style, it's enough to say something like:

\newcommand*\mymathbox[1]{%
  \fcolorbox{ocre}{mygray}{\hspace{1em}#1\hspace{1em}}}

and then use box=\mymathbox in the optional argument of empheq. A complete example:

\documentclass{book}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{empheq}
\usepackage{bookman}
\usepackage[framemethod=tikz]{mdframed}

\definecolor{ocre}{RGB}{243,102,25}
\definecolor{mygray}{RGB}{243,243,244}

\newcommand*\mymathbox[1]{%
  \fcolorbox{ocre}{mygray}{\hspace{1em}#1\hspace{1em}}}

\newtheoremstyle{mystyle}
  {\topsep}
  {\topsep}
  {\normalfont}
  {}
  {\sffamily\bfseries}
  {.}
  {.5em}
  {{\color{ocre}\thmname{#1}~\thmnumber{#2}}\thmnote{\,--\,#3}}%
\theoremstyle{mystyle}
\newmdtheoremenv[
  backgroundcolor=mygray,
  linecolor=ocre,
  leftmargin=20pt,
  innerleftmargin=0pt,
  innerrightmargin=0pt,
  ]{theo}{Theorem}[section]

\begin{document}

\chapter{Test chapter}
\section{Test section}

\begin{theo}[Name of the theorem]
In $E=\mathbb{R}^n$ all norms are equivalent.
\begin{align}
a &= b\\
E &= mc^2 + \int_a^a x\, \mathrm{d}x
\end{align}
\end{theo}

\begin{empheq}[box=\mymathbox]{align}
a&=b\\
E&=mc^2 + \int_a^a x\, \mathrm{d}x
\end{empheq}

\end{document}

enter image description here

In a comment, it has been requested to have a framed box similar for those for theorems in my previous solution, but for math expressions; one possibility here is to use the tcolorbox package:

\documentclass{book}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{bookman}
\usepackage[most]{tcolorbox}

\definecolor{ocre}{RGB}{243,102,25}
\definecolor{mygray}{RGB}{243,243,244}

\tcbset{myformula/.style={
  arc=0pt,
  outer arc=0pt,
  colback=mygray,
  colframe=ocre,
  boxrule=0.4pt,
  left=2pt,
  right=2pt,
  highlight math style={
    arc=0pt,
    outer arc=0pt,
    colback=mygray,
    colframe=red.
    }
  }
}

\begin{document}

\chapter{Test chapter}
\section{Test section}

\begin{tcolorbox}[ams equation,myformula]
E = mc^2 + \int_a^a x\, \mathrm{d}x
\end{tcolorbox}

\begin{tcolorbox}[ams align,myformula]
a &= b \\
E &= mc^2 + \int_a^a x\, \mathrm{d}x
\end{tcolorbox}

\end{document}

enter image description here

Or, using mdframed again,

\documentclass{book}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{bookman}
\usepackage[framemethod=tikz]{mdframed}

\definecolor{ocre}{RGB}{243,102,25}
\definecolor{mygray}{RGB}{243,243,244}

\newmdenv[
  innertopmargin=0pt,
  backgroundcolor=mygray,
  linecolor=ocre,
  innerleftmargin=0pt,
  innerrightmargin=0pt,
  leftmargin=10pt
  ]{mymath}

\begin{document}

\chapter{Test chapter}
\section{Test section}

\begin{mymath}
\begin{align}
a &= b\\
E &= mc^2 + \int_a^a x\, \mathrm{d}x
\end{align}
\end{mymath}

\end{document}

enter image description here

  • Hello, I also just wanted to do the same type of box around normal equations. In the equation environment. I would like to get the same box around the equation: \begin{equation} E(s)= R(s)-C(s)H(s) \label{e3} \end{equation} – Joe Sep 6 '13 at 12:46
  • @Joe please see my updated answer. – Gonzalo Medina Sep 6 '13 at 13:31
  • I apologize for not be through enough with my dilemma, but I actually wanted to get the box to cover the full width of the page just like that in the Theorem box. – Joe Sep 6 '13 at 13:42
  • @Joe answer updated with a solution using tcolorbox (make sure you have a recent version of tcolorbox installed; otherwise, let me know and I can give you another option). – Gonzalo Medina Sep 6 '13 at 13:54
  • Prefect! I know we are not supposed to say THANKS and leave our comments succinct...but THANK YOU! – Joe Sep 6 '13 at 14:02

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.