# Force to align left a empheq box

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage[dvipsnames]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{empheq}

\definecolor{lightgrey}{HTML}{f0f0f0}

\newtcbox{\resultbox}[1][lightgrey]{
nobeforeafter,
math upper,
tcbox raise base,
enhanced,
boxrule=1pt,
colback = #1!30,
sharp corners
}

\begin{document}

\begin{empheq}[box=\resultbox]{equation*}
a(t) = 2\alpha - \gamma\omega^2 cos(\omega t)
\end{empheq}

\end{document}


result:

there any way to force align to left of that empheq box?

Thank you.

EDIT: sorry for the inconvenience, from now it's already full minimum code to be compiled.

is there any way to use fleqn to only affects the class \resultbox?

You just need to add the option fleqn to your document class line.

Here is the full code:

\documentclass[fleqn]{article}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{skins,theorems}
\usepackage{empheq}
\newtcbox{\resultbox}[1][lightgray]{
nobeforeafter,
math upper,
tcbox raise base,
enhanced,
boxrule=1pt,
colback = #1!30,
sharp corners
}

\begin{document}

\begin{empheq}[box=\resultbox]{equation*}
v(t) = 2\alpha t - \gamma\omega sen(\omega t))
\end{empheq}

\end{document}


Next time please give a full minimal working example. In particular, the code should compile.

EDIT to typeset equation on the left without setting fleqn globally

The fleqn option sets a flag @fleqn that is used by the empheq package to typeset the equation on left. The hack below sets this flag when the package is loaded and then creates a new environment Empheq that sets this flag for the environment only. With this in place, you can have your cake and eat it too, so to speak.

\documentclass{article}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{skins,theorems}
\newtcbox{\resultbox}[1][lightgray]{
nobeforeafter,
math upper,
tcbox raise base,
enhanced,
boxrule=1pt,
colback = #1!30,
sharp corners
}
\makeatletter% hack to allow empheq environment to be used with fleqn in force only locally
\@fleqntrue
\usepackage{empheq}
\newenvironment{Empheq}{\@fleqntrue\empheq[box=\resultbox]{equation*}}{\endempheq}
\@fleqnfalse
\makeatother

\begin{document}

\begin{Empheq}
v(t) = 2\alpha t - \gamma\omega sen(\omega t))
\end{Empheq}
\begin{equation*}
v(t) = 2\alpha t - \gamma\omega sen(\omega t))
\end{equation*}

\end{document}


This produces:

I have typeset the equation normally underneath to highlight the difference. I have not tested this hack comprehensively. It is unlikely that it breaks something else as this is not the way the fleqn is meant to be used. In particular, other empheq environments in your document will almost certainly be broken.

• is there any way to use fleqn to only affects the class \resultbox without affects the rest of equations? Thank you! – Edgar Alfonso Aug 19 '16 at 0:15
• See my edit for a hack. – Andrew Aug 19 '16 at 0:42