Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
1  
have you seen How can I center text/math inside a list environment? –  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
add comment

1 Answer 1

up vote 1 down vote accepted

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}
}
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.