# Center displayed, boxed equation within environment

I would like to center, with respect to the page margins, a displayed equation that is boxed and is within either an enumerate or itemize environment. Below is an example of what I have. Notice that the displayed, boxed equation is centered with respect to the environment (not the page margins). By the way, I borrowed the answer to this question in order to make the boxed equation.

\documentclass[11pt]{article}
\usepackage{amsmath,amssymb,amsfonts}

\usepackage{color}
\definecolor{myblue}{rgb}{.8, .8, 1}

\usepackage{amsmath}
\usepackage{empheq}

%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%
%Code for boxed equation, taken from a question on Stack Exchange:
\newlength\mytemplen
\newsavebox\mytempbox

\makeatletter
\newcommand\mybluebox{%
\@ifnextchar[%]
{\@mybluebox}%
{\@mybluebox[0pt]}}

\def\@mybluebox[#1]{%
\@ifnextchar[%]
{\@@mybluebox[#1]}%
{\@@mybluebox[#1][0pt]}}

\def\@@mybluebox[#1][#2]#3{
\sbox\mytempbox{#3}%
\mytemplen\ht\mytempbox
\ht\mytempbox\mytemplen
\mytemplen\dp\mytempbox
\dp\mytempbox\mytemplen
\colorbox{myblue}{\hspace{1em}\usebox{\mytempbox}\hspace{1em}}}

\makeatother
%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%

\begin{document}
\title{Title}
\author{Author}
\date{Date}
\maketitle

\noindent Here is a sentence.
\begin{itemize}
\item Here is an item.
\item Here is an item.
\begin{enumerate}
\item Here is Step 1.
\item Here is Step 2 with an equation:
\begin{empheq}[box={\mybluebox[5pt]}]{equation*}
x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}.
\end{empheq}
\item Here is Step 3.
\end{enumerate}
\item Here is an item.
\end{itemize}

\end{document}


-
– cmhughes Apr 27 '13 at 22:28
I have, but I'm unsure about what changes I need to make to my code in order to center the equation. – Noob Apr 27 '13 at 22:43

The solution given by herbert in How can I center text/math inside a list environment? (the same which cmhughes linked above) can be easily modified for your case.

\documentclass[11pt]{article}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{showframe} %% just for illustration

\usepackage{color}
\definecolor{myblue}{rgb}{.8, .8, 1}

\usepackage{amsmath}
\usepackage{empheq}

%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%
%Code for boxed equation, taken from a question on Stack Exchange:
\newlength\mytemplen
\newsavebox\mytempbox

\makeatletter
\newcommand\mybluebox{%
\@ifnextchar[%]
{\@mybluebox}%
{\@mybluebox[0pt]}}

\def\@mybluebox[#1]{%
\@ifnextchar[%]
{\@@mybluebox[#1]}%
{\@@mybluebox[#1][0pt]}}

\def\@@mybluebox[#1][#2]#3{
\sbox\mytempbox{#3}%
\mytemplen\ht\mytempbox
\ht\mytempbox\mytemplen
\mytemplen\dp\mytempbox
\dp\mytempbox\mytemplen
\colorbox{myblue}{\hspace{1em}\usebox{\mytempbox}\hspace{1em}}}
%
%% This is the macro for you
\def\MLine#1{\par\hspace*{-\@totalleftmargin}\parbox{\textwidth}{%
\begin{empheq}[box={\mybluebox[5pt]}]{equation*}
#1
\end{empheq}}}
\makeatother
%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%

\begin{document}
\title{Title}
\author{Author}
\date{Date}
\maketitle

\noindent Here is a sentence.
\begin{itemize}
\item Here is an item.
\item Here is an item.
\begin{enumerate}
\item Here is Step 1.
\item Here is Step 2 with an equation:
\MLine{x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}}
\item Here is Step 3.
\end{enumerate}
\item Here is an item.
\end{itemize}

\end{document}


It can be generalized in case if you want to use other formats of the equation (say unstarred ones) by

\def\MLine#1{\par\hspace*{-\@totalleftmargin}\parbox{\textwidth}{%
#1
}}


and use the the equation like:

\MLine{%
\begin{empheq}[box={\mybluebox[5pt]}]{equation}
x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}
\end{empheq}
}

-
This may be closed after getting feedback from OP and I will delete this accordingly. – Harish Kumar Apr 27 '13 at 23:17
Thanks, Harish! – Noob Apr 28 '13 at 0:57
@Nathan: Glad it helped. :) – Harish Kumar Apr 28 '13 at 1:02