3

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
    \advance\mytemplen #1\relax
    \ht\mytempbox\mytemplen
    \mytemplen\dp\mytempbox
    \advance\mytemplen #2\relax
    \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}

enter image description here

2

1 Answer 1

2

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
    \advance\mytemplen #1\relax
    \ht\mytempbox\mytemplen
    \mytemplen\dp\mytempbox
    \advance\mytemplen #2\relax
    \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}

enter image description here

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}
}
2
  • This may be closed after getting feedback from OP and I will delete this accordingly.
    – user11232
    Commented Apr 27, 2013 at 23:17
  • @Nathan: Glad it helped. :)
    – user11232
    Commented Apr 28, 2013 at 1:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .